facedetect.py
from pynq import Overlay Overlay("base.bit").download() import time import cv2 import numpy as np from pynq.drivers import HDMI from pynq.drivers.video import VMODE_1920x1080 hdmi_out = HDMI('out', video_mode=VMODE_1920x1080) hdmi_in = HDMI('in', init_timeout=10, frame_list=hdmi_out.frame_list) hdmi_in.start() hdmi_out.start() for i in range(10): print("waiting ",10-i) time.sleep(1) print("change HDMI output frame") hdmi_out.frame_index_next() print("main loop") try: while True: frame = hdmi_in.frame_raw() np_frame= (np.frombuffer(frame, dtype=np.uint8)).reshape(1080,1920,3) face_cascade = cv2.CascadeClassifier( './data/haarcascade_frontalface_default.xml') eye_cascade = cv2.CascadeClassifier( './data/haarcascade_eye.xml') gray = cv2.cvtColor(np_frame, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.3, 5) for (x,y,w,h) in faces: cv2.rectangle(np_frame,(x,y),(x+w,y+h),(255,0,0),2) roi_gray = gray[y:y+h, x:x+w] roi_color = np_frame[y:y+h, x:x+w] eyes = eye_cascade.detectMultiScale(roi_gray) for (ex,ey,ew,eh) in eyes: cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2) hdmi_out.frame_raw(bytearray(np_frame.tobytes())) except KeyboardInterrupt: print("terminating application") hdmi_out.stop() hdmi_in.stop() del hdmi_in, hdmi_out