def main(): args = get_args() # Creating a kernel for the morphology operations kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (11, 11)) # Init the ColorTracker object tracker = color_tracker.ColorTracker(max_nb_of_objects=5, max_nb_of_points=20, debug=True) # Setting a callback which is called at every iteration callback = partial(tracking_callback, verbose=args.verbose) tracker.set_tracking_callback(tracking_callback=callback) # Start tracking with a camera with color_tracker.WebCamera(video_src=0) as webcam: # Start the actual tracking of the object tracker.track(webcam, hsv_lower_value=args.low, hsv_upper_value=args.high, min_contour_area=args.contour_area, kernel=kernel)
moveX, moveY = choose_angles(throw_mode, angle) trigger = False # if trigger and throw_mode == 1: # command = "trig" # moveX, moveY = choose_angles(throw_mode, angle) # trigger = False cs.sendto("{0},{1},{2}".format(command, moveX, moveY).encode(), ('192.168.1.27', 12345)) last_finger_center = finger_center_filtered last_joint_center = joint_center_filtered if __name__ == "__main__": webcam = color_tracker.WebCamera(video_src=1) webcam.start_camera() kernel1 = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (8, 8)) kernel2 = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)) tracker = color_tracker.ColorTracker(camera=webcam, max_nb_of_points=10, debug=True) tracker.set_tracking_callback(tracking_callback=tracking_callback) tracker.track(hsv_lower_values=[(37, 75, 44), (0, 164, 192)], hsv_upper_values=[(87, 255, 253), (255, 255, 255)], min_contour_areas=[150, 50], kernels=[kernel1, kernel2],
# Visualizing the original frame and the debugger frame cv2.imshow("original frame", tracker.frame) cv2.imshow("debug frame", tracker.debug_frame) # Stop the script when we press ESC key = cv2.waitKey(1) if key == 27: tracker.stop_tracking() for obj in tracker.tracked_objects: print("Object {0} center {1}".format(obj.id, obj.last_point)) # Creating a kernel for the morphology operations kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (11, 11)) # Init the ColorTracker object tracker = color_tracker.ColorTracker(max_nb_of_objects=5, max_nb_of_points=20, debug=True) # Setting a callback which is called at every iteration tracker.set_tracking_callback(tracking_callback=tracking_callback) # Start tracking with a camera with color_tracker.WebCamera(video_src=0) as webcam: # Start the actual tracking of the object tracker.track(webcam, hsv_lower_value=HSV_LOWER_VALUE, hsv_upper_value=HSV_UPPER_VALUE, min_contour_area=2500, kernel=kernel)
import cv2 import color_tracker def tracker_callback(t: color_tracker: ColorTracker): cv2.imshow('debug', t.debug_frame) cv2.waitKey(1) tracker = color_tracker.ColorTracker( max_nb_of_objects=1, max_nb_of_points=20, debug=True) tracker.set_tracking_callback(tracker_callback) with color_tracker.WebCamera() as cam: tracker.track(cam, [100, 103, 82], [130, 255, 255], max_skipped_frames=24)