Exemple #1
0
 def __init__(self):
     threading.Thread.__init__(self)
     self.run_it = True
     self.gate = 0  # 0==yellow,1==blue
     self.gates = [None, None]
     self.gates_last = [[999, 0], [999, 0]]
     self.frame_balls = []  # balls[]=[x,y,w,h,area]
     self.largest_ball = None
     self.fps = 60
     with open("colors/colors.pkl", "rb") as fh:  # color lookup table
         self.colors_lookup = pickle.load(fh)
         segment.set_table(self.colors_lookup)  # load table to C module
     self.CAM_D_ANGLE = 60 * np.pi / 180 / 640
     with open("distances.pkl", "rb") as fh:  # fitted distance parameters
         self.CAM_HEIGHT, self.CAM_DISTANCE, self.CAM_ANGLE, self.Y_FAR, self.X_a, self.X_b, self.W_a, self.W_b = pickle.load(
             fh
         )
     self.H_BALL = 2.15  # half height
     self.H_GATE = 10  # half height
     self.fragmented = np.zeros((480, 640), dtype=np.uint8)
     self.t_ball = np.zeros((480, 640), dtype=np.uint8)
     self.t_gatey = np.zeros((480, 640), dtype=np.uint8)
     self.t_gateb = np.zeros((480, 640), dtype=np.uint8)
     self.t_debug = np.zeros((480, 640, 3), dtype=np.uint8)
     self.debugi = 0
     self.ball_history = deque([], maxlen=60)
     self.gate = 0
     self.t_debug_locked = False
     self.angle_fix = 0
     ys, xs = np.mgrid[:480, :640]
     self.ball_way = np.abs(xs - self.X_b - ys * self.X_a) < self.W_b + 4 + ys * self.W_a
     self.yarr = np.arange(480)
     self.xmid = np.round(self.yarr * self.X_a + self.X_b).astype("uint16")
Exemple #2
0
 def __init__(self):
     threading.Thread.__init__(self)
     self.run_it = True
     self.gate = 0  #0==yellow,1==blue
     self.gates = [None, None]
     self.gates_last = [[999, 0], [999, 0]]
     self.frame_balls = []  #balls[]=[x,y,w,h,area]
     self.largest_ball = None
     self.fps = 60
     with open('colors/colors.pkl', 'rb') as fh:  #color lookup table
         self.colors_lookup = pickle.load(fh)
         segment.set_table(self.colors_lookup)  #load table to C module
     self.CAM_D_ANGLE = 60 * np.pi / 180 / 640
     with open('distances.pkl', 'rb') as fh:  #fitted distance parameters
         self.CAM_HEIGHT, self.CAM_DISTANCE, self.CAM_ANGLE, self.Y_FAR, self.X_a, self.X_b, self.W_a, self.W_b = pickle.load(
             fh)
     self.H_BALL = 2.15  #half height
     self.H_GATE = 10  #half height
     self.fragmented = np.zeros((480, 640), dtype=np.uint8)
     self.t_ball = np.zeros((480, 640), dtype=np.uint8)
     self.t_gatey = np.zeros((480, 640), dtype=np.uint8)
     self.t_gateb = np.zeros((480, 640), dtype=np.uint8)
     self.t_debug = np.zeros((480, 640, 3), dtype=np.uint8)
     self.debugi = 0
     self.ball_history = deque([], maxlen=60)
     self.gate = 0
     self.t_debug_locked = False
     self.angle_fix = 0
     ys, xs = np.mgrid[:480, :640]
     self.ball_way = np.abs(xs - self.X_b -
                            ys * self.X_a) < self.W_b + 4 + ys * self.W_a
     self.yarr = np.arange(480)
     self.xmid = np.round(self.yarr * self.X_a + self.X_b).astype('uint16')
Exemple #3
0
import segment
import numpy as np
import cPickle as pickle
import time
import cv2

with open("../colors.pkl", "rb") as fh:
    colors_lookup = pickle.load(fh)

segment.set_table(colors_lookup)

cap = cv2.VideoCapture(0)
if not cap.isOpened():
    print("cam not opened")
    exit()
_, yuv = cap.read()
cap.release()

timea = time.time()
for i in xrange(60):
    ob = yuv.astype("uint32")
    fragmented = colors_lookup[ob[:, :, 0] + ob[:, :, 1] * 0x100 + ob[:, :, 2] * 0x10000]
    t_ball = (fragmented == 1).view("uint8")
    t_gatey = (fragmented == 2).view("uint8")
    t_gateb = (fragmented == 3).view("uint8")
print(time.time() - timea)
print(fragmented.shape)

while True:
    cv2.imshow("tava", t_ball * 255)
    if cv2.waitKey(1) & 0xFF == ord("q"):
Exemple #4
0
import segment
import numpy as np
import cPickle as pickle
import time
import cv2

with open('../colors.pkl', 'rb') as fh:
    colors_lookup = pickle.load(fh)

segment.set_table(colors_lookup)

cap = cv2.VideoCapture(0)
if not cap.isOpened():
    print('cam not opened')
    exit()
_, yuv = cap.read()
cap.release()

timea = time.time()
for i in xrange(60):
    ob = yuv.astype('uint32')
    fragmented = colors_lookup[ob[:, :, 0] + ob[:, :, 1] * 0x100 +
                               ob[:, :, 2] * 0x10000]
    t_ball = (fragmented == 1).view('uint8')
    t_gatey = (fragmented == 2).view('uint8')
    t_gateb = (fragmented == 3).view('uint8')
print(time.time() - timea)
print(fragmented.shape)

while True:
    cv2.imshow('tava', t_ball * 255)