def main(): global isDriving global CAR, PERSON, STOP_SIGN, TRAFFIC_LIGHT cap = cv2.VideoCapture(1) print(cap.isOpened()) from_android() isDriving = 1 if (isDriving == 1): while cap.isOpened(): ret, frame = cap.read() frame = cv2.resize(frame, (width, height)) if (CAR == True): to_arduino('car') CAR = False elif (PERSON == True): to_arduino('person') PERSON = False elif (STOP_SIGN == True): to_arduino('stop_sign') STOP_SIGN = False elif (TRAFFIC_LIGHT == True): to_arduino('traffic_light') TRAFFIC_LIGHT = False try: frame, point = get_lane(frame) print("point, ", point) if point == -1: print("no left no right") elif point == -2: to_arduino("left") print("no left") elif point == -3: to_arduino("right") print("no right") else: get_direction(point) except: #print("error") pass cv2.imshow('0825', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cv2.destroyAllWindows() cap.release()
def main(): global isDriving cap = cv2.VideoCapture(1) print(cap.isOpened()) from_android() isDriving = 1 if (isDriving == 1): while cap.isOpened(): ret, frame = cap.read() frame = cv2.resize(frame, (width, height)) cv2.imwrite("temp.jpg", frame) try: frame, point = get_lane(frame) print("point, ", point) if point == -1: print("no left no right") elif point == -2: to_arduino("left") print("no left") elif point == -3: to_arduino("right") print("no right") else: get_direction(point) except: #print("error") pass cv2.imshow('0825', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cv2.destroyAllWindows() cap.release()
#-*- coding: utf-8 -*- import cv2,socket from line import get_lane ip = '192.168.43.134' # 라즈베리파이 주소 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_address = (ip ,3000) sock.connect(server_address) cap = cv2.VideoCapture(0) # 노트북 유에스비 while cap.isOpened(): try: ret, frame = cap.read() try: frame, point, num = get_lane(frame) print "x좌표=",point,"선 개수=",num sock.send(point.encode()) sock.send(num.encode()) except Exception, e: print e pass cv2.imshow('get_lane', frame) if cv2.waitKey(1) & 0xFF == ord('q'): sock.send("1111".encode()) sock.send("9".encode()) break
elif CAR_CENTER < x_point: if curve > 40 and curve < 140: curve+=2 #cap = cv2.VideoCapture('challenge_video.mp4') cap = cv2.VideoCapture(1) print(cap.isOpened()) while cap.isOpened(): ret, frame = cap.read() frame = cv2.resize(frame, (width, height)) try: frame, point = get_lane(frame) if point == -1: print("no left no right") elif point == -2: if curve > 40 and curve < 140: curve-=2 to_arduino(str(curve)) print("no left") elif point == -3: if curve > 40 and curve < 140: curve+=2 to_arduino(str(curve)) print("no right") else: print("left and right")