The PYNQ-Z2 board, OpenCV and Jupyter Notebooks were all new topics for me a few weeks prior to CS467. That is until I was asked to join an AMD sponsored project for my capstone course at OSU. Our objective: delivery tracker software which would identify a person approaching your residence to drop off a package, snap a photo of the individual, store the photo for later review and notify the homeowners their new fitbit and yoga mat are likely sitting on their doorstep.
Booting up the PYNQ-Z2 board and accessing the Jupyter Notebook environment for the first time is relatively straightforward if following this setup guide. After reviewing the files in the getting_started directory I moved on to notebooks/base/video where we have interactive python code to implement face detection and video filters. It is both exciting and a source of relief to see what can be accomplished with less than a page of Python code. Following the process of loading the pynq overlay, initializing our video I/O for use with a webcam, capturing a frame, applying face detection and writing the frame to our hdmi out, and there you have a frame of your (certainly) beautiful face correctly identified by OpenCV.
By importing time and looping through portions of the code for a specified number of frames or infinitely until there is an interrupt, we can quickly determine which lines of code are the most resource intensive based on the fps for each trial. The culprit unsurprisingly should be face_cascade.detectMultiScale(gray, 1.3, 5) which is the function responsible for the actual face detection. Through further tests you can quickly identify the scale factor parameter (currently set to 1.3) as one important variable in determining how fast this function runs. While a scale factor of 1.08 will result in a greater number of faces being detected (including false positives), a scale factor of 1.3 will run faster while resulting in fewer detections (including false negatives).
PYNQ-Z2 running Jupyter and executing facial recognition with OpenCV. It is a great place to start the first week of our Capstone project.