0

to get better performance, i try to get frames with opencv from webcam and store them in a queue, then i want to run mediapipe in an extra thread to get the frames from the buffer and process them and show the image with the drawed landmarks. the video shown with cv2.imshow() in the mediapipe is much slower as when i run everything in the mainthread. i tried already to buffer the processed frames in a second queue and took the frames from there to display in a seperate method, but it is still slow. i tried several IDEAs ..without the processing operation it is still fast showing the video in seperate thread. but why is processing so slow in seperate thread? If anybody can help me that i can use mediapipe in seperate thread with a fast video that would be so great.

def process(input_buffer):
    with mp_holistic.Holistic(min_detection_confidence=0.5, min_tracking_confidence=0.5) as holistic:
        while True:
            frame = input_buffer.get()
            image, results = mediapipe_detection(frame, holistic)
            draw_styled_landmarks(image, results)

            # Show to screen
            cv2.imshow('Feed', image)

            # Break gracefully
            if cv2.waitKey(10) & 0xFF == ord('q'):
                break

input_buffer = queue.Queue()
thread = threading.Thread(target=process, args=(input_buffer,))
thread.start()
cap = cv2.VideoCapture(0)
# Set mediapipe model
while cap.isOpened():

        # Read feed
    ret, frame = cap.read()
    input_buffer.put(frame)


cap.release()
cv2.destroyAllWindows()

i tried already to buffer the processed frames in a second queue and took the frames from there to display in a seperate thread and method, but it is still slow. i tried several IDEAs . i tried multiprocessing instead of multithreading

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36

0 Answers0