-
Notifications
You must be signed in to change notification settings - Fork 1
/
road_sign_recognition.py
68 lines (58 loc) · 2.09 KB
/
road_sign_recognition.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import cv2 as cv
import numpy as np
import threading
import struct
import time
from utils.RoadSignRecognition import RoadSignRecognition
from utils.Controller import Controller
Develop_Mode = True # True means use computer camera. False means use dog camera
client_address = ("192.168.1.103", 43897)
server_address = ("192.168.1.120", 43893)
if __name__ == '__main__':
sign_detector = RoadSignRecognition()
controller = Controller(server_address)
if Develop_Mode:
cap = cv.VideoCapture(0)
else:
cap = cv.VideoCapture("/dev/video0", cv.CAP_V4L2)
# cap.set(cv.CAP_PROP_FRAME_WIDTH, 1920)
# cap.set(cv.CAP_PROP_FRAME_HEIGHT, 1080)
stop_heartbeat = False
# start to exchange heartbeat pack
def heart_exchange(con):
pack = struct.pack('<3i', 0x21040001, 0, 0)
while True:
if stop_heartbeat:
return
con.send(pack)
time.sleep(0.25) # 4Hz
heart_exchange_thread = threading.Thread(target=heart_exchange, args=(controller,))
heart_exchange_thread.start()
# stand up
print("Wait 10 seconds and stand up......")
pack = struct.pack('<3i', 0x21010202, 0, 0)
controller.send(pack)
time.sleep(5)
controller.send(pack)
time.sleep(5)
controller.send(pack)
print("Dog should stand up, otherwise press 'ctrl + c' and re-run the demo")
while True :
ret, frame = cap.read()
if not ret:
continue
bbox = sign_detector.detect(frame)
frame = sign_detector.visualize(frame)
sign = sign_detector.classify(frame)
if sign is not None:
print(sign)
cv.imshow("Road Sign Recognition", frame)
k = cv.waitKey(1)
if k == 113 or k == 81: # q or Q to quit
print("Demo is quiting......")
if not Develop_Mode:
controller.drive_dog("squat")
cap.release()
cv.destroyWindow("Road Sign Recognition")
stop_heartbeat = True
break