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
예제 #3
0
def demo_line_algrithm(ip, speed, dis):
    """
    利用图像传统知识进行巡线,对图像进行二值化,选取组最大的轮廓的中心点。图像的长640,宽480。
     0  左转 250  直行 320  直行 380 右转  640

     Parameter
     --------
     * ip:string
        -树莓派的IP
     * speed:int
        -小车运行速度
     * dis:float
        -运行的时间,控制距离
    """
    #相机的初始化
    camera = Camera()
    camera.connect_server(ip)
    camera.start_receive()
    camera.thread_play()
    #算法初始化
    algithm = Algrithm()
    #小车初始化
    car = Car(ip)

    global STOP_FLAGE
    while True:
        pic = camera.take_picture()
        pt = algithm.line(pic, 60)
        # algithm.set_debug()
        x = pt[0]
        print('%d和320比较' % x)
        if 250 < x < 380:
            car.run_forward(speed, dis)  #直行
        elif x < 250:
            print("spin left")
            car.turn_left(speed * 0.6, dis)  #左转
        elif x > 380:
            print("spin right")
            car.turn_right(speed * 0.6, dis)  #右转
        if STOP_FLAGE:
            return
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 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