Welcome to Rider Pi Robot repository
11. Face Detection
Face detection
1. Experimental purpose
Face detection for driving the car
2. Experimental path source code
Enter the car system, end the car program, enter "ip (ip is the car's ip): 8888" in the browser, enter the password "yahboom" Then log in Enter the path Rider-pi_class/5.AI Visual Recognition Course/11. Face detection and run 12_Face_detection.ipynb.
Or enter the command in the terminal to directly start the python script
cd /home/pi/Rider-pi_class/5.AI Visual Recognition Course/11. Face detectionpython3 FaceDetection_USB.py3. Experimental phenomenon
After running the source code, you can see that the car will detect the face and select it

4. Main source code analysis
xif __name__ == '__main__': capture = cv.VideoCapture(0) # capture.set(0, cv.VideoWriter.fourcc('M', 'J', 'P', 'G')) capture.set(cv.CAP_PROP_FRAME_WIDTH, 320) capture.set(cv.CAP_PROP_FRAME_HEIGHT, 240) print("capture get FPS : ", capture.get(cv.CAP_PROP_FPS)) pTime, cTime = 0, 0 face_detector = FaceDetector(0.75) display(image_widget) try: while capture.isOpened(): ret, frame = capture.read() # frame = cv.flip(frame, 1) frame,_ = face_detector.findFaces(frame) if cv.waitKey(1) & 0xFF == ord('q'): break cTime = time.time() fps = 1 / (cTime - pTime) pTime = cTime text = "FPS : " + str(int(fps)) cv.putText(frame, f"FPS: {fps:.1f}", (10, 30), cv.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2) image_widget.value = bgr8_to_jpeg(frame) #Display the image on the LCD screen b, g, r = cv.split(frame) image = cv.merge((r, g, b)) imgok = Image.fromarray(image) mydisplay.ShowImage(imgok) except KeyboardInterrupt: capture.release()The car calls the detected face model, selects the recognized face results, and displays the recognition rate.