oarriaga / face_classification

Real-time face detection and emotion/gender classification using fer2013/imdb datasets with a keras CNN model and openCV.
MIT License
5.61k stars 1.59k forks source link

save detected result and video file as a input #53

Closed trohit920 closed 6 years ago

trohit920 commented 6 years ago

Hi @oarriaga ,

I am wondering is there a way, by which we can save the detected result e.g. emotion detected after running the script video_emotion_color_demo.py . Also can we run this script on video files (mp4) saved on local system for emotion detection or gender classification ? If yes can you modify the code or tell me how to do it ?

mirceaciu commented 6 years ago

You can alter the script to do what you want. This are basic python jobs

To save result:

if emotion_text == 'angry':
    color = emotion_probability * np.asarray((255, 0, 0))
    file_to_write = open('myfile.csv', 'a')
    file_to_write.write('angry,')
    file_to_write.close()

To read from video file just replace 0(that represents video camera) with the path to the video file: video_capture = cv2.VideoCapture("path/video/file.mp4")

This isn't a issue per se.

roiksail commented 6 years ago

hello mirceaciu...i got this error: Traceback (most recent call last): File "video_emotion_gender_demo.py", line 104, in color = emotion_probability * np.asarray((255, 0, 0)) NameError: name 'emotion_probability' is not defined terminate called without an active exception Aborted (core dumped) i cant save results...i want to save gender and emotion results in csv file with times that occure it and other informations

trohit920 commented 6 years ago

@mirceaciu @oarriaga What i mean here is to save the result as video file like .mp4 or .avi as i know cv2.VideoWriter_fourcc with different codec can be used but it is producing me an error like:

cv2.error: /home/rohit/opencv-3.3.0/modules/imgcodecs/src/loadsave.cpp:604: error: (-2) could not find a writer for the specified extension in function imwrite_

Can you advice me what can be done to save the result as video file ?

oarriaga commented 6 years ago

Here is a link of a tutorial on how to save video using openCV.