Hello,
I'm having trouble with Python OpenCV library, running on AWS Lightsail container instance.
Some information:
- It is running on python:3.7 Docker image.
- Python Flask app
- AWS Lightsail container instance
- Using following packages: link
- Uses opencv-contrib-python-headless==4.5.4.60 for OpenCV.
- Error image: link
When trying to compare two images, I'm receiving HTTP status code of 502 Bad Gateway, which is very strange.
Seems to work perfectly on my Windows machine locally, but on this Linux image it does not work.
`from cv2 import cv2
import logging
logger = logging.getLogger()
def compare_two_images(image_to_compare_file, image_to_compare_against_file):
# Image imports
# Features
logger.warning("image_to_compare_file " + image_to_compare_file)
logger.warning("image_to_compare_against_file " + image_to_compare_against_file)
sift = cv2.SIFT_create()
logger.warning("SIFT created " + str(sift is None))
# QueryImage
img1 = cv2.imread(image_to_compare_file, cv2.IMREAD_GRAYSCALE)
logger.warning("IMG1 read created " + str(img1 is None))
# Find the key points and descriptors with SIFT
kp1, desc1 = sift.detectAndCompute(img1, None)
logger.warning("DETECT AND COMPUTE " + str(kp1 is None) + " " + str(desc1 is None))
img2 = cv2.imread(image_to_compare_against_file, cv2.IMREAD_GRAYSCALE)
logger.warning("IMG2 read created " + str(img2 is None))
kp2, desc2 = sift.detectAndCompute(img2, None)
logger.warning("DETECT AND COMPUTE " + str(kp2 == None) + " " + str(desc2 is None))
# BFMatcher with default params
bf = cv2.BFMatcher()
matches = bf.knnMatch(desc1, desc2, k=2)
# Apply ratio test
good = []
for m, n in matches:
if m.distance < 0.55 * n.distance:
good.append([m])`
It crashes on kp1, desc1 = sift.detectAndCompute(img1, None)
and produces 502 Bad Gateway.
Then, on some other endpoints I have in my Python Flask app, it produces 503 Service Temporarily Unavailable for a very times.
After that, I can see that images were deleted.
Any help is appreciated.
I think you accidentally submitted the question twice? See https://repost.aws/questions/QUHTcwJWsnTimBF6fduWK3Hg/python-flask-open-cv-library-does-not-work-produces-http-code-502-bad-gateway-when-trying-to-compare-images