aboutsummaryrefslogtreecommitdiff
path: root/decoder.py
diff options
context:
space:
mode:
Diffstat (limited to 'decoder.py')
-rw-r--r--decoder.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/decoder.py b/decoder.py
index 2467328..2229bd8 100644
--- a/decoder.py
+++ b/decoder.py
@@ -15,6 +15,7 @@ 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("-e", "--erasure", help="detect erasures", action="store_true")
args = parser.parse_args()
cheight = cwidth = max(args.height // 10, args.width // 10)
@@ -47,9 +48,9 @@ while data is None:
ret, raw_frame = cap.read()
if not ret:
print("End of stream")
- sys.exit(1)
- # cv2.imshow("", raw_frame)
- # cv2.waitKey(33)
+ break
+ cv2.imshow("", raw_frame)
+ cv2.waitKey(1)
# raw_frame is a uint8 BE CAREFUL
raw_frame = cv2.cvtColor(raw_frame, cv2.COLOR_BGR2RGB)
@@ -118,7 +119,8 @@ while data is None:
frame = (frame[::2] << 4) + frame[1::2]
frame = np.pad(frame, (0, (len(frame) + 254) // 255 * 255 - len(frame)))
frame = np.ravel(frame.reshape(255, len(frame) // 255), "F")[: frame_size // 2]
- data = decoder.decode(bytes(rsc.decode(frame ^ frame_xor, erase_pos=list(np.where(frame == 0)[0]))[0]))
+ erase_pos = list(np.where(frame == 0)[0]) if args.erasure else []
+ data = decoder.decode(bytes(rsc.decode(frame ^ frame_xor, erase_pos=erase_pos)[0]))
print("Decoded frame")
except KeyboardInterrupt:
sys.exit()