python - 有没有办法提高 opencv 视频处理的速度?

标签 python opencv python-multithreading video-processing

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

有没有什么方法可以引入线程的概念来更快地处理视频?

我试过使用这个:How to increase performance of OpenCV cv2.VideoCapture(0).read() 我尝试实例化 __init__ 方法线程,但是,如何将它与读取 while 循环内帧的 while 循环连接起来。

最佳答案

这里有有用的教程:link1 link2

关于python - 有没有办法提高 opencv 视频处理的速度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64160416/

相关文章:

algorithm - FLANN 的使用可以归入机器学习吗?

c++ - 如何使用C++和OpenCV生成热图?

c++ - OpenCV Mat 数据成员访问

python - 在 Dask 中使用 read_csv 进行列名移位

python - 为什么我的 docopt 选项没有默认值?

python - 基本并行化。创建一个工作人员池,所有工作人员并行运行相同的功能

带有事件对象的 Python 线程

python - 在经过证书身份验证的资源上使用 python 请求下载列表文件

python - LSTM 预测一条直线

python - 有没有办法在一行中运行多个 %run 语句?