Person and Face Detection using Intel OpenVINO toolkit

Story
This project can be used to detect the presence of people in a room. It uses the pre-trained models downloaded using the OpenVINO model downloader.
This project can be used to detect the presence of people by detecting their faces and their body.
Things used in this project
Software apps and online services |
||||||
![]() |
|
Intel OpenVINO | ||||
|
Steps
1 Download and install Anaconda Distribution of Python
2 Install all the dependencies
3 Download the Intel Distribution of OpenVINO toolkit.(My OpenVINO version - 2020.0.1.033)
Python Virtual Environment
1 Install virtual environment
pip install virtualenv
virtualenv --system-site-packages -p python openvinoenv
2 Activate virtual environment
openvinoenv\Scripts\activate
3 Running "setupvars.bat" file to set up the OpenVINO environment variables
cd "C:\Program Files (x86)\IntelSWTools\openvino_2020.1.033\bin\"setupvars.bat
4 Installing all the requirements from the "requirements.txt" file
cd "C:\Program Files (x86)\IntelSWTools\openvino_2020.1.033\deployment_tools\model_optimizer>"
pip install -r requirements.txt
5 Once done with OpenVINO, deactivate the environment
deactivate
NOTE - I have created a batch file named "openvinoenv.bat" to run the following steps in one singe line.
call "openvinoenv\Scripts\activate"call "C:\Program Files (x86)\IntelSWTools\openvino_2020.1.033\bin\setupvars.bat"
With a single line, the python virtual environment for OpenVINO toolkit can be created and the OpenVINO environment variables can be initialized.
openvinoenv.bat
Pre-trained Models
It uses the pre-trained models from the Intel OpenVino pre-trained models.
The following pre-trained models were downloaded using the model downloader
python "C:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\open_model_zoo\tools\downloader\downloader.py"
Demonstration Videos used from the sample videos of intel-iot-devkit Github Repository.
System specifications used
Processor - Intel Core i7 9750H
Ram - 16 GB
OS - Windows 10 64 bit
Final Code Github Repository Link - here
Date of Download of Intel® Distribution of OpenVINO toolkit for Windows - January 2020 (w_openvino_toolkit_p_2020.1.033.exe)
Email ID used- same as the one with the hackster.io
Code
main.py Python
Main Code for People and Face Detection Using Intel OpenVINO toolkit
import cv2 net2 = cv2.dnn.readNet('person-detection-retail-0013.bin', 'person-detection-retail-0013.xml') net = cv2.dnn.readNet('face-detection-adas-0001.bin', 'face-detection-adas-0001.xml') cap = cv2.VideoCapture("video1.mp4") font = cv2.FONT_HERSHEY_SIMPLEX while cv2.waitKey(1) < 0: hasFrame, frame = cap.read() frame = cv2.resize(frame,(1280,720),fx=0,fy=0, interpolation = cv2.INTER_CUBIC) if not hasFrame: break face_blob = cv2.dnn.blobFromImage(frame, size=(672, 384)) net.setInput(face_blob) out_face = net.forward() for detection in out_face.reshape(-1, 7): confidence = float(detection[2]) xmin = int(detection[3] * frame.shape[1]) ymin = int(detection[4] * frame.shape[0]) xmax = int(detection[5] * frame.shape[1]) ymax = int(detection[6] * frame.shape[0]) if confidence > 0.5: cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), color=(0, 255, 0)) cv2.putText(frame,'FACE',(xmin, (ymin-10)),font, 0.4,(0, 255, 255),1,cv2.LINE_AA) person_blob = cv2.dnn.blobFromImage(frame, size=(672, 384)) net2.setInput(person_blob) out_person = net2.forward() for detection in out_person.reshape(-1, 7): confidence2 = float(detection[2]) xmin2 = int(detection[3] * frame.shape[1]) ymin2 = int(detection[4] * frame.shape[0]) xmax2 = int(detection[5] * frame.shape[1]) ymax2 = int(detection[6] * frame.shape[0]) if confidence2 > 0.6: cv2.rectangle(frame, (xmin2, ymin2), (xmax2, ymax2), color=(0, 255, 0)) cv2.putText(frame,'PERSON',(xmin2, (ymin2-10)),font, 0.4,(0, 255, 255),1,cv2.LINE_AA) cv2.imshow('OpenVINO face detection', frame)
Main Repository - person_and_face_detection - Nilutpol Kashyap
Project for Person and Face Detection for public Security using the Pre-trained models from Intel Distribution of OpenVINO toolkit. — Read More
Latest commit to the master branch on 10-14-2020
Credits

This content is provided by our content partner Avnet, a global technology solutions provider with end-to-end ecosystem capabilities. Visit them online for more great content like this.