ParisNeo / FaceAnalyzer

A python library for face detection and features extraction based on mediapipe library
MIT License
42 stars 11 forks source link

Cannot run examples #2

Closed ianni67 closed 2 years ago

ianni67 commented 2 years ago

Hello @ParisNeo , thank you for sharing your valuable software. I cloned the repo and ran: python setup.py build python setup.py install then tried to run the face_mask example: cd /examples/OpenCV/face_mask python face_mask.py

but the program exited immediately:

$ python face_mask.py
/home/ianni/.virtualenvs/MP/lib/python3.8/site-packages/FaceAnalyzer-0.1.11-py3.8.egg/FaceAnalyzer/Face.py:1507: SyntaxWarning: assertion is always true, perhaps remove parentheses?
/home/ianni/.virtualenvs/MP/lib/python3.8/site-packages/FaceAnalyzer-0.1.11-py3.8.egg/FaceAnalyzer/Face.py:1507: SyntaxWarning: assertion is always true, perhaps remove parentheses?
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
$

Edit: I also tried creating a virtualenv and installing FaceAnalyzer from scratch with pip, according to the instructions: pip install FaceAnalyzer

and then ran, again:

cd /examples/OpenCV/face_mask
python face_mask.py

and again, it did not work:

$ python face_mask.py 
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
$

What can I do?

ParisNeo commented 2 years ago

Sorry for the delay.

For face_mask example. You need to generate a reference face file called reference.pkl that will be used by the script. To do this, first run this file in the same directory : build_eye_open_mouth_open_triangles.py

A window will show up and you'll see your face with triangles. Open wide your eyes and mouth then press s. This will create a triangulation scheme and save it to reference.pkl file.

Once that file is created, the example will work.

If you still have questions, please don't hesitate to ask.

ianni67 commented 2 years ago

Hi @ParisNeo , thank you very much four your kind reply. I followed your instructions, however, also build_eye_open_mouth_open_triangles.py did not work as expected. I ran the program, an application opened for a fraction of a second and immediately closed. No window, no face triangles appeared on the screen:


$ python build_eye_open_mouth_open_triangles.py 
/home/ianni/.virtualenvs/MP/lib/python3.8/site-packages/FaceAnalyzer-0.1.11-py3.8.egg/FaceAnalyzer/Face.py:1507: SyntaxWarning: assertion is always true, perhaps remove parentheses?
/home/ianni/.virtualenvs/MP/lib/python3.8/site-packages/FaceAnalyzer-0.1.11-py3.8.egg/FaceAnalyzer/Face.py:1507: SyntaxWarning: assertion is always true, perhaps remove parentheses?
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
$

Is there anything else that I'm missing?

ParisNeo commented 2 years ago

You confirm that you have a camera on your PC that is connected? I use opencv to build the window. I've tested this on windows and it works flowlessly. I've never tested it on linux, so Maybe something is going wrong.

You may try for example to test an opencv example from the internet. There are simple examples on the opencv webpage: https://docs.opencv.org/4.x/dd/d43/tutorial_py_video_display.html Maybe you have a problem with your opencv configuration.

Does the pygame examples work for you? If So, I may rewrite the face_mask code in pygame.

ianni67 commented 2 years ago

Ok, I got it, I was a bit lazy and did not check your code properly. Linux does not like the second parameter cv2.CAP_DSHOW at line 51 in face_mask.py. Removing the parameter did the job. Thank you for your help.

ParisNeo commented 2 years ago

Ah, yes I forgot that one. Maybe I'll add some safegards for linux.

As for the assets for face_mask example, here I only uploaded an asset that is under creative commons licence. You can find way funnier assets if you want to play with that. It works also for some cartoon faces

ParisNeo commented 2 years ago

I've updated the code in the latest version of the repository. Thanks for your suggestion