Speaking of face recognition, it's OpenCV! !!
Please refer to Yesterday's article and install the USB camera driver in the Linux kernel.
Write Article that Nyuraru explained in detail from the beginning with a few hours difference. If you want to know more about it, check it out too!
OpenCV has a package in opkg.
# opkg install opencv python-opencv
detectface.py
import cv2
import sys
cascPath = sys.argv[1]
faceCascade = cv2.CascadeClassifier(cascPath)
video_capture = cv2.VideoCapture(0)
# Capture frame-by-frame
ret, frame = video_capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.cv.CV_HAAR_SCALE_IMAGE
)
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
# Save the resulting frame
cv2.imwrite('face.png', frame)
# When everything is done, release the capture
video_capture.release()
I modified the code of Spat here. Thank you.
This OpenCV uses a face-shaped light and dark library called Haar Cascades, so bring it from a computer that has OpenCV installed somewhere (appropriate). For Ubuntu, it is located at * /usr/share/opencv/haacascades/haacascade_frontalface_alt.xml *. With this,
# python ./detectface.py ./haacascade_frontalface_alt.xml
Then, a recognition result file called face.png will be generated in the same directory.
Recommended Posts