def main():
    with CameraStreamProcessor(
            camera=CvVideoCamera(is_color=False),
            pipeline=[
                CvBlobDetector(
                    min_threshold=31.23,
                    max_threshold=207.05,
                    filter_by_color=True,
                    blob_color=255,
                    filter_by_area=True,
                    min_area=17.05,
                    max_area=135.46,
                    filter_by_circularity=True,
                    min_circularity=0.62,
                    filter_by_inertia=True,
                    min_inertia_ratio=0.27,
                    filter_by_convexity=True,
                    min_convexity=0.60,
                ),
                # CvContourBlobDetector(),
                NearestNeighbourTracker(threshold=20),
                KeypointEncoder(),
            ],
            view=KeypointView(color=(0, 255, 0)),
            display=CvVideoDisplay(name='preview'),
            writer=CvImageOutputFileSeq(),
    ) as p:
        keypoints = p.process(num_frames=5, outfile="demo1.jpg")
        #        keypoints = p.process(num_frames=300)
        print(f"keypoints.shape = {keypoints.shape}")
        print(f"keypoints[0] = {keypoints[0]}")

    with FileStreamProcessor(
            reader=CvImageInputFileSeq(),
            pipeline=[
                CvBlobDetector(
                    min_threshold=31.23,
                    max_threshold=207.05,
                    filter_by_color=True,
                    blob_color=255,
                    filter_by_area=True,
                    min_area=17.05,
                    max_area=135.46,
                    filter_by_circularity=True,
                    min_circularity=0.62,
                    filter_by_inertia=True,
                    min_inertia_ratio=0.27,
                    filter_by_convexity=True,
                    min_convexity=0.60,
                ),
                # CvContourBlobDetector(),
                NearestNeighbourTracker(threshold=20),
                KeypointEncoder(),
            ],
            view=KeypointView(color=(0, 255, 0)),
            display=CvVideoDisplay(name='preview'),
    ) as p:
        keypoints = p.process(num_frames=5, infile="demo1.jpg")
        print(f"keypoints.shape = {keypoints.shape}")
def main():
    with AsyncProcessor(
            CameraStreamProcessorMP(
                camera=DShowVideoCamera(format=6, is_color=False),
                pipeline=[
                    # CvBlobDetector(
                    #     min_threshold=31.23,
                    #     max_threshold=207.05,
                    #     filter_by_color=True,
                    #     blob_color=255,
                    #     filter_by_area=True,
                    #     min_area=17.05,
                    #     max_area=135.46,
                    #     filter_by_circularity=True,
                    #     min_circularity=0.62,
                    #     filter_by_inertia=True,
                    #     min_inertia_ratio=0.27,
                    #     filter_by_convexity=True,
                    #     min_convexity=0.60,
                    # ),
                    CvContourBlobDetector(),
                    NearestNeighbourTracker(threshold=20),
                    KeypointEncoder(),
                ],
                view=KeypointView(color=(0, 255, 0)),
                display=CvVideoDisplay(name='preview'),
                writer=CvVideoOutputFile(fps=120,
                                         frame_size=(640, 480),
                                         is_color=False),
                qsize=2,
            )) as p:

        p.async_process(outfile='demo1.mp4')
        print("Getting on with something else ...")
        time.sleep(5)
        p.async_cancel()
        frames = p.async_result()
        print("frames.shape = {}".format(frames.shape))
Пример #3
0
def main():
    with CameraStreamProcessor(
            camera=CvVideoCamera(is_color=False),
            pipeline=[
                CvBlobDetector(
                    min_threshold=31.23,
                    max_threshold=207.05,
                    filter_by_color=True,
                    blob_color=255,
                    filter_by_area=True,
                    min_area=17.05,
                    max_area=135.46,
                    filter_by_circularity=True,
                    min_circularity=0.62,
                    filter_by_inertia=True,
                    min_inertia_ratio=0.27,
                    filter_by_convexity=True,
                    min_convexity=0.60,
                ),
                # CvContourBlobDetector(),
                NearestNeighbourTracker(threshold=20),
                KeypointEncoder(),
            ],
            view=KeypointView(color=(0, 255, 0)),
            display=CvVideoDisplay(name='preview'),
            writer=CvVideoOutputFile(is_color=False),
    ) as p:
        # capture sequence of keypoints - ensure sensor has sufficient time to return to
        # its rest position before end of sequence
        keypoints = p.process(num_frames=300, outfile="demo1.mp4")
        #        keypoints = p.process(num_frames=300)
        print(f"keypoints.shape = {keypoints.shape}")

        # check that final keypoint ordering is the same as initial ordering
        init_keypoints, final_keypoints = keypoints[0], keypoints[-1]
        dists = ssd.cdist(final_keypoints, init_keypoints, 'euclidean')
        min_dist_idxs = np.argmin(dists, axis=1)
        print("Test passed: {}".format(np.all(min_dist_idxs == range(len(min_dist_idxs)))))
Пример #4
0
def main():       
    with AsyncProcessor(CameraStreamProcessorMT(
        camera=CvVideoCamera(is_color=False),
        pipeline=[
            CvBlobDetector(
                min_threshold=31.23,
                max_threshold=207.05,
                filter_by_color=True,
                blob_color=255,
                filter_by_area=True,
                min_area=17.05,
                max_area=135.46,
                filter_by_circularity=True,
                min_circularity=0.62,
                filter_by_inertia=True,
                min_inertia_ratio=0.27,
                filter_by_convexity=True,
                min_convexity=0.60,
            ),
            # CvContourBlobDetector(),
            NearestNeighbourTracker(threshold=20),
            KeypointEncoder(),
        ],
        view=KeypointView(color=(0,255,0)),
        display=CvVideoDisplay(name='preview'),
        writer=CvVideoOutputFile(is_color=False),
        )) as p:        
        
        p.async_process(outfile='demo1.mp4')
        print("Getting on with something else ...")
        time.sleep(5)
        p.async_cancel()
        frames = p.async_result()
        print("frames.shape = {}".format(frames.shape))

    with AsyncProcessor(FileStreamProcessorMT(
            reader=CvVideoInputFile(is_color=False),
            pipeline=[
                CvBlobDetector(
                    min_threshold=31.23,
                    max_threshold=207.05,
                    filter_by_color=True,
                    blob_color=255,
                    filter_by_area=True,
                    min_area=17.05,
                    max_area=135.46,
                    filter_by_circularity=True,
                    min_circularity=0.62,
                    filter_by_inertia=True,
                    min_inertia_ratio=0.27,
                    filter_by_convexity=True,
                    min_convexity=0.60,
                ),
                # CvContourBlobDetector(),
                NearestNeighbourTracker(threshold=20),
                KeypointEncoder(),
            ],
            view=KeypointView(color=(0, 255, 0)),
            display=CvVideoDisplay(name='replay'),
    )) as p:
        p.async_process(num_frames=100, infile="demo1.mp4")
        print("Getting on with something else ...")
        time.sleep(5)
#        p.async_cancel()
        keypoints = p.async_result()
        print(f"keypoints.shape = {keypoints.shape}")