Welcome to Rider Pi Robot repository
9. Object Detection
Object detection
1. Experimental purpose
Drive the car to detect human posture
2. Experimental path source code
Enter the car system and end the car program
Enter the command in the terminal and start the python script directly
cd /home/pi/Rider-pi_class/5.AI Visual Recognition Course/9. Object detection/detectionpython3 target_detection_USB.py3. Experimental phenomenon
After running the source code, you can see that the car will detect objects, and press the "f" button to switch the display

4. Main program source code
xif __name__ == '__main__': capture = cv.VideoCapture(0) capture.set(3, 320) capture.set(4, 240) cv_edition = cv.__version__ if cv_edition[0] == '3': capture.set(cv.CAP_PROP_FOURCC, cv.VideoWriter_fourcc(*'XVID')) else: capture.set(cv.CAP_PROP_FOURCC, cv.VideoWriter.fourcc('M', 'J', 'P', 'G')) capture.set(cv.CAP_PROP_FRAME_WIDTH, 320) capture.set(cv.CAP_PROP_FRAME_HEIGHT, 240) state=True while capture.isOpened(): start = time.time() ret, frame = capture.read() action = cv.waitKey(10) & 0xFF if state==True: frame = Target_Detection(frame) cv.putText(frame, "Detection", (120, 15), cv.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 255), 1) else: frame = openpose(frame) cv.putText(frame, "Openpose", (120, 15), cv.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 255), 1) if action == ord('q') or action == ord('Q'): break if action == ord('f') or action == ord('F'): state = not state end = time.time() fps = 1 / (end - start) text = "FPS : " + str(int(fps)) cv.putText(frame, text, (10, 20), cv.FONT_HERSHEY_SIMPLEX, 0.6, (100, 200, 200), 1) cv.imshow('frame', frame) #Display the image on the LCD screen b, g, r = cv.split(frame) image = cv.merge((r, g, b)) imgok = Image.fromarray(image) display.ShowImage(imgok) capture.release() cv.destroyAllWindows() display.clear() splash = Image.new("RGB", (display.height, display.width), "black") display.ShowImage(splash)It can be seen from the source code that the car turns on the camera and displays the recognition results on the car screen and the computer screen.