Beispiel #1
0
def checkColor(image):
    count=0
    hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
    mask = cv2.inRange(hsv, (36, 25, 25), (70, 255,255))
    res = cv2.bitwise_and(image,image, mask=mask)
    ret,thrshed = cv2.threshold(cv2.cvtColor(res,cv2.COLOR_BGR2GRAY),3,255,cv2.THRESH_BINARY)
    _,contours,hier = cv2.findContours(thrshed,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
    for cnt in contours:
        area = cv2.contourArea(cnt)
        if area >10000:
            print('object found')
            gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
            corners()
            cv2.putText(image, 'Green Object Detected', (10,80), cv2.FONT_HERSHEY_SIMPLEX, 1.0,(255, 255, 255),lineType=cv2.LINE_AA)
            cv2.rectangle(image,(5,40),(400,100),(0,255,255),2)
            count+=1
    print('count', count)
    if count==10:
        gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
        a=corners(gray)
        j=0
        while j<20:
            dr.goCustom(90,90)
            j+=1
            n=0
            while n<1:
                dr.stop(2)
                if a =='Left':
                    dr.left()
                else:
                    dr.right()
                n=n+1
def check_turning(dis):
    if int(dis[1]) < 100:
        dr.goCustom(80, 90)
        #print("Adjusting left")
    elif int(dis[1]) > 150:
        dr.goCustom(90, 80)
        #print('Adjusting right')
    else:
        #print('going forward')
        dr.goStraight()
def check_turning(dis):
    if int(dis[0]) < 245:
        dr.goCustom(110, 90)
        print('-->')
    elif int(dis[1]) < 235:
        dr.goCustom(90, 110)
        print('<--')
    else:
        print('^')
        dr.goStraight()
def check_turning(dis):
    if int(dis[0]) < 265:
        dr.goCustom(100, 90)
        print('-->')
    elif int(dis[1]) < 255:
        dr.goCustom(100, 90)
        print('<--')
    else:
        print('^')
        dr.goStraight()
def check_turning(dis):
    if int(dis[1]) < 100:
        dr.goCustom(80, 90)
        print('left')
    elif int(dis[1]) > 150:
        dr.goCustom(90, 80)
        print('right')
    else:
        #dr.goStraight()
        dr.goStraight()
        print('straight')
Beispiel #6
0
def check_turning(dis):
    if int(dis[0]) < 150:
        dr.goCustom(110, 90)
    elif int(dis[1]) < 200:
        dr.goCustom(90, 110)
    else:
        dr.goCustom(90, 90)
Beispiel #7
0
#image = cv2.imread('roverroadvision.png')
    if turnTo:
        print('I am busy turning')
        i=0
        while True:
            checkColor(image)
            if i>20:
                TurnTo=False
                break
            i+=1
    else: 
        try:
            lane_image = np.copy(image)
            canny_image = canny(lane_image)
            cropped_image = roi(canny_image)
            lines = cv2.HoughLinesP(canny_image, 1, np.pi/180, 50, np.array([]), minLineLength=20, maxLineGap=50)
            averaged_lines, distances = average_slope_intercept(lane_image, lines)
            line_image = display_lines(lane_image, averaged_lines)
            combo_image = cv2.addWeighted(lane_image, 0.8, line_image, 1, 1)
            cv2.imshow("Result", combo_image)   
            check_turning(distances)
        except:
            cv2.imshow("Result", image)
            dr.goCustom(70,90)
            turnTo=True
    if cv2.waitKey(10) & 0xFF == ord('q'):
        cap.release()
        cv2.destroyAllWindows()
        break
cv2.waitKey(0)
                                    1,
                                    np.pi / 180,
                                    50,
                                    np.array([]),
                                    minLineLength=20,
                                    maxLineGap=50)
            averaged_lines, distances = average_slope_intercept(
                lane_image, lines)
            line_image = display_lines(lane_image, averaged_lines)
            combo_image = cv2.addWeighted(lane_image, 0.8, line_image, 1, 1)
            cv2.imshow("Result", combo_image)
            check_turning(distances)
            i += 1
            print(i)
        except:
            cv2.imshow("Result", image)
            dr.goCustom(60, 75)
            i -= 1
            print(i)

        if cv2.waitKey(10) & 0xFF == ord('q'):
            cap.release()
            cv2.destroyAllWindows()
            break

    i = 0
    dr.stop(1)
    dr.right()
    #dr.goStraight()

cv2.waitKey(0)