-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
81 lines (71 loc) · 2.61 KB
/
Main.py
File metadata and controls
81 lines (71 loc) · 2.61 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from picamera.array import PiRGBArray
from picamera import PiCamera
import serial
import cv2
import time
from Blue_Ball_Detection_Contour import Blue_Ball_Detection
from Red_Ball_Detection_Contour import Red_Ball_Detection
from Basket_Detection_Contour import Basket_Detection
from Boundary_Check import Boundary_Check
ser = serial.Serial('/dev/ttyUSB0',9600)
camera = PiCamera()
camera.awb_mode = 'fluorescent' # Options: auto,fluorescent,flash
camera.resolution = (544, 544)
camera.hflip = True
camera.vflip = True
rawCapture = PiRGBArray(camera, size=(544, 544))
# Allow the camera to warm up
time.sleep(0.1)
while True:
state = ser.readline()
rawCapture.truncate(0)
state = state.decode('utf-8')
# Depending on the received message find the needed feature
if (state == "findball_1_b\n"):
camera.capture(rawCapture, format="bgr")
image = rawCapture.array
image = Boundary_Check(image)
operation = Blue_Ball_Detection(image)
operation = 'm1_'+ operation
operation = operation.encode('utf-8')
ser.write(operation)
elif (state == "findball_2_b\n"):
camera.capture(rawCapture, format="bgr")
image = rawCapture.array
image = Boundary_Check(image)
operation = Blue_Ball_Detection(image)
operation = 'm2_'+ operation
operation = operation.encode('utf-8')
ser.write(operation)
elif (state == "findball_1_r\n"):
camera.capture(rawCapture, format="bgr")
image = rawCapture.array
image = Boundary_Check(image)
operation = Red_Ball_Detection(image)
operation = 'm1_'+ operation
operation = operation.encode('utf-8')
ser.write(operation)
elif (state == "findball_2_r\n"):
camera.capture(rawCapture, format="bgr")
image = rawCapture.array
image = Boundary_Check(image)
operation = Red_Ball_Detection(image)
operation = 'm2_'+ operation
operation = operation.encode('utf-8')
ser.write(operation)
elif (state=="findbasket_1\n"):
camera.capture(rawCapture, format="bgr")
image = rawCapture.array
operation = Basket_Detection(image)
operation = 'm1_'+ operation
operation = operation.encode('utf-8')
ser.write(operation)
elif (state=="findbasket_2\n"):
camera.capture(rawCapture, format="bgr")
image = rawCapture.array
operation = Basket_Detection(image)
operation = 'm2_'+ operation
operation = operation.encode('utf-8')
ser.write(operation)
else:
print("Error")