D
D
DUDE2020-04-08 18:31:27
Python
DUDE, 2020-04-08 18:31:27

How to deal with multithreading in OpenCV?

Hello everyone, I've been sitting for three hours now and I can't understand. I need to capture from the camera in one thread, and output to the screen in the other thread. Anyone have any suggestions how to do this?

It is clear that there will be two functions:

...

camera = cv2.VideoCapture(0,  cv2.CAP_DSHOW)


def read():
    while True:
        result, frame = camera.read()

def show():
    while True:
        cv2.imshow("test", frame)


t1 = threading.Thread(target=read)
t2 = threading.Thread(target=show)

t1.start()
t2.start()

t1.join()
t2.join()

...

Yes, this code is written incorrectly. This is the question, how to organize the work and data exchange of streams so that it all works?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DUDE, 2020-07-20
@stympel

In general, in short, the guys made two class based threads, created a queue and worked with it, no magic in general.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question