Exemplo n.º 1
0
def decorate_frame(frame, source):
    img = add_frame_labels(
        frame=frame,
        labels=[f"{source}"],
        color=colors.get("BHP"),
    )
    return img
Exemplo n.º 2
0
def add_calib_info(camera, img, side):
    """label the corrected frames to aid in diagnostics"""

    return add_frame_labels(
        frame=img,
        labels=calibration_labels(camera.calibration, side),
        color=colors.get("BLACK"),
    )
Exemplo n.º 3
0
def canny(mat):
    img = imutils.auto_canny(image=mat, sigma=0.3)
    img = add_frame_labels(
        frame=img,
        labels=[f"canny cost: {canny.cost:6.3f}s"],
        color=colors.get("WHITE"),
    )
    return img
Exemplo n.º 4
0
def add_reticle(img):
    """adds markup to frame for warp debug"""

    olive = colors.get("OLIVE")
    h, w = img.shape[:2]
    cx, cy = (int(w / 2), int(h / 2))
    center = cx, cy
    # circles
    for r in range(50, 300, 100):
        cv.circle(
            img=img,
            center=center,
            radius=r,
            lineType=cv.LINE_8,
            color=olive,
            thickness=1,
        )

    # space
    for y in range(0, h, int(h / 20)):
        cv.line(
            img=img,
            pt1=(0, y),
            pt2=(w, y),
            color=olive,
            lineType=cv.LINE_4,
            thickness=1,
        )
        if y == cy:
            cv.line(
                img=img,
                pt1=(0, y),
                pt2=(w, y),
                color=olive,
                lineType=cv.LINE_4,
                thickness=3,
            )

    for x in range(0, w, int(w / 20)):
        cv.line(
            img=img,
            pt1=(x, 0),
            pt2=(x, h),
            color=olive,
            lineType=cv.LINE_4,
            thickness=1,
        )
        if x == cx:
            cv.line(
                img=img,
                pt1=(x, 0),
                pt2=(x, h),
                color=olive,
                lineType=cv.LINE_4,
                thickness=3,
            )

    return img
Exemplo n.º 5
0
def decorate_frame(frame, side, count, source):
    img = add_frame_labels(
        frame=frame,
        labels=[
            f"{side}",
            f"{source}",
            f"frame # {count}",
        ],
        color=colors.get("BHP"),
    )
    return img
Exemplo n.º 6
0
def size(img):
    h, w = img.shape[:2]
    img = add_frame_labels(
        frame=img,
        labels=[
            f"size: {w}x{h}",
            "Geyser watch",
            "q to quit",
        ],
        color=colors.get("GREEN"),
    )
    return img
Exemplo n.º 7
0
def label_frame(camera, frame):
    labels = [
        f"Reprojected fisheye frame",
        f"undistort cost: {camera.correct.cost:6.3f}s",
        f"balance: {camera.balance}",
        f"cid: {camera.cid} calibrated on {camera.calibration_time_formatted}",
        # f'dim2 {dim2}',
        # f'dim3 {dim3}',
    ]
    labeled_frame = add_frame_labels(
        frame=frame,
        labels=labels,
        color=colors.get("BHP"),
    )
    return labeled_frame
Exemplo n.º 8
0
 def update():
     rectified = camera.correct(img)
     labels = [
         f"Reprojected fisheye frame",
         f"undistort cost: {camera.correct.cost:6.3f}s",
         f"balance: {camera.balance}",
         f"cid: {camera.cid} calibrated on {camera.calibration_time_formatted}",
         # f'dim2 {dim2}',
         # f'dim3 {dim3}',
     ]
     labeled_frame = add_frame_labels(
         frame=rectified,
         labels=labels,
         color=colors.get("BHP"),
     )
     cv.imshow(window_name, labeled_frame)
     cv.imshow("Raw image", img)
Exemplo n.º 9
0
def cli(left_source, right_source, calibration_file, balance):
    """
    Displays corrected live stereo video feed from fisheye stereo rig
    Visual inspection tool to verify correction works
    """

    camera = CalibratedFisheyeCamera(
        calibration_file=calibration_file,
        balance=balance,
        dim2=None,
        dim3=None,  # remember we have these
    )
    stream = VideoStream(src=source)
    player = VideoPlayer()

    with stream, player:
        ok, frame = stream.read()
        if ok:
            camera.set_map(first_frame=frame)
        else:
            print("Cannot read video feed")
            sys.exit(0)

        frame_count = 0
        while go():
            ok, frame = stream.read()
            if ok:
                frame_count += 1
                undistorted_frame = camera.correct(frame)
                labels = [
                    f"Reprojected fisheye frame: {frame_count}",
                    f"undistort cost: {camera.correct.cost:6.3f}s",
                    f"balance: {balance}",
                    f"cid: {camera.cid} calibrated on {camera.calibration_time_formatted}",
                    # f'dim2 {dim2}',
                    # f'dim3 {dim3}',
                ]
                labeled_frame = add_frame_labels(
                    frame=undistorted_frame,
                    labels=labels,
                    color=colors.get("BHP"),
                )
                stack = np.hstack((frame, labeled_frame))
                player.show(stack)
Exemplo n.º 10
0
def cli(source, calibration_file):
    """Undistort live feed from pinhole model type camera"""

    calibration_path = Path(calibration_file).expanduser()

    camera = CalibratedPinholeCamera(calibration_file=calibration_path)
    stream = VideoFile(src=str(source))
    player = VideoPlayer()

    with stream, player:
        while go():
            ok, frame = stream.read()
            if ok:
                frame = camera.correct(frame)
                frame = add_frame_labels(
                    frame=frame,
                    labels=[f"undistort cost: {camera.correct.cost:6.3f}s"],
                    color=colors.get("BHP"),
                )
                player.show(frame)