np.ones(10) * 32000, np.zeros(1000) ]), dtype=np.int16) pip_3 = np.array(np.concatenate([ np.zeros(1000), np.ones(5) * -32000, np.ones(5) * 32000, np.ones(5) * -32000, np.zeros(1000) ]), dtype=np.int16) fs = 44100 while True: frame = plr.read() # get size and position of biggest colour splotch p2, p1, p0 = det.predict(frame) if max(p0, p1, p2) < 0.87: # too small p0 = p1 = p2 = 0 drv.stop() # add them to counters left += (10e-2 * p0) center += (10e-2 * p1) right += (10e-2 * p2) left_spikes = nrn_left.update(left, pip=pip_1, fs=fs) center_spikes = nrn_center.update(center, pip=pip_2, fs=fs) right_spikes = nrn_right.update(right, pip=pip_3, fs=fs)
from utils.player import Player from utils.driver import Driver from utils.detector import Detector # initialize videoplayer, car driver, and cup detector plr = Player() drv = Driver() det = Detector("cup") while True: ret, frame = plr.read() p0, p1, p2 = det.predict(frame) print("------------") print(p0, "|", p1, "|", p2) print("------------") # if a cup is likely >50% on screen, engage movement if max(p0, p1, p2) > 0.5: if p2 > p1 and p2 > p0: drv.right() elif p0 > p1 and p0 > p2: drv.left() else: drv.forward() # remember to close the streams drv.close() plr.close()