-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
54 lines (49 loc) · 1.34 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import sys
import numpy as np
import cv2
import RPi.GPIO as GPIO
from TrafficLight import findLight
from carTest import findCar
video = cv2.VideoCapture(0)
success,image = video.read()
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(12,GPIO.OUT)
GPIO.setup(18,GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
while success:
cv2.imwrite("test.jpg", image)
result1, modImage = findLight("red")
result2, carImage = findCar()
result = result1 and result2
if result1:
toprint = "Red Light"
if result2:
toprint = "Car"
if result :
print("STOP, Red Light and Car")
state = GPIO.input(18)
if state == False:
GPIO.output(18,GPIO.HIGH)
GPIO.output(12,GPIO.LOW)
GPIO.output(13,GPIO.LOW)
elif result1 or result2:
print("CAUTION, %s", toprint)
state = GPIO.input(13)
if state == False:
GPIO.output(13,GPIO.HIGH)
GPIO.output(12,GPIO.LOW)
GPIO.output(18,GPIO.LOW)
else :
print("NONE")
state = GPIO.input(12)
if state == False:
GPIO.output(12,GPIO.HIGH)
GPIO.output(13,GPIO.LOW)
GPIO.output(18,GPIO.LOW)
success, image = video.read()
GPIO.output(12,GPIO.LOW)
GPIO.output(18,GPIO.LOW)
GPIO.output(13,GPIO.LOW)
video.release()
cv2.destroyAllWindows()