Last active
May 12, 2022 08:52
-
-
Save ufxpri/70f346c85c0d789a8ec5dedad02f754f to your computer and use it in GitHub Desktop.
python shared memory video transfer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from multiprocessing.shared_memory import SharedMemory | |
| import cv2 | |
| # import time | |
| import numpy as np | |
| frame_shape_shm = SharedMemory('frame_shape') | |
| frame_shape = np.ndarray([3], buffer=frame_shape_shm.buf, dtype='i4') | |
| frame_ready_shm = SharedMemory('frame_ready') | |
| frame_ready = frame_ready_shm.buf | |
| frame_buffer_shm = SharedMemory('frame_buffer') | |
| frame_buffer = np.ndarray(frame_shape, buffer=frame_buffer_shm.buf, dtype='u1') | |
| try: | |
| while True: | |
| if frame_ready[0]==1: | |
| frame_ready[0]=0 | |
| cv2.imshow('frame', frame_buffer) | |
| cv2.waitKey(1) | |
| except KeyboardInterrupt: | |
| pass | |
| frame_buffer_shm.close() | |
| frame_buffer_shm.unlink() | |
| frame_ready_shm.close() | |
| frame_ready_shm.unlink() | |
| frame_shape_shm.close() | |
| frame_shape_shm.unlink() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
copy of stack overflow answer