Home > Software engineering >  Process image only when new image received from USB camera
Process image only when new image received from USB camera

Time:01-03

I am new to multithreading/processing. I have created a multithreaded application in Python3.

  1. Thread 1 reads from the USB camera with cv2.VideoCapture()
  2. Main Thread process this image and returns the postprocessed image.

I realised that the Main Thread is running 3~4 times on the same image frame. How should I make it such that the Main Thread processing function only runs on new image frames that come from the USB camera? Which methods/objects should I use to enable this?

CodePudding user response:

There are a few ways of doing this:

  • Use a Queue. The frame-processing thread does a blocking wait on the queue and the frame grabbing thread puts a message on the queue to say a frame is ready. No need to put the whole video frame on the queue, just put an index into a list of frames so it can get it and process it while acquisition thread reads next frame into a different buffer.
  • Use a multiprocessing event.

Both these ideas are covered very well here.

  • Related