# otherwise, we are reading from a video file else: camera = cv2.VideoCapture(args["video"]) if args["tra_file"] is None: if args["folder"] is None: raise NameError('target trajectory file is not present') else: folder_path = os.path.dirname(args["folder"]) args["tra_file"] = os.path.join(folder_path, 'trajectory_v2.tra') # Define BlobFinder bfinder = BlobFinder(mask) bfinder.erode_iter = 2 bfinder.dilate_iter = 2 bfinder.area_lim = [args['min_area'], args['max_area']] bfinder.roundness_lim = [0, 1] bfinder.background_init = 60 bfinder.threshold = 10 bfinder.gaussian_blur = 21 bfinder.skip_filter_contours = False # Load ref cumsum and bin edges if args["bin_edges_file"] is None: raise NameError('bin edges file is not present') else: bin_edges = np.load(args["bin_edges_file"]) # Load ref cumsum and bin edges if args["refcumsum_file"] is None: raise NameError('ref cumsum file is not present')
refresh_time = 0.5 blob_brightness = [20, 30, 150, 254] max_nb_images = 1 # Bfinder parameters args = dict() # loop over the frames of the video t_start = time.time() # mask background = btgen.background() mask = btgen.mask(background) # Create a bfinder tracker bfinder = BlobFinder(mask) bfinder.erode_iter = 2 bfinder.dilate_iter = 2 bfinder.area_lim = [0, 10000] bfinder.roundness_lim = [0, 1] bfinder.background_init = 60 bfinder.threshold = 10 bfinder.gaussian_blur = 1 bfinder.skip_filter_contours = False # Parameter for croping xmargin = [0, 0] ymargin = [0, 0] # Build up an expected histogram ninitframes = 50 bin_edges = np.arange(1, 255) ref_cumsum = np.zeros(bin_edges.shape[0] - 1) for _ in range(bfinder.background_init): # grab the current frame and initialize the occupied/unoccupied
argcam = args["folder"] # otherwise, we are reading from a video file else: argcam = args["video"] if args["tra_file"] is None: if args["folder"] is None: raise NameError('target trajectory file is not present') else: folder_path = os.path.dirname(args["folder"]) args["tra_file"] = os.path.join(folder_path, 'trajectory_v2.tra') bmarker = BlobFinder(mask, None) bmarker.erode_iter = 1 bmarker.dilate_iter = 1 bmarker.area_lim = [0, 2000] bmarker.roundness_lim = [0, 1] bmarker.threshold = args["threshold"] bmarker.gaussian_blur = 1 bmarker.skip_filter_contours = True # Create image for display scale = 0.4 refresh_time = 0.5 nframe_bg = 100 camera = cv2.VideoCapture(argcam) background = get_background(camera, nframe_bg) background = background[..., 0] camera.release()