예제 #1
0
def main_2():
    video, calibration_image = get_capture_and_calibration_image_video2()
    calibrator = Calibrator.calibrate(calibration_image, 2)
    # visualize_calibration(calibrator, calibration_image)
    if not calibrator.calibrated:
        print('System was not calibrated.')
        return

    detector = Detector(calibrator)

    wnd = CvNamedWindow('detection', cv2.WINDOW_NORMAL)

    # detect_and_show('detection', detector, video.read_at_pos(442), video.frame_pos() - 1)
    # detect_and_show('detection', detector, video.read_at_pos(464), video.frame_pos() - 1)
    # detect_and_show('detection', detector, video.read_at_pos(471), video.frame_pos() - 1)
    # detect_and_show('detection', detector, video.read_at_pos(833), video.frame_pos() - 1)

    # detect_and_show('detection', detector, video.read_at_pos(497), video.frame_pos() - 1)
    # detect_and_show('detection', detector, video.read_at_pos(320), video.frame_pos() - 1)
    detect_and_show(wnd, detector, video.read_at_pos(820), video.frame_pos() - 1)

    detect_and_show(wnd, detector, video.read_at_pos(286), video.frame_pos() - 1)

    # detect_and_show('detection', detector, video.read_at_pos(1511), video.frame_pos() - 1)
    # detect_and_show('detection', detector, video.read_at_pos(1601), video.frame_pos() - 1)
    # detect_and_show('detection', detector, video.read_at_pos(1602), video.frame_pos() - 1)
    # detect_and_show('detection', detector, video.read_at_pos(1603), video.frame_pos() - 1)
    # detect_and_show('detection', detector, video.read_at_pos(1604), video.frame_pos() - 1)
    # 833

    video.release()
    cv2.destroyAllWindows()
예제 #2
0
def main_6_video():
    video, calibration_image = get_capture_and_calibration_image_video6()
    calibrator = Calibrator.calibrate(calibration_image, 2)
    visualize_calibration(calibrator, calibration_image)
    if not calibrator.calibrated:
        print('System was not calibrated.')
        return

    detector = Detector(calibrator)
    wnd = CvNamedWindow('detection', cv2.WINDOW_NORMAL)

    video.set_pos(961)
    ellipses_count = 0
    for frame in video.frames():
        pos = video.frame_pos()
        print(pos)
        t, ellipses = detect_and_draw(detector, frame)
        ellipses_count = max(ellipses_count, len(ellipses))
        utils.put_frame_pos(frame, pos)
        put_video_duration(frame, video.frame_pos_msec())
        put_ellipses_count(frame, ellipses_count)
        wnd.imshow(frame)
        cv2.waitKey()
    cv2.waitKey()

    video.release()
    cv2.destroyAllWindows()
예제 #3
0
def main_2_test():
    def test_region(frame_num, region):
        col, row, d_col, d_row = region
        detect_and_show(wnd, detector, video.read_at_pos(frame_num)[row:row + d_row, col:col + d_col], None,
                        True)

    video, calibration_image = get_capture_and_calibration_image_video2()
    calibrator = Calibrator.calibrate(calibration_image, 2)
    # visualize_calibration(calibrator, calibration_image)
    if not calibrator.calibrated:
        print('System was not calibrated.')
        return

    wnd = CvNamedWindow('detection', cv2.WINDOW_NORMAL)

    detector = Detector(calibrator)

    test_region(442, (474, 545, 134, 74))
    test_region(442, (403, 545, 148, 74))
    test_region(442, (403, 545, 204, 74))
    test_region(442, (434, 542, 163, 76))
    test_region(442, (472, 540, 78, 78))
    #
    # test_region(464, (596, 422, 187, 136))
    # test_region(464, (652, 422, 73, 136))
    # test_region(464, (652, 432, 73, 70))

    # test_region(833, (838, 485, 68, 73))
    # test_region(833, (770, 321, 68, 122))
    # test_region(833, (770, 256, 71, 132))

    # test_region(833, (598, 317, 68, 68))
    # test_region(833, (601, 317, 66, 122))
    # test_region(833, (561, 317, 106, 122))

    # test_region(1511, (721, 151, 131, 132))
    # test_region(1511, (723, 151, 127, 77))
    # test_region(1511, (658, 151, 250, 132))

    # test_region(1511, (779, 151, 71, 77))
    # test_region(1511, (780, 157, 66, 67))

    test_region(497, (958, 173, 74, 65))

    # test_region(1601, (308, 428, 70, 70))
    # test_region(1601, (308, 373, 76, 66))
    # test_region(1601, (308, 317, 136, 187))
    # test_region(1601, (318, 160, 76, 66))

    video.release()
    cv2.destroyAllWindows()
예제 #4
0
def main_6():
    video, calibration_image = get_capture_and_calibration_image_video6()
    calibrator = Calibrator.calibrate(calibration_image, 2)
    # visualize_calibration(calibrator, calibration_image)
    if not calibrator.calibrated:
        print('System was not calibrated.')
        return

    detector = Detector(calibrator)
    wnd = CvNamedWindow('detection', cv2.WINDOW_NORMAL)
    detect_and_show(wnd, detector, video.read_at_pos(229), video.frame_pos() - 1)

    video.release()
    cv2.destroyAllWindows()
예제 #5
0
def main():
    video, calibration_image = get_capture_and_calibration_image_video2()
    calibrator = Calibrator.calibrate(calibration_image, 2)
    assert len(calibrator.reference_ellipses) >= 2
    for ref_ellipse in calibrator.reference_ellipses:
        get_image_patch(ref_ellipse, calibration_image)

    cv2.imshow('calib', calibration_image)

    def cb(evt, x, y, _, img):
        if evt != cv2.EVENT_LBUTTONDOWN:
            return
        print(x, y, img[y, x])

    cv2.setMouseCallback('calib', cb, param=calibration_image)
    cv2.waitKey()
예제 #6
0
def main_6_test():
    def test_region(frame_num, region):
        col, row, d_col, d_row = region
        detect_and_show(wnd, detector, video.read_at_pos(frame_num)[row:row + d_row, col:col + d_col], None,
                        True)

    video, calibration_image = get_capture_and_calibration_image_video6()
    calibrator = Calibrator.calibrate(calibration_image, 2)
    # visualize_calibration(calibrator, calibration_image)
    if not calibrator.calibrated:
        print('System was not calibrated.')
        return
    wnd = CvNamedWindow('detection', cv2.WINDOW_NORMAL)
    detector = Detector(calibrator)
    # 1201 1218 3001
    test_region(1660, (1406, 444, 128, 120))

    video.release()
    cv2.destroyAllWindows()
예제 #7
0
def main_6_video_write_results(max_frames):
    max_frames = max_frames or -1
    video, calibration_image = get_capture_and_calibration_image_video6()
    print(f'FRAME COUNT: {video.frame_count()}')
    calibrator = Calibrator.calibrate(calibration_image, 2)
    # visualize_calibration(calibrator, calibration_image)
    if not calibrator.calibrated:
        print('System was not calibrated.')
        return

    fourcc = cv2.VideoWriter_fourcc(*'XVID')  # fourcc = cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')
    out = cv2.VideoWriter('d:/DiskE/Computer_Vision_Task/Video_6_out_full.avi', fourcc, video.fps(), video.resolution())
    detector = Detector(calibrator)

    import time
    t0 = time.time()

    ellipses_count = 0
    for frame in video.frames():
        pos = video.frame_pos()

        try:
            t, ellipses = detect_and_draw(detector, frame, False)
        except:
            print(f'Error at frame {pos}')
            raise

        ellipses_count = max(ellipses_count, len(ellipses))
        utils.put_frame_pos(frame, pos)
        put_video_duration(frame, video.frame_pos_msec())
        put_ellipses_count(frame, ellipses_count)
        out.write(frame)
        if pos % 100 == 0:
            secs_per_frame = round((time.time() - t0) / pos, 2)
            print(f'Frames processed: {pos}. Secs per frame: {secs_per_frame}')
        if max_frames > 0 and pos > max_frames:
            break

    print('Done!', time.time() - t0)

    video.release()
    out.release()