cocube_sengo2
import cocube_sengo2 as sg2
初始化
sg2.init()
sg2.reset()
sg2.change_algo("AprilTag")
说明:
init()会等待摄像头就绪,最长约5sreset()用于重置全部算法- 多数读取函数都要求先切到对应算法
支持的算法
"Color Recog""Blob Detect""AprilTag""Line Detect""Deep Learning""Card Recog""Face Recog""Obj20Class""QRcode""Motion Detect"
颜色识别
sg2.change_algo("Color Recog")
sg2.set_color_area(x, y, w, h)
sg2.read_color()
sg2.get_color_rgb("R")
色块检测
sg2.change_algo("Blob Detect")
sg2.set_blob_property("red", w, h)
sg2.read_blob()
sg2.get_blob("x")
AprilTag
sg2.change_algo("AprilTag")
sg2.set_apriltag_type("36H11")
sg2.read_apriltag()
sg2.get_apriltag("x")
可选族:
16H525H936H11
巡线
sg2.change_algo("Line Detect")
sg2.get_line("degree")
sg2.get_line("x2")
深度学习
sg2.change_algo("Deep Learning")
sg2.record_learning(id)
sg2.delete_learning(id)
sg2.get_learning_id()
说明:
record_learning(id)/delete_learning(id)的id范围是1~15get_learning_id()返回当前识别到的学习类别 ID
卡片识别
sg2.change_algo("Card Recog")
sg2.read_card()
sg2.get_card("x")
Sengo2 的卡片集比 Sengo1 更大,常见包括:
forwardturn_leftturn_rightturn_aroundparkgreen_lightred_lightspeed_40speed_60speed_80
人脸、20 类物体、二维码、运动检测
sg2.change_algo("Face Recog")
sg2.record_face(id)
sg2.delete_face(id)
sg2.get_face_id()
sg2.change_algo("Obj20Class")
sg2.read_obj20()
sg2.get_obj20("x")
sg2.change_algo("QRcode")
sg2.read_qrcode()
sg2.change_algo("Motion Detect")
sg2.get_motion("x")
说明:
record_face(id)/delete_face(id)的id范围是1~10Face Recog这一组只直接提供人脸 ID,不提供x / y / w / h位置框read_obj20()返回 20 类物体名称,例如person、car、catread_qrcode()返回二维码字符串内容get_motion("x" / "y" / "w" / "h")返回运动区域
注意
set_apriltag_type(...)只接受16H5、25H9、36H11- Sengo2 颜色识别在未识别到明确颜色时,可能返回
unknown
最小示例
import time
import cocube_sengo2 as sg2
sg2.init()
sg2.change_algo("Color Recog")
while True:
color_name = sg2.read_color()
if color_name:
print(color_name)
time.sleep_ms(100)