0

I'm trying to add a camera image showing component to an existing python program that shows multiple input in real time from various hardware devices.

To that end, I need to use openCV's imshow() function on the main thread to show frames from separate frame capture and processing threads (since imshow() doesn't work outside it).

From what I understand I can't use a while loop to do that, since the program would be stuck on it and everything else would not run. What could be a solution? I wondered about putting everything else on a separate thread (including the frame grab 'sub-threads') and keeping only imshow on the main one. But that doesn't seem right.

EDIT

The problem with the imshow() function on the frame capture/display thread was apparently not adding a cv2.waitKey(1) function. Not including that line causes the window to freeze even in the main thread.

haryor
  • 23
  • 4
  • why cant you put the `imshow()` in its own thread? – DrBwts May 25 '22 at 09:45
  • W/out loop you will single frame and stop. – toyota Supra May 25 '22 at 12:30
  • @DrBwts In questions such as [this](https://stackoverflow.com/questions/44577228/multithreaded-cv2-imshow-in-python-does-not-work) and [this](https://stackoverflow.com/questions/60737852/opencv-imshow-hangs-if-called-two-times-from-a-thread) people mention that it doesn't work on threads. The reason I found out about this is because I also get the hanging gray/empty OpenCV named window. But everyone seems to have vastly different opinions on what a solution would be, and some mention having the imshow() on the main thread, which I think doesn't work for me. – haryor May 26 '22 at 02:33
  • @toyotaSupra That's true. It's the reason why I'm trying to find some way to use a loop without hanging the rest of the code but at the same time doesn't conflict with OpenCV imshow function. – haryor May 26 '22 at 02:36
  • I understood. I see what your problem is. There is no way to do a loop. Only when pressing the button to pause and pressing again to continue. I was doing my electronic project. – toyota Supra May 26 '22 at 02:48

1 Answers1

0

I don't have rep enough to comment, so I am writing here. I think you can use simple ROS structure to publish frames as ros-topic then do what ever you want with different ros-nodes.