From 5259da7b02e62f81c383fa67e06cd7ee554e6301 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sun, 28 Apr 2024 19:25:38 -0400 Subject: Crop webcam image to prevent perspective distortion, correctly truncate frame for raptor code using CLI flag, make encoder.py print flags --- decoder.py | 10 +++++++--- encoder.py | 3 +-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/decoder.py b/decoder.py index cb34487..2738939 100644 --- a/decoder.py +++ b/decoder.py @@ -14,7 +14,8 @@ parser.add_argument("-x", "--height", help="grid height", default=100, type=int) parser.add_argument("-y", "--width", help="grid width", default=100, type=int) parser.add_argument("-f", "--fps", help="frame rate", default=30, type=int) parser.add_argument("-l", "--level", help="error correction level", default=0.1, type=float) -parser.add_argument("-s", "--size", help="number of bytes to decode", default=2**16, type=int) +parser.add_argument("-s", "--size", help="number of bytes to decode", type=int) +parser.add_argument("-p", "--psize", help="packet size", type=int) parser.add_argument("-e", "--erasure", help="detect erasures", action="store_true") args = parser.parse_args() @@ -56,9 +57,12 @@ while data is None: if not ret: print("End of stream") break + # raw_frame is a uint8 BE CAREFUL + if type(args.input) == int: + X, Y = raw_frame.shape[:2] + raw_frame = raw_frame[X // 4:3 * X // 4, Y // 4: 3 * Y // 4] cv2.imshow("", raw_frame) cv2.waitKey(1) - # raw_frame is a uint8 BE CAREFUL raw_frame = cv2.cvtColor(raw_frame, cv2.COLOR_BGR2RGB) X, Y = raw_frame.shape[:2] @@ -123,7 +127,7 @@ while data is None: ) ) # erase_pos = bytearray(np.where(frame == 0)[0]) if args.erasure else bytearray() - data = decoder.decode(bytes(rsc.decode(bytearray(np.packbits(frame) ^ frame_xor))[0][:-4])) + data = decoder.decode(bytes(rsc.decode(bytearray(np.packbits(frame) ^ frame_xor))[0][:args.psize])) print("Decoded frame") except KeyboardInterrupt: sys.exit() diff --git a/encoder.py b/encoder.py index 914e396..c510b18 100644 --- a/encoder.py +++ b/encoder.py @@ -39,8 +39,7 @@ rcorner = np.pad(np.dstack((ones, zeros, zeros)), ((0, 1), (1, 0), (0, 0))) gcorner = np.pad(np.dstack((zeros, ones, zeros)), ((1, 0), (0, 1), (0, 0))) bcorner = np.pad(np.dstack((zeros, zeros, ones)), ((1, 0), (1, 0), (0, 0))) -print("Data length:", len(data)) -print("Packets:", len(packets)) +print(f"-x {args.height} -y {args.width} -l {args.level} -s {len(data)} -p {len(packets[0])}") def frame(packet): -- cgit v1.2.3-70-g09d2