Exemplo n.º 1
0
def run():
    capL = cv2.VideoCapture(1)
    capL.set(cv2.CAP_PROP_FRAME_WIDTH, BINCAP_W)
    capL.set(cv2.CAP_PROP_FRAME_HEIGHT, BINCAP_H)
    capR = cv2.VideoCapture(0)
    capR.set(cv2.CAP_PROP_FRAME_WIDTH, BINCAP_W)
    capR.set(cv2.CAP_PROP_FRAME_HEIGHT, BINCAP_H)
    while True:
        disparity = util.getDisparity(capL.read(), capR.read())
        cv2.imshow('disparity', disparity)
        orient = util.getOriention(disparity)
        if orient == 2:
            print 'forward'
            continue

        while orient == 0:
            print 'backward'
            disparity = util.getDisparity(capL.read(), capR.read())
            cv2.imshow('disparity', disparity)
            orient = util.getOriention(disparity)

        while orient == 1:
            turn = turnTo(disparity)
            # turn left
            if turn == 3:
                while orient != 2:
                    print 'turn left'
                    disparity = util.getDisparity(capL.read(), capR.read())
                    cv2.imshow('disparity', disparity)
                    orient = util.getOriention(disparity)
            # turn right
            elif turn == 4:
                while orient != 2:
                    print 'turn right'
                    disparity = util.getDisparity(capL.read(), capR.read())
                    cv2.imshow('disparity', disparity)
                    orient = util.getOriention(disparity)
        # end
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    cap0.release()
    cap1.release()
    cv2.destroyAllWindows()
Exemplo n.º 2
0
def run():
    capL = cv2.VideoCapture(1)
    capL.set(cv2.CAP_PROP_FRAME_WIDTH, BINCAP_W)
    capL.set(cv2.CAP_PROP_FRAME_HEIGHT, BINCAP_H)
    capR = cv2.VideoCapture(0)
    capR.set(cv2.CAP_PROP_FRAME_WIDTH, BINCAP_W)
    capR.set(cv2.CAP_PROP_FRAME_HEIGHT, BINCAP_H)
    while True:
        disparity = util.getDisparity(capL.read(), capR.read())
        cv2.imshow('disparity', disparity)
        orient = util.getOriention(disparity)
        if orient == 2:
            print 'forward'
            continue

        while orient == 0:
            print 'backward'
            disparity = util.getDisparity(capL.read(), capR.read())
            cv2.imshow('disparity', disparity)
            orient = util.getOriention(disparity)

        while orient==1:
            turn = turnTo(disparity)
            # turn left
            if turn==3:
                while orient!=2:
                    print 'turn left'
                    disparity = util.getDisparity(capL.read(), capR.read())
                    cv2.imshow('disparity', disparity)
                    orient = util.getOriention(disparity)
            # turn right
            elif turn==4:
                while orient!=2:
                    print 'turn right'
                    disparity = util.getDisparity(capL.read(), capR.read())
                    cv2.imshow('disparity', disparity)
                    orient = util.getOriention(disparity)
        # end
        if cv2.waitKey(1) & 0xFF==ord('q'):
            break
    cap0.release()
    cap1.release()
    cv2.destroyAllWindows()
Exemplo n.º 3
0
    def handle(self):
        print 'get connection from :',self.client_address
        imgL = np.zeros((BINCAP_H, BINCAP_W, 3), np.uint8)
        imgR = np.zeros((BINCAP_H, BINCAP_W, 3), np.uint8)
        while True:
            try:
                data = self.request.recv(16)
                print 'receive data:',data
                if not data:
                    print 'break connection!'
                    break
                else:
                    action = str(data).strip()
                    if action == 'put':
                        self.request.send('ready')
                        stringDataL = self.recvdata()
                        stringDataR = self.recvdata()
                    else:
                        print 'receive error!'
                        continue

                imgL[50:100] = cv2.imdecode(np.fromstring(stringDataL, dtype='uint8'), 1)
                imgL_640_480 = cv2.resize(imgL, (BINIMG_W, BINIMG_H), interpolation=cv2.INTER_CUBIC)
                # cv2.imshow('L', imgL_640_480)
                #
                imgR[50:100] = cv2.imdecode(np.fromstring(stringDataR, dtype='uint8'), 1)
                imgR_640_480 = cv2.resize(imgR, (BINIMG_W, BINIMG_H), interpolation=cv2.INTER_CUBIC)
                # cv2.imshow('R', imgR_640_480)

                disparity = util.getDisparity(imgL_640_480, imgR_640_480)
                # cv2.imshow('disparity',np.uint8(disparity))

                orient = util.getOriention(disparity)
                self.request.send(str(orient))

                if cv2.waitKey(1) & 0xff==ord('q'):
                    self.request.send('end')
                    cv2.destroyAllWindows()
                    break
            except Exception,e:
                print 'error:',e
                break