cocube_sengo1
import cocube_sengo1 as sg1
初始化
sg1.init()
sg1.reset()
sg1.change_algo("Card Recog")
说明:
init()会等待摄像头就绪,最长约5sreset()用于重置全部算法状态- 调用读取函数前,通常要先
change_algo(...)
支持的算法
"Color Recog""Blob Detect""Ball Detect""Line Detect""Card Recog""Face Recog""QRcode"
颜色识别
sg1.change_algo("Color Recog")
sg1.set_color_area(x, y, w, h)
sg1.read_color()
sg1.get_color_rgb("R")
返回颜色包括:
black、white、red、green、blue、yellow
set_color_area(x, y, w, h) 还会做边界检查,区域不能超出画面范围。
色块检测
sg1.change_algo("Blob Detect")
sg1.set_blob_property("red", w, h)
sg1.read_blob()
sg1.get_blob("x")
sg1.get_blob("y")
sg1.get_blob("w")
sg1.get_blob("h")
球检测
sg1.change_algo("Ball Detect")
sg1.detect_ball()
sg1.get_ball("x")
这一项是 Sengo1 独有,常见返回值有:
ping pongtennis ball
巡线
sg1.change_algo("Line Detect")
sg1.get_line("x1")
sg1.get_line("y1")
sg1.get_line("x2")
sg1.get_line("y2")
sg1.get_line("degree")
卡片识别
sg1.change_algo("Card Recog")
sg1.read_card()
sg1.get_card("x")
Sengo1 常见卡片包括:
forwardleftrightbackpark
人脸识别
sg1.change_algo("Face Recog")
sg1.record_face(id)
sg1.delete_face(id)
sg1.get_face_id()
sg1.get_face("x")
二维码
sg1.change_algo("QRcode")
sg1.read_qrcode()
sg1.get_qrcode("x")
read_qrcode() 返回二维码字符串内容。
注意
- 如果当前算法不匹配,读取函数会直接抛错,提示先
change_algo(...) record_face(id)/delete_face(id)的id范围是1~10
最小示例
import time
import cocube_sengo1 as sg1
sg1.init()
sg1.change_algo("Card Recog")
while True:
card = sg1.read_card()
if card:
print(card, sg1.get_card("w"))
time.sleep_ms(100)