37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
from kuukar.kuukar_lcd import lcd
|
|
from kuukar.kuukar_leds import leds
|
|
from kuukar.kuukar_motion import motion
|
|
import threading
|
|
import multiprocessing
|
|
import cv2
|
|
|
|
|
|
class cv:
|
|
def __init__(self, lcd: lcd, leds: leds, motion: motion) -> None:
|
|
self.motion = motion
|
|
self.lcd = lcd
|
|
self.leds = leds
|
|
self.camera = cv2.VideoCapture(0)
|
|
threading.Thread(target=self._cv_loop).start()
|
|
|
|
def _cv_loop(self):
|
|
while True:
|
|
img = self.capture_image()
|
|
stop_signs = self.detect_sign(img)
|
|
if len(stop_signs) >= 1: # Stop Sign Found~!
|
|
self.motion.stop()
|
|
|
|
def get_road_curve(self, frame):
|
|
pass
|
|
|
|
def capture_image(self):
|
|
ret, frame = self.camera.read()
|
|
return frame
|
|
|
|
def detect_sign(self, frame):
|
|
stopsign_cascade = cv2.CascadeClassifier('./stopsign_good.xml')
|
|
image = frame.array
|
|
gray_img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
|
found_stopsigns = stopsign_cascade.detectMultiScale(gray_img, 1.1, 5)
|
|
return found_stopsigns
|