def cli(left_eye, right_eye): stream = StereoCamera( left_src=left_eye, right_src=right_eye, ) player = VideoPlayer() with player, stream: count = 0 while go(): ok, frames = stream.read() if ok: count += 1 annotated = [] for side, source, frame in zip(("left", "right"), (left_eye, right_eye), frames.frames()): annotated.append( decorate_frame( frame=frame, side=side, count=count, source=source, )) stack = np.hstack(annotated) player.show(stack)
def cli(source): _decorate = partial(decorate_frame, source=source) stream = VideoStream(src=source) player = VideoPlayer(stream=stream, frame_callback=_decorate) with player: player.autoplay()
def cli(left_eye, right_eye, output_folder, chessboard_rows, chessboard_columns): """ Find chessboard calibration images in both frames of the stereo pair """ out_path = Path(output_folder).expanduser() out_path.mkdir(parents=True, exist_ok=True) chessboard_size = (chessboard_columns, chessboard_rows) finder = ChessboardFinder(chessboard_size) stream = StereoCamera( left_src=left_eye, right_src=right_eye, ) player = VideoPlayer() with player, stream: original_writer = get_stereo_writer(stream, file_name="original_stereo.avi") annotated_writer = get_stereo_writer(stream, file_name="annotated_stereo.avi") frame_count = 0 good_count = 0 while go(): ok, frames = stream.read() frame_count += 1 if ok: good = [] annotated = [] # so we have a good stereo frame, now inspect each frame and if # a chessboard is found in each, save the pair to disk. for frame in frames.frames(): labels = [f"Stereo Calibrate {frame_count}"] display_frame = frame.copy() height, width, channels = display_frame.shape has_corners, corners = finder.corners(frame) if has_corners: good.append(True) finder.draw(display_frame, corners) labels.append("CHESSBOARD") else: good.append(False) labels.append("NO CHESSBOARD FOR YOU") add_frame_labels(display_frame, labels=labels) annotated.append(display_frame) if all(good): # both frames have verified chessboards save frames for analysis for side, frame in frames.calibration_named_frames(): cv.imwrite(f"{out_path}/{side}_{good_count:05}.jpg", frame) good_count += 1 player.show(np.hstack(annotated)) annotated_writer.stereo_write(annotated) original_writer.stereo_write(frames.frames())
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)
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)
@cost def canny(img): img = imutils.auto_canny(image=img, sigma=0.3) img = add_frame_labels( frame=img, labels=[ f"canny cost: {canny.cost:6.3f}s", "q to quit", ], color=colors.get("WHITE"), ) return img stream = VideoStream(src=0) writer = VideoWriter( size=stream.get_wh_size(), file_name="canny.avi", color=False, fps=60, ) player = VideoPlayer() with stream, player, writer: while go(): ok, frame = stream.read() if ok: frame = canny(frame) writer.write(frame) player.show(frame)
from rakali import VideoPlayer, VideoStream from rakali.annotate import add_frame_labels, colors FRONT_LAWN = 1 WATER_HEATER = 2 PARK = 3 BACK_LAWN = 4 SOURCE = f"rtsp://10.0.0.247:554/ch0{WATER_HEATER}/01" 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 stream = VideoStream(src=SOURCE) player = VideoPlayer(stream=stream, frame_callback=size) with player: player.autoplay()
#! /usr/bin/env python import imutils from rakali import VideoPlayer, VideoStream from rakali.annotate import add_frame_labels, colors from rakali.video.fps import cost @cost 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 stream = VideoStream(src=0) player = VideoPlayer(stream=stream, frame_callback=canny) with player: player.autoplay()