diff options
author | Anthony Wang | 2024-05-12 16:33:34 -0400 |
---|---|---|
committer | Anthony Wang | 2024-05-12 16:33:34 -0400 |
commit | 3d0382268958a5923fe3eb1df8161c78375fcf93 (patch) | |
tree | e0e79e8b550f3596f34e9e8237fb49f52ad50973 /decoder.py | |
parent | 7a2c685c156b3aff30c736ca80765b9e9ba153b8 (diff) |
Run camera at 60fps and use state machine to skip every other frame
Diffstat (limited to 'decoder.py')
-rw-r--r-- | decoder.py | 19 |
1 files changed, 14 insertions, 5 deletions
@@ -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)) |