jeffbass / imagezmq

A set of Python classes that transport OpenCV images from one computer to another using PyZMQ messaging.
MIT License
1.01k stars 160 forks source link

handle reading threaded frames from the Imagezmq #80

Open mikahoy045 opened 1 year ago

mikahoy045 commented 1 year ago

Hi Jeff, I want to stream from camera to PC using imagezmq(camera stream to PC using normal open cv is okay). I plan to added custom yolov7 object detection. After digging the source it seems that yolov7 using loadstream function that runs the frames received using threads ( loadstream function line 266) that works basically like in here.

Is there any example codes or suggestion so that I can consume the imagezmq frame while keep the processing of the frame in threading (so that it still speeds up the fps even using CPU)?

jeffbass commented 1 year ago

I think you are asking about consuming the imageZMQ frames on the image receiving end (rather than threading the camera-image-sending end).

I use a receive frame loop in the main program with a thread to consume / process the frames in my imagehub repository.

The main program receiving frames in a forever loop is here. The thread processing the frames is here at line 75. It is a simple process that writes the frames to disk, which is IO bound and makes if a good candidate for threading.

The frames are passed from the main image capture loop to the image thread using a deque from collections.deque. I use this because deque's are thread-safe. If you use some other way to pass frames from main to thread, you need to make sure your method is thread safe.

A thread to feed frames to a yolo7 consumer could work in the same way.