def demo_ai_camera_speaker(ip): """ 智能相机的构建,实时识别相机中的物体 间隔一段时间,把识别的物体朗读出来 Parameter -------- *ip:string -树莓派的IP """ camera = Camera() camera.connect_server(ip) camera.start_receive() ai = Ai() speaker = Speaker() interval = 20 times = 0 while True: pic = camera.take_picture() ret,names,box= ai.find_object(pic) cv2.imshow("ai", ret) cv2.waitKey(1) times = times + 1 if times > interval: times = 0 if len(names) > 0: speaker.say('i find') for item in names: speaker.say(item) if len(names) > 0: speaker.say('in the picture')
def demo_line_ai(ip, speed, dis): """ 利用训练数据进行巡线 Param ----- *ip: string -树莓的ip *speed: int -运行速度 *dis: int -检测一次走的距离 """ #相机初始化 camera = Camera() camera.connect_server(ip) camera.start_receive() # camera.thread_play() #车初始化 car = Car(ip) #Ai初始化,自己训练的结果 ai = Ai() global STOP_FLAGE while True: pic = camera.take_picture() #cv2.imread("./aiLib/line/line.jpg")# ret, name, box = ai.find_object(pic) cv2.imshow('test', ret) cv2.waitKey(1) # continue x = 0 if len(name) == 0: #没有检测到线 continue for item in name: if item == 'line': x = box[0][0] print(x, type(x)) if 250 < x < 380: car.run_forward(speed, dis) #直行 elif x < 250: print("spin right") car.turn_left(speed * 0.6, dis) #左转 elif x > 380: print("spin left") car.turn_right(speed * 0.6, dis) #右转 if STOP_FLAGE: return
def demo_step_find_object(ip, speed=20, dis=1, object='cup', vAngle=30, hAngle=90): """ 移动,一步一步的寻找物体 Parameter ------- *ip:string -树莓派的 *object:string -要寻找的物体 *vAngle:int -垂直方向的角度 *hAngle:int -水平方向的角度 *speed:int -移动的速度 *dis:float -时间间隔 """ # 初始化 car = Car(ip) # 相机初始化 camera = Camera() camera.connect_server(ip) camera.start_receive() camera.thread_play() ai = Ai(classes="./aiLib/coco/coco.names", config="./aiLib/coco/yolov3.cfg", weight="./aiLib/coco/yolov3.weights") car.turn_servo_camera_vertical(vAngle) car.turn_servo_camera_horizental(hAngle) global STOP_FLAGE while True: if STOP_FLAGE is True: print('over .............................................') return status = get_status_with_camera(car, camera, ai, object) car.turn_servo_camera_horizental(90) print(status) if status == 'status_move': car.run_forward(speed, dis) if status == 'status_turn_right': car.spin_right(10, 0.4) if status == 'status_turn_left': car.spin_left(10, 0.4) if status == 'status_stop': return
def demo_shaking_camera_find_object1(ip, object): """ 控制相机的舵机寻找物体,让相机上下水平进行旋转,寻找物体 Parameter --- *object:string -要寻找的物体 """ print(type(object)) global STOP_FLAGE camera = Camera() camera.connect_server(ip) camera.start_receive() camera.thread_play() car = Car(ip) ai = Ai() speaker = Speaker() for pos in range(25, 55, 15): car.turn_servo_camera_vertical(pos) for angle in range(20, 180, 20): car.turn_servo_camera_horizental(angle) time.sleep(2) #图像稳定时间 picture = camera.take_picture() frame, names, _ = ai.find_object(picture) if STOP_FLAGE: return print(names) for item in names: if item == object: speaker.say("find a") speaker.say(item) cv2.imshow('result', frame) cv2.waitKey(0) return
def demo_ai_camera(ip): """ 智能相机的构建,实时识别相机中的物体 Parameter ---- *ip:string -树莓派的Ip """ camera = Camera() camera.connect_server(ip) camera.start_receive() ai = Ai() while True: pic = camera.take_picture() ret, names, box = ai.find_object(pic) cv2.imshow("ai", ret) k = cv2.waitKey(1) if k == 27: # wait for ESC key to exit cv2.destroyAllWindows() break
def demo_move_step_find_object1(ip, speed=20, dis=1, object='cup', vAngle=65, hAngle=90): """ 连续移动寻找物体 Parameter ------- *ip:string -树莓派的Ip *object:string -要寻找的物体 *vAngle:int -垂直方向的角度 *hAngle:int -水平方向的角度 """ camera = Camera() camera.connect_server(ip) camera.start_receive() ai = Ai() mainThread_ = threading.Thread(target=find_object, args=( camera, ai, object, )) mainThread_.start() #启动相机查看功能 moveThread_ = threading.Thread(target=move_step_find_object1_thread, args=( ip, camera, ai, object, vAngle, hAngle, )) moveThread_.start() #启动寻物 camera.play() #图像显示
def demo_move_find_object(ip, object, vAngle=30, hAngle=90): """ 连续移动寻找物体 Parameter ------- *ip:string -树莓派的Ip *object:string -要寻找的物体 *vAngle:int -垂直方向的角度 *hAngle:int -水平方向的角度 """ car = Car(ip) camera = Camera() camera.connect_server(ip) camera.start_receive() camera.thread_play() ai = Ai(classes="./aiLib/coco/coco.names", config="./aiLib/coco/yolov3.cfg", weight="./aiLib/coco/yolov3.weights") car.turn_servo_camera_vertical(vAngle) car.turn_servo_camera_horizental(hAngle) mainThread_ = threading.Thread(target=find_object, args=( camera, ai, object, )) mainThread_.start() Cruising(car, 6) # 以4的速度进行漫游
def __init__(self, ip="172.16.10.227"): """ 初始化,区别coco.names;yolov3.cfg;yolov3.weights文件放在aiLib文件夹中; 启动相机服务 Parameter -------- --ip string类型,default "172.16.10.227" , """ global figure figure = Figure() figure.load_model("model\model.ckpt") print("init camera") self.camera = Camera() self.camera = Camera() self.camera.connect_server(ip) self.camera.start_receive() self.ai = Ai() self.speaker = Speaker()
def demo_move_step_find_object(ip, speed=20, dis=1, object='cup', vAngle=40, hAngle=80): """ 连续移动寻找物体 Parameter ------- *ip:string -树莓派的Ip *object:string -要寻找的物体 *vAngle:int -垂直方向的角度 *hAngle:int -水平方向的角度 """ car = Car(ip) camera = Camera() camera.connect_server(ip) camera.start_receive() camera.thread_play() ai = Ai(classes="./aiLib/coco/coco.names", config="./aiLib/coco/yolov3.cfg", weight="./aiLib/coco/yolov3.weights") car.turn_servo_camera_vertical(vAngle) car.turn_servo_camera_horizental(hAngle) mainThread_ = threading.Thread(target=find_object, args=( camera, ai, object, )) mainThread_.start() Cruising(car, 4) # 以4的速度进行漫游 car.turn_servo_camera_vertical(vAngle) car.turn_servo_camera_horizental(hAngle) global STOP_FLAGE while CAMERA_FLAGE: if STOP_FLAGE == True: car.stop_all_wheels() print('over .............................................') return status = get_status_with_camera(car, camera, ai, object) car.turn_servo_camera_horizental(90) print(status) if status == 'status_move': car.run_forward(speed, dis) if status == 'status_turn_right': car.spin_right(10, 0.4) if status == 'status_turn_left': car.spin_left(10, 0.4) if status == 'status_stop': return