aboutsummaryrefslogtreecommitdiff
path: root/decoder.py
diff options
context:
space:
mode:
authorAnthony Wang2024-04-28 19:25:38 -0400
committerAnthony Wang2024-04-28 19:25:38 -0400
commit5259da7b02e62f81c383fa67e06cd7ee554e6301 (patch)
tree00d68a1c129043212a0bcd8cdc29d8612fc13467 /decoder.py
parent922d8e7834df411818341639dd859d3f6ff21880 (diff)
Crop webcam image to prevent perspective distortion, correctly truncate frame for raptor code using CLI flag, make encoder.py print flags
Diffstat (limited to 'decoder.py')
-rw-r--r--decoder.py10
1 files changed, 7 insertions, 3 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()