HaarCascade算法做人臉識(shí)別
import numpy as np?
import CV2
cap = CV2.VideoCapture("/home/nvidia/GAN_Pic03.png")
算法的模型路徑
libHaarCascadePath="/usr/share/openCV4/haarcascades/"
使用“前臉(frontalface)”模型
libHaarCascadeFace="haarcascade_frontalface_default.xml"?
faceCascade = CV2.CascadeClassifier(libHaarCascadePath+libHaarCascadeFace)
_,?
frame = cap.read()?
gray = CV2.cvtColor(frame, CV2.COLOR_BGR2GRAY)?
faces = faceCascade.detectMultiScale(gray, 1.3, 5)?
for (x, y, w, h) in faces:?
print("Detect Face!\n")?
CV2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2)?
roi_gray = gray[y : y + h, x : x + w]?
roi_color = frame[y : y + h, x : x + w]?
CV2.imshow("Jetson Nano的OpenCV人臉檢測(cè)Demo", frame)?
CV2.waitKey()?
CV2.destroyAllWindows()?
cap.release()
標(biāo)簽: