I have a set of web APIs that I run on Apache with WSGI for image processing. Recently I upgraded my OpenCV to 3.2 (I'm using Python 2.7) OpenCV seems to work fine when I run it from console, but when I make web API calls openCV hangs on converting image to grayscale:
cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
It's totally random, couldn't find a pattern. Some times it hangs and some times it works for the same image. Any ideas?
More Info: When I do it from shell command all works fine:
>>> sudo python manage.py shell
>>> import cv2
>>> import numpy as np
>>> from PIL import Image
>>> image = Image.open(img_path)
>>> image = np.asarray(image)
>>> print image
array([[[255, 255, 255],
[255, 255, 255],
[255, 255, 255],...]]], dtype=uint8)
>>> img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
>>> print img
array([[255, 255, 255, ..., 255, 255, 255],
[255, 255, 255, ..., 255, 255, 255],
[255, 255, 255, ..., 255, 255, 255],
...,
[255, 255, 255, ..., 255, 255, 255],
[255, 255, 255, ..., 255, 255, 255],
[255, 255, 255, ..., 255, 255, 255]], dtype=uint8)
UPDATE: The issue is with WSGI. When I specify more than 1 process in apache config for WSGIDaemonProcess I can easily reproduce the hangs. After setting it to 1 it works
WSGIDaemonProcess processes=1 threads=25 maximum-requests=100
I'm still not sure why multiple processes in wsgi cause troubles