2. 80-Class Object Detection
2.1. Python Example
from mpython import *
import smartcamera_k230 as smartcamera
smart_camera = smartcamera.SmartCameraK230(tx=Pin.P1, rx=Pin.P0)
smart_camera.model_init(2)
while True:
smart_camera.yolo_detect.recognize()
class_id = smart_camera.yolo_detect.id
if class_id != None:
print(str('Class id: ') + str(smart_camera.yolo_detect.id))
print(str('Class name: ') + str(smart_camera.yolo_detect.category_list[smart_camera.yolo_detect.id]))
print(str('Confidence: ') + str(smart_camera.yolo_detect.max_score))
2.2. mPython Graphical Example
2.3. Functions and Methods
- smart_camera.model_init(cur_state)
Instantiate the model
- Parameters:
cur_state (int) – model id for initialization
Example:
smart_camera.model_init(2)
- class smart_camera.yolo_detect
- recognize()
Run recognition
- class smart_camera.yolo_detect
80-class instance
- Variables:
id (int) – 80-class category id, range: 0-79
category_list (list) – list of the 80 object categories, [“人”,”自行车”,”汽车”,”摩托车”,”飞机”,”公共汽车”,”火车”,”卡车”,”船”,”交通灯”,”消防栓”,”停车标志”,”泊车计时器”,”长椅”,”鸟”,”猫”,”狗”,”马”,”绵羊”,”奶牛”,”大象”,”熊”,”斑马”,”长颈鹿”,”背包”,”雨伞”,”手提包”,”领带”,”手提箱”,”飞盘”,”滑雪板”,”运动球”,”风筝”,”棒球”,”蝙蝠”,”棒球手套”,”滑板”,”冲浪板”,”网球拍”,”瓶子”,”酒杯”,”杯子”,”叉子”,”刀”,”勺子”,”碗”,”香蕉”,”苹果”,”三明治”,”橙子”,”西兰花”,”胡萝卜”,”热狗”,”披萨”,”甜甜圈”,”蛋糕”,”椅子”,”沙发”,”盆栽”,”床”,”餐桌”,”厕所”,”电视”,”笔记本电脑”,”鼠标”,”遥控器”,”键盘”,”手机”,”微波炉”,”烤箱”,”烤面包机”, “水槽”,”冰箱”,”书籍”,”时钟”,”花瓶”,”剪刀”,”泰迪熊”,”吹风机”,”牙刷”]
max_score (float) – confidence, range: 0-100
Note
The category_list attribute returns Chinese strings — these are the
original labels produced by the K230D firmware’s built-in YOLO model (COCO
80-class). When comparing detection results in your code, you must use these
exact Chinese strings; translating them will cause mismatches at runtime.
Example usage:
# category_list[idx] returns a Chinese label such as '人' (person);
# always compare against the exact string from the library
if smart_camera.yolo_detect.category_list[smart_camera.yolo_detect.id] == '人':
print("Person detected!")