aboutsummaryrefslogtreecommitdiff
path: root/decoder.py
diff options
context:
space:
mode:
Diffstat (limited to 'decoder.py')
-rw-r--r--decoder.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/decoder.py b/decoder.py
index 43d06a5..a1c0d51 100644
--- a/decoder.py
+++ b/decoder.py
@@ -47,13 +47,19 @@ if args.input.isdecimal():
args.input = int(args.input)
cap = cv2.VideoCapture(args.input)
data = None
-start_time = time.time()
+start_time = 0
+status = 0
+decoded = 0
while data is None:
try:
ret, raw_frame = cap.read()
if not ret:
print("End of stream")
break
+ if isinstance(args.input, int) and (status == 1 or (status == 0 and np.random.rand() < 0.5)):
+ status = 2
+ print("Skipped")
+ continue
# raw_frame is a uint8 BE CAREFUL
if type(args.input) == int:
# Crop image to reduce camera distortion
@@ -98,9 +104,6 @@ while data is None:
frame = cv2.warpPerspective(raw_frame, M, (args.width, args.height))
# Convert to new color space
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.packbits(
np.concatenate(
(
@@ -109,16 +112,22 @@ while data is None:
frame[args.height - cheight :, cwidth : args.width - cwidth].flatten(),
)
)
- )
+ )[:frame_bytes]
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]))
+ decoded += 1
+ status = 1
+ if start_time == 0:
+ start_time = time.time()
print("Decoded frame")
except KeyboardInterrupt:
break
except Exception as e:
+ status = 0
print(e)
cap.release()
+print(decoded)
with open(args.output, "wb") as f:
f.write(data)
print(8 * len(data) / (time.time() - start_time))