aboutsummaryrefslogtreecommitdiff
path: root/decoder.py
diff options
context:
space:
mode:
authorAnthony Wang2024-04-21 11:47:36 -0400
committerAnthony Wang2024-04-21 11:47:36 -0400
commit959f31d58548d8d1e932dba7de591a07b7258672 (patch)
tree7226885313a0d82ff9ae3de05adb0f678934ab9c /decoder.py
parentcef9bab49ad9f303978858b2824ab0862c0df689 (diff)
XOR frames with arange, implement color to 8-bit in decoder, add camera device index flag
Diffstat (limited to 'decoder.py')
-rw-r--r--decoder.py23
1 files changed, 15 insertions, 8 deletions
diff --git a/decoder.py b/decoder.py
index 357db39..e58e246 100644
--- a/decoder.py
+++ b/decoder.py
@@ -11,30 +11,37 @@ 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)
+parser.add_argument("--device", help="camera device index", default=1, type=int)
args = parser.parse_args()
cheight = args.height // 10
cwidth = args.width // 10
frame_size = args.height * args.width - 4 * cheight * cwidth
+frame_xor = np.arange(frame_size, dtype=np.uint8)
rs_size = int(frame_size * (1 - args.level))
rsc = RSCodec(frame_size - rs_size)
-raptor_decoder = Decoder.with_defaults(args.size, rs_size)
+raptor_decoder = Decoder.with_defaults(args.len, rs_size)
data = None
-cap = cv2.VideoCapture(0)
+cap = cv2.VideoCapture(args.device)
while data is None:
- ret, frame = cap.read()
+ ret, raw_frame = cap.read()
if not ret:
continue
- frame_full = decode(frame) # TODO
+ color_frame = decode(raw_frame) # TODO
+ frame = (
+ (color_frame[:, :, 0] >> 5 & 0b00000111)
+ + (color_frame[:, :, 1] >> 2 & 0b00111000)
+ + (color_frame[:, :, 2] & 0b11000000)
+ )
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(),
+ frame[:cheight, cwidth : args.width - cwidth].flatten(),
+ frame[cheight : args.height - cheight].flatten(),
+ frame[args.heigth - cheight, cwidth : args.width - cwidth].flatten(),
)
)
- data = raptor_decoder.decode(rsc.decode(frame_data))
+ data = raptor_decoder.decode(rsc.decode(frame_data ^ frame_xor))
with open(args.file, "wb") as f:
f.write(data)
cap.release()