Welcome to DOGZILLA-Lite repository
8. Yolo detection
YOLO Detection
1. Purpose of the experiment
Drive the robot dog's yolo detection and label the corresponding name according to object recognition
2. Experimental path source code
Enter the robot dog system, end the robot dog program, enter "ip (ip is the robot dog's ip): 8888" in the browser, enter the password "yahboom" and log in. Enter the path of DOGZILLA_Lite_class/5.AI Visual Recognition Course/08. YOLO detection and run yolo.ipynb . Or enter the command in the terminal to directly start the python script
xxxxxxxxxxcd /home/pi/DOGZILLA_Lite_class/5.AI Visual Recognition Course/08. YOLO detectionpython3 yolo.py
3. Experimental Phenomenon
After running the source code, you can see that the robot dog can detect objects

4. Main source code analysis
xxxxxxxxxxdef yoloFast(self,target="camera"): ret='' self.open_camera() if self.yolo==None: self.yolo = yoloXgo('/home/pi/model/Model.onnx', ['person','bicycle','car','motorbike','aeroplane','bus','train','truck','boat','traffic light','fire hydrant','stop sign','parking meter','bench','bird','cat','dog','horse','sheep','cow','elephant','bear','zebra','giraffe','backpack','umbrella','handbag','tie','suitcase','frisbee','skis','snowboard','sports ball','kite','baseball bat','baseball glove','skateboard','surfboard','tennis racket','bottle','wine glass','cup','fork','knife','spoon','bowl','banana','apple','sandwich','orange','broccoli','carrot','hot dog','pizza','donut','cake','chair','sofa','pottedplant','bed','diningtable','toilet','tvmonitor','laptop','mouse','remote','keyboard','cell phone','microwave','oven','toaster','sink','refrigerator','book','clock','vase','scissors','teddy bear','hair drier','toothbrush'], [352,352],0.66) if target=="camera": self.open_camera() success,image = self.cap.read() else: image=np.array(Image.open(target)) datas = self.yolo.run(image) b,g,r = cv2.split(image) image = cv2.merge((r,g,b)) image = cv2.flip(image,1) if datas: for data in datas: XGOEDU.rectangle(self,image,data['xywh'],"#33cc00",2) xy= (data['xywh'][0], data['xywh'][1]) XGOEDU.text(self,image,data['classes'],xy,1,"#ff0000",2) value_yolo = data['classes'] ret=(value_yolo,xy) imgok = Image.fromarray(image) #把颜色转回来 Turn the color back r,g,b = cv2.split(image) image1 = cv2.merge((b,g,r)) cv2.imshow('frame', image1)#显示在终端上 display on the terminal self.display.ShowImage(imgok) if ret=='': return None else: return retmy_edu = my_yolo() #循环进行摄像头识别,按c键退出 Loop through the camera recognition, press c to exitwhile True: result=my_edu.yoloFast() #缺省参数,默认使用摄像头识别 Default parameters, use camera recognition by default print(result) if cv2.waitKey(1) & 0xFF == ord('q'): breakThrough the source code, the robot dog calls the edu API library and detects objects by turning on the camera.