Huskylens二哈识图
# https://bxy.dfrobot.com.cn/bit_huskylens
from microbit import *
from huskylens import Huskylens,Parameter
husky = Huskylens() #huskylens初始化 ,接线:哈士奇接到I2C口SCL SDA
algorithm = "ALGORITHM_FACE_RECOGNITION" # 人脸识别
#algorithm = "ALGORITHM_OBJECT_TRACKING" # 物体追踪
#algorithm = "ALGORITHM_OBJECT_RECOGNITION" # 物体识别
#algorithm = "ALGORITHM_LINE_TRACKING" # 巡线
#algorithm = "ALGORITHM_COLOR_RECOGNITION" # 颜色识别
#algorithm = "ALGORITHM_TAG_RECOGNITION" # 标签识别
#algorithm = "ALGORITHM_OBJECT_CLASSIFICATION" # 物体分类
#algorithm = "ALGORITHM_QR_RECOGNITION" # 二维码识别(仅高配版有)
#algorithm = "ALGORITHM_BARCODE_RECOGNITION" # 条形码识别(仅高配版有)
husky.command_request_algorthim(algorithm) #切换识别模式
husky.command_request_clear_text() # 清除所有屏幕显示的文字
#husky.command_request_photo() #保存摄像头照片,需插上内存卡
#husky.command_request_screenshot() #保存屏幕截图照片,需插上内存卡
husky_type = "blocks" # 方框
#husky_type = "arrows" # 箭头
while True:
data = husky.command_request() #请求一次数据 存入结果
count = husky.read_count(husky_type) #从结果中取方框/箭头总数
#依次从结果中取每个方框/箭头的数据
for i in range(count):
print("data[%s]:"%(i))
print("X_center:", husky.read_blocks_arrows_parameter_direct(Parameter.xCenter, husky_type, i+1)) #从结果中取方框或箭头的数据,取中心x坐标
print("y_center:", husky.read_blocks_arrows_parameter_direct(Parameter.yCenter, husky_type, i+1)) #从结果中取方框或箭头的数据,取中心y坐标
print("width:", husky.read_blocks_arrows_parameter_direct(Parameter.width, husky_type, i+1)) #从结果中取方框或箭头的数据,取方框宽
print("height:", husky.read_blocks_arrows_parameter_direct(Parameter.height, husky_type, i+1)) #从结果中取方框或箭头的数据,取方框高
print("ID:", husky.read_blocks_arrows_parameter_direct(Parameter.id, husky_type, i+1)) #从结果中取方框或箭头的数据,取id
if button_a.is_pressed(): #按下micro:bit A键
id = 1
husky.command_request_learn_once(id) #学习一次
husky.command_request_customnames(id,"TEST") #设置学习的id名字
husky.command_request_custom_text("id:"+str(id),25,52) #在屏幕上显示文字数字或字母,一次最长20字符
elif button_b.is_pressed(): #按下micro:bit B键
husky.command_request_forget() #遗忘所有学习的内容
husky.command_request_clear_text() # 清除所有屏幕显示的文字
sleep(100)