I have a flask application which allow user to upload an image then it does some multistep processing.
Am trying to read the uploaded image in cv2 using cv2.imread
but the function never returns it just hangs in cv2.imread
the calling method
def remove_skin_color(filename):
print('removing skin color for {}'.format(filename))
colorDetection = ColorDetector()
img_loc = os.path.join(app.root_path, app.config['UPLOAD_FOLDER'], filename)
print('processing image {}'.format(img_loc))
no_skin_img = colorDetection.get_removed_skin(img_loc=img_loc)
cv2.imwrite(os.path.join(app.root_path, IMG_FOLDER, filename), no_skin_img)
print('writing image done')
return filename
logs
[Sat Apr 27 14:05:53.119646 2019] [wsgi:error] [pid 12364:tid 1328] [client 197.125.110.218:39284] request method is POST\r
[Sat Apr 27 14:05:53.122573 2019] [wsgi:error] [pid 12364:tid 1328] [client 197.125.110.218:39284] True\r
[Sat Apr 27 14:05:53.122573 2019] [wsgi:error] [pid 12364:tid 1328] [client 197.125.110.218:39284] receiving ... file.JPEG\r
[Sat Apr 27 14:05:53.122573 2019] [wsgi:error] [pid 12364:tid 1328] [client 197.125.110.218:39284] 1556366753_file.JPEG\r
[Sat Apr 27 14:05:53.126479 2019] [wsgi:error] [pid 12364:tid 1328] [client 197.125.110.218:39284] removing skin color for 1556366753_file.JPEG\r
[Sat Apr 27 14:05:53.126479 2019] [wsgi:error] [pid 12364:tid 1328] [client 197.125.110.218:39284] processing image C:\\wamp64\\www\\app\\uploads\\1556366753_file.JPEG\r
the called method
def get_removed_skin(self, bn_img=None, img_loc=None):
try:
if img_loc:
sourceImage = cv2.imread(img_loc) #code hangs here
else:
sourceImage = bn_img
except Exception as e:
print(e)
# Constants for finding range of skin color in YCrCb
min_YCrCb = np.array([0, 133, 77], np.uint8)
max_YCrCb = np.array([255, 173, 127], np.uint8)
# Convert image to YCrCb
imageYCrCb = cv2.cvtColor(sourceImage, cv2.COLOR_BGR2YCR_CB)
# Find region with skin tone in YCrCb image
skinRegion = cv2.inRange(imageYCrCb, min_YCrCb, max_YCrCb)
# Do contour detection on skin region
_, contours, hierarchy = cv2.findContours(skinRegion, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cv2.fillPoly(sourceImage, pts=contours, color=(255, 255, 255))
return sourceImage
note : am running this App on Wamp (Apache) server + WSGI on my laptop
virtual host conf
# Virtual Hosts
#
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
ErrorLog ${INSTALL_DIR}/www/app/app.log
WSGIScriptAlias / "${INSTALL_DIR}/www/app/web.wsgi"
DocumentRoot "${INSTALL_DIR}/www/app"
<Directory "${INSTALL_DIR}/www/app/">
Options +Indexes +Includes +FollowSymLinks +MultiViews +ExecCGI
AllowOverride All
#Require local
Require all granted
</Directory>
</VirtualHost>
when I run the application locally it works as expected with no issues
I have simplified the process to be as below and still same issue
def upload_file():
print('request method is {}'.format(request.method))
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
print('file not in request.files')
return redirect(request.url)
file = request.files['file']
if file.filename == '':
print('filename is {}'.format(file.filename))
return redirect(request.url)
print(file and allowed_file(file.filename))
if file and allowed_file(file.filename):
print('receiving ... ', file.filename)
filename = secure_filename(file.filename)
ts = int(time.time())
file_name = file_name_template.format(ts, filename)
print(file_name)
filePath = os.path.join(app.root_path, app.config['UPLOAD_FOLDER'], file_name)
file.save(filePath)
# file.save(os.path.join(app.config['UPLOAD_FOLDER'], file_name))
img = cv2.imread(filePath)
print(' file has been read') #this line never gets printed
out_image_name = remove_skin_color(file_name)
json_data = color_palette(out_image_name)
return json_data