예제 #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
예제 #2
0
def turn(direction):
    if direction == 'Left':
        stop(3)
        dr.goStraight()
        time.sleep(2)
        dr.stop(1)
        dr.left()
        #print('Turning left')
    if direction == 'Right':
        stop(3)
        dr.goStraight()
        time.sleep(2)
        dr.stop(1)
        dr.right()
예제 #3
0
while True:
    _, frame = cap.read()

    direction_list = []

    if turn_com == False:
        try:
            image_with_lanes, distance = detect_lanes(frame)
            check_turning(distance)
            cv2.imshow('Result', image_with_lanes)
            out.write(image_with_lanes)
        except:
            cv2.imshow('Result', frame)
            out.write(frame)
            turn_com = True
            dr.stop(0.5)
            print('Stop')
    else:
        try:
            image_with_h_lane, turn_command = detect_h_line(frame)
            cv2.imshow('Result', image_with_h_lane)
            out.write(image_with_h_lane)
            print('Going for forward horizontal line')
            dr.goStraight()
            if turn_command == True:
                print('stop')
                dr.stop(0.5)
                for i in range(5):
                    arrow_image, direction = arrow_detection(frame)
                    direction_list.append(direction)
                    cv2.imshow('Result', arrow_image)
예제 #4
0
파일: stop.py 프로젝트: bburke20/366
import direction
direction.stop()
                                    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)