diff options
author | Anthony Wang | 2024-04-21 01:15:52 -0400 |
---|---|---|
committer | Anthony Wang | 2024-04-21 01:15:52 -0400 |
commit | cef9bab49ad9f303978858b2824ab0862c0df689 (patch) | |
tree | 6cb48d326c9ee5d3d5f0c3ac71ac75077340109a /decoder.py | |
parent | 762d99dc02066555f723b9537c65330f8bf9d10f (diff) |
Implement ECC, webcam capture
Diffstat (limited to 'decoder.py')
-rw-r--r-- | decoder.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/decoder.py b/decoder.py new file mode 100644 index 0000000..357db39 --- /dev/null +++ b/decoder.py @@ -0,0 +1,40 @@ +import argparse +import cv2 +import numpy as np +from creedsolo import RSCodec +from raptorq import Decoder + +parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) +parser.add_argument("file", help="output file for decoded data") +parser.add_argument("--len", help="number of bytes to decode", default=2**16, type=int) +parser.add_argument("--height", help="grid height", default=100, type=int) +parser.add_argument("--width", help="grid width", default=100, type=int) +parser.add_argument("--fps", help="framerate", default=30, type=int) +parser.add_argument("--level", help="error correction level", default=0.1, type=float) +args = parser.parse_args() + +cheight = args.height // 10 +cwidth = args.width // 10 +frame_size = args.height * args.width - 4 * cheight * cwidth +rs_size = int(frame_size * (1 - args.level)) + +rsc = RSCodec(frame_size - rs_size) +raptor_decoder = Decoder.with_defaults(args.size, rs_size) +data = None +cap = cv2.VideoCapture(0) +while data is None: + ret, frame = cap.read() + if not ret: + continue + frame_full = decode(frame) # TODO + frame_data = np.concatenate( + ( + frame_full[:cheight, cwidth : args.width - cwidth].flatten(), + frame_full[cheight : args.height - cheight].flatten(), + frame_full[args.heigth - cheight, cwidth : args.width - cwidth].flatten(), + ) + ) + data = raptor_decoder.decode(rsc.decode(frame_data)) +with open(args.file, "wb") as f: + f.write(data) +cap.release() |