Welcome to K210 Module repository
13. Human body detection
13. Human body detection
13. Human body detection13.1 Experimental objectives13.2 Preparation before the experiment13.3 Experimental process13.4 Experimental results13.5. Experimental summary
13.1 Experimental objectives
This lesson mainly studies the human body detection function of K210.
The reference code path for this experiment is: CanMV\05-AI\body_detect.py
13.2 Preparation before the experiment
Please confirm whether the sd card model file is imported successfully, the path is: /sd/KPU/head_body_detect/person_detect_v1.kmodel
13.3 Experimental process
The factory firmware of the module has integrated the AI visual algorithm module. If you have downloaded other firmware, please burn it back to the factory firmware before conducting the experiment.
xxxxxxxxxx# 加载YOLO模型 Load YOLO modelbody_kpu = KPU()body_kpu.load_kmodel("/sd/KPU/head_body_detect/person_detect_v1.kmodel")body_kpu.init_yolo2(anchor, anchor_num=len(anchor) // 2, img_w=320, img_h=240, net_w=320, net_h=256, layer_w=10, layer_h=8, threshold=0.5, nms_value=0.2, classes=len(names))xxxxxxxxxx while True: # 手动垃圾回收,避免内存泄漏 Manual garbage collection to avoid memory leaks gc.collect() clock.tick() # 捕获图像,并处理为Yolo可识别的图片形式 Capture and handle picture img = sensor.snapshot() a = od_img.draw_image(img, 0,0) od_img.pix_to_ai() # 进行AI计算 perform AI calculations body_kpu.run_with_output(input=od_img, getlist=False, get_feature=False) body_boxes = body_kpu.regionlayer_yolo2() if len(body_boxes) > 0: for l in body_boxes : # 绘制捕获到的目标 Plotting captured targets a = img.draw_rectangle(l[0],l[1],l[2],l[3], color=(255, 0, 0)) fps = clock.fps() a = img.draw_string(0, 0, "%2.1ffps" %(fps), color=(0, 60, 128), scale=2.0) lcd.display(img)13.4 Experimental results
Connect the K210 module to the computer via a microUSB data cable, click the connect button in CanMV IDE, and click the run button after the connection is complete to run the example code. You can also download the code as main.py to the K210 module and run it.
After waiting for the system to initialize, the LCD displays the camera image, and the human on the screen will be marked by the drawn box.

13.5. Experimental summary
Through this experiment, we learned how to implement basic human detection functions on the K210 platform and gained a deeper understanding of the operation process of the YOLO model in practical applications. At the same time, in subsequent experiments, we can try to adjust the model parameters to optimize the recognition accuracy and processing speed.