diff options
Diffstat (limited to 'decoder.py')
-rw-r--r-- | decoder.py | 34 |
1 files changed, 20 insertions, 14 deletions
@@ -1,5 +1,5 @@ import argparse -import traceback +import time import cv2 import numpy as np from creedsolo import RSCodec @@ -47,6 +47,7 @@ if args.input.isdecimal(): args.input = int(args.input) cap = cv2.VideoCapture(args.input) data = None +start_time = time.time() while data is None: try: ret, raw_frame = cap.read() @@ -65,7 +66,7 @@ while data is None: # Find positions and colors of corners X, Y = raw_frame.shape[:2] cx, cy = X // 3, Y // 3 - widx, wcol = find_corner(raw_frame[:cx, :cy], lambda B: np.sum(B, axis=2) - np.std(B, axis=2)) + widx, wcol = find_corner(raw_frame[:cx, :cy], lambda B: np.sum(B, axis=2) - 2 * np.std(B, axis=2)) ridx, rcol = find_corner(raw_frame[:cx, Y - cy :], lambda B: B[:, :, 0] - B[:, :, 1] - B[:, :, 2]) ridx[1] += Y - cy gidx, gcol = find_corner(raw_frame[X - cx :, :cy], lambda B: B[:, :, 1] - B[:, :, 2] - B[:, :, 0]) @@ -89,30 +90,35 @@ while data is None: [ [ccw, cch], [args.width - ccw - 1, cch], - [ccw, args.height - ccw - 1], + [ccw, args.height - cch - 1], [args.width - ccw - 1, args.height - cch - 1], ] ), ) frame = cv2.warpPerspective(raw_frame, M, (args.width, args.height)) # Convert to new color space - frame = (np.squeeze(F @ (frame - origin)[..., np.newaxis]) >= 128).astype(np.uint8) - # import matplotlib.pyplot as plt + frame = (np.squeeze(F @ (frame - origin)[..., np.newaxis]) >= 192).astype(np.uint8) + # import matplotlib.pyplot as pltc # plt.imshow(frame * 255) # plt.show() - frame = np.concatenate( - ( - frame[:cheight, cwidth : args.width - cwidth].flatten(), - frame[cheight : args.height - cheight].flatten(), - frame[args.height - cheight :, cwidth : args.width - cwidth].flatten(), + frame = np.packbits( + np.concatenate( + ( + frame[:cheight, cwidth : args.width - cwidth].flatten(), + frame[cheight : args.height - cheight].flatten(), + frame[args.height - cheight :, cwidth : args.width - cwidth].flatten(), + ) ) ) - data = decoder.decode(bytes(rsc.decode(bytearray(np.packbits(frame) ^ frame_xor))[0][: args.psize])) + reshape_len = frame_bytes // 255 * 255 + frame[:reshape_len] = np.ravel(frame[:reshape_len].reshape(255, reshape_len // 255), "F") + data = decoder.decode(bytes(rsc.decode(bytearray(frame ^ frame_xor))[0][: args.psize])) print("Decoded frame") except KeyboardInterrupt: break - except: - traceback.print_exc() + except Exception as e: + print(e) +cap.release() with open(args.output, "wb") as f: f.write(data) -cap.release() +print(8 * len(data) / (time.time() - start_time)) |