tamerthamoqa / facenet-realtime-face-recognition

A small-scale flask server facial recognition system, using a pre-trained facenet model with real-time web camera face recognition functionality, and a pre-trained Multi-Task Cascading Convolutional Neural Network (MTCNN) for face detection and cropping.
MIT License
98 stars 28 forks source link

Live crash on Mac OS #3

Open chrisbenseler opened 4 years ago

chrisbenseler commented 4 years ago

When trying to use the live feature, the video does not open and the app crashes. On a MacOS (10.14.5)

The log outputs:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.'

Any idea?

tamerthamoqa commented 4 years ago

Hi chrisbenseler,

It is a weird issue since I did not face this with Ubuntu 18.04 and Windows 10, it seems cv2.VideoCapture() follows the same logic as cv2.imshow() like in the github issue here: https://github.com/skvark/opencv-python/issues/134

It seems these calls must be from the main thread only and flask (or waitress in this case) creates a thread per each request which causes this issue, I suppose disallowing threaded mode would fix the issue.

Changing the serve() command to include the parameter 'threads=0' or 'threads=1' (not sure which) might solve the issue: https://docs.pylonsproject.org/projects/waitress/en/stable/arguments.html

Or replacing the waitress.serve() with the flask app.run() method with parameter 'threaded=False' might work.

I will try to install a MacOS virtual machine soon and try to help but I can't promise anything as I am currently having a bit of a workload.