Ask Your Question

Revision history [back]

cv2.imread failing when deployed to aws beanstalk

The following is my code, where I read an image file (using opencv) and do face recognition (dlib) and face swapping using opencv.

My Server Setup: Elastic beasnktalk (flask) OPENCV 3.4.1 AND PYTHON VERSION 3.6.5

import cv2
from flask import Flask
import os

@application.route('/readImage',methods=['POST'])
def handleHTTPPostRequest():
    imagePath = f'{os.getcwd()}/input.png'
    print('image path is', imagePath)
    print(cv2.__version__)
    im = cv2.imread(imagePath,cv2.IMREAD_COLOR)
    print(im) 
#Do face recognition and faceswapping

return 'success'

This is giving expected output on my local machine(Ubuntu 18.04) no matter how many times I execute it.

I moved this to elastic beanstalk(CentOS) with necessary setup. The request runs fine only for the first time. The successive POST calls always get stuck at cv2.imread and doesn’t throw any error (print(im) never gets printed)

I have restarted the server multiple times, looks like the post call only works the very first time and cv2.imread() is stuck after the first post call.What am I missing