diff --git a/scripts/leap-view b/scripts/leap-view index 2cecbd1..27ef12d 100755 --- a/scripts/leap-view +++ b/scripts/leap-view @@ -8,6 +8,7 @@ import numpy as np logger = logging.getLogger(__name__) + def main() -> int: # Handle program arguments ap = argparse.ArgumentParser( @@ -22,8 +23,15 @@ def main() -> int: choices=["640x120", "640x240", "640x480", "752x120", "752x240", "752x480"], default="640x480", ) - ap.add_argument("--only", help="Only show the left or right camera", choices=["left", "right"]) - ap.add_argument("--no-brightness-normalization", help="Do not normalize the brightness of the frames", action="store_true") + ap.add_argument( + "--only", help="Only show the left or right camera", choices=["left", "right"] + ) + ap.add_argument("--no-led", help="Disable the LEDs", action="store_true") + ap.add_argument( + "--no-brightness-normalization", + help="Do not normalize the brightness of the frames", + action="store_true", + ) ap.add_argument( "-v", "--verbose", help="Enable verbose logging", action="store_true" ) @@ -47,6 +55,13 @@ def main() -> int: cap.set(cv2.CAP_PROP_FRAME_WIDTH, width) cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height) cap.set(cv2.CAP_PROP_CONVERT_RGB, 0) + + # Configure the LEDs + # NOTE: See the libuvc for leap documentation for info about this + # https://github.com/ewpratten/leapuvc/blob/master/LeapUVC-Manual.pdf + cap.set(cv2.CAP_PROP_CONTRAST, (0b0010 | (int(not args.no_led) << 6))) + cap.set(cv2.CAP_PROP_CONTRAST, (3 | (int(not args.no_led) << 6))) + cap.set(cv2.CAP_PROP_CONTRAST, (4 | (int(not args.no_led) << 6))) # Read frames while True: @@ -62,11 +77,11 @@ def main() -> int: # Split into left and right frames (every other byte) left_frame = frame[:, 0::2] right_frame = frame[:, 1::2] - + # Ignore the last row of the frames left_frame = left_frame[:-1] right_frame = right_frame[:-1] - + # Normalize the frames so that the brightest pixel is 255 if not args.no_brightness_normalization: left_frame = cv2.normalize(left_frame, None, 0, 255, cv2.NORM_MINMAX)