def video_generator( path_video, ts_format="2016", path_filelists=None, log_callback=None, stderr_fd=sp.DEVNULL, ): timestamps = get_timestamps(path_video, ts_format, path_filelists) fname_video = os.path.basename(path_video) data_source = DataSource.new_message(filename=fname_video) for frame_index, frame in enumerate(VideoReader(path_video, stderr_fd)): if log_callback is not None: log_callback(frame_index) img = frame yield data_source, img, timestamps[frame_index] if "frame_index" not in locals(): raise RuntimeError("No frames loaded from video") loaded_frame_count = frame_index + 1 if loaded_frame_count != len(timestamps): raise RuntimeError( "Number of loaded frames ({}) did not match number of timestamps ({})".format( loaded_frame_count, len(timestamps) ) )
def video_generator(path_video, ts_format='2016', path_filelists=None, log_callback=None, stderr_fd=sp.DEVNULL): timestamps = get_timestamps(path_video, ts_format, path_filelists) fname_video = os.path.basename(path_video) data_source = DataSource.new_message(filename=fname_video) for i, frame in enumerate(VideoReader(path_video, stderr_fd)): if log_callback is not None: log_callback(i) img = frame yield data_source, img, timestamps[i]
def test_no_detection(tmpdir, pipeline_config): repo = Repository(str(tmpdir)) sink = BBBinaryRepoSink(repo, camId=0) pipeline = Pipeline([Image, Timestamp], [PipelineResult], **pipeline_config) image = np.zeros((3000, 4000), dtype=np.uint8) results = pipeline([image, 0]) data_source = DataSource.new_message(filename='source') sink.add_frame(data_source, results, 0) sink.finish() assert(len(list(repo.iter_fnames())) == 1) for fname in repo.iter_fnames(): with open(fname, 'rb') as f: fc = FrameContainer.read(f) assert(len(fc.frames) == 1) assert fc.dataSources[0].filename == 'source' frame = fc.frames[0] assert(len(frame.detectionsUnion.detectionsDP) == 0)
def image_generator(): ts = time.time() data_source = DataSource.new_message(filename='bees.jpeg') for i in range(2): img = imread(bees_image) yield data_source, img, ts + i