This repo takes advantages of OpenCV and TensorFlow to achieve the goal of concentration analysis (camera/video part).
If you prefer Chinese README, please refer to this file.
Note: The original video before being processed is referred from the Internet
- opencv-python 4.2.0.32
- tensorflow 1.14.0
- Python 3.6.9
- Codes from this repo has been tested on Ubuntu 18.04
git clone https://github.com/MercurialJD/Concentration-Detection.git
This project accepts video files or real-time camera records. In the case no argument is provided or the given argument points to a camera, the corresponding camera will be automatically invoked; If a video file is given as an argument, the video will be analyzed.
For video formats that can be identified by OpenCV:
python3 concentration_estimation.py --video /path/to/your/video.mp4
Default camera:
python3 concentration_estimation.py
Explicitly designated camera:
python3 concentration_estimation.py --cam 0
Please adjust concentration_estimation.py
w.r.t. your requirements.
-
If the processed video is needed, please uncomment following lines:
# fourcc = cv2.VideoWriter_fourcc(*'mp4v') # out = cv2.VideoWriter('output.mp4', fourcc, 20.0, (width, height)) ... # cv2.putText(frame, "FACING", (height//50, width//50), cv2.FONT_HERSHEY_DUPLEX, 1, (0, 0, 0), 1) ... # cv2.putText(frame, "UNFACED", (height//50, width//50), cv2.FONT_HERSHEY_DUPLEX, 1, (0, 0, 0), 1) ... # out.write(frame) ... # out.release()
-
If real-tile preview is needed, please uncomment the following line:
# cv2.imshow("Preview", frame)
-
If the facial identification box need to be customized, please modify:
pose_estimator.draw_annotation_box(...)
-
If head-pose axes need to be customized, please modify:
pose_estimator.draw_axis(...)
- Facial recognition with DNN module provided by OpenCV
- Facial landmarks with 68-point estimation provided by TensorFlow
- Pose estimation with PnP algorithm
- Stabilization with Kalman filter
- Concentration analysis
Please refer to LICENSE.md.
- Fine-Grained Head Pose Estimation Without Keypoints (CVPR 2018) by Ruiz, Nataniel and Chong, Eunji and Rehg, James M.
- Head pose estimation by TensorFlow and OpenCV by Yin Guobing