'Is there a way to increase speed for video processing with opencv? [duplicate]

out = cv2.VideoWriter(output_file, codec, fps, (width,height))

while video.isOpened():
    has_frame, image = video.read()
    if has_frame:
        image_in = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
        image_in = tf.expand_dims(image_in, 0)
        image_in = transform_images(image_in, FLAGS.size)

        boxes, scores, classes, nums = get_yolo_model()(image_in)

        image = draw_outputs(image, (boxes, scores, classes, nums), get_class_names())
        image = cv2.putText(
            image, 
            "", 
            (0, 30), 
            cv2.FONT_HERSHEY_COMPLEX_SMALL, 
            1, 
            (0, 0, 255),
            2
        )

        out.write(image)

        frame_count += 1
        print('[In progress...] Writing frame:', frame_count)
    else:
        break

Is there a way I can introduce the concept of threading to process the video faster?

I have tried to use this: How to increase performance of OpenCV cv2.VideoCapture(0).read() I tried instantiating __init__ method Threading, however, how do I connect it with the while loop that reads the frames inside my while loop.



Solution 1:[1]

Here are useful tutorials: link1 link2

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MohammadHosseinZiyaaddini