from robomaster import robot
line = []
# 重编callback回调函数
def on_detect_line(line_info):
number = len(line_info)
line.clear()
line_type = line_info[0]
# print('line_type', line_type)
for i in range(1, number):
x, y, ceta, c = line_info
line.append([x, y, ceta, c])
persons = []
def on_detect_person(person_info):
number = len(person_info)
persons.clear()
for i in range(0, number):
x, y, w, h = person_info
persons.append([x, y, w, h])
# print("person: x:{0}, y:{1}, w:{2}, h:{3}".format(x, y, w, h))
if __name__ == '__main__':
# 初始化
ep_robot = robot.Robot()
# 直连模式
ep_robot.initialize(conn_type="ap")
# 机器人版本
ep_version = ep_robot.get_version()
print("Robot Version: {0}".format(ep_version))
# 云台跟随底盘
ep_robot.set_robot_mode(mode=robot.CHASSIS_LEAD)
# 云台向下旋转10度
ep_gimbal = ep_robot.gimbal
ep_gimbal.moveto(pitch=0, yaw=0).wait_for_completed()
ep_gimbal.move(pitch=-10, yaw=0).wait_for_completed()
# 初始化麦轮
ep_chassis = ep_robot.chassis
# 启动视觉识别
ep_vision = ep_robot.vision
# 启动摄像头
ep_camera = ep_robot.camera
ep_camera.start_video_stream(display=False)
# 启动线识别
ep_vision.sub_detect_info(name="line", color="blue", callback=on_detect_line)
# 启动人识别
ep_vision.sub_detect_info(name="person", callback=on_detect_person)
# threading1 = threading.Thread(target=ep_vision.sub_detect_info, args=('line', 'blue', on_detect_line))
# threading1.start()
# time.sleep(2)
# print(line)
# threading2 = threading.Thread(target=ep_vision.sub_detect_info, args=('person', '', on_detect_person))
# threading2.start()
# time.sleep(2)
# 这里不管启动不启动多线程,后边都只能输出一个数据。而且启动行人识别后,机器还总有提示声音(怎么去除)。哪位大佬可以帮帮我,怎样在SDK中同时启用多个识别功能啊??非常感谢!! 在模块编程里面转换出来的python代码也不能直接用,有没有API代码转换SDK代码的教程?
while True:
print(persons)
print(line)