在Mac OS X 10.10.2上使用waitKey的opencv imshow太慢(使用c ++) [英] opencv imshow with waitKey too slow on Mac OS X 10.10.2 (using c++)

查看:187
本文介绍了在Mac OS X 10.10.2上使用waitKey的opencv imshow太慢(使用c ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac OS X 10.10.2上使用opencv c ++处理视频帧并显示它们.带有waitKey的imshow用于显示视频的性能非常慢.

I am using opencv c++ on Mac OS X 10.10.2 to process video frames and display them. The performance of imshow with waitKey to display the video is extremely slow.

我有以下代码可以正确显示HD(1920x1080)灰度帧,除了它的运行速度大约慢了10倍(即每秒2到3帧而不是每秒30帧).

I have the following code which displays HD (1920x1080) grayscale frames correctly, except that it runs about 10 times too slow (i.e. 2 to 3 frames per second instead of 30 frames per second).

          cv::Mat framebuf[TEST_COUNT];

    //--- Code here to allocate and fill the frame buffer with about 4 seconds of video. This part works correctly.

        //--- This loop runs too slow by factor of approximately 10x
    for (int f = 0; f < TEST_COUNT; f++)
    {
        cv::imshow(windowName, framebuf[f]);
        cv::waitKey(33);
    }

有人可以建议如何从opencv imshow()获得实时或接近实时的性能吗?我看到很多帖子都指出他们正在实时显示视频,甚至比实时显示更快,所以我不确定自己做错了什么.任何帮助将不胜感激.

Can anyone suggest how to get real-time or near real-time performance from opencv imshow()? I have seen many posts that state that they are displaying video in real-time or even faster than real-time, so I am not sure what I am doing wrong. Any help would be greatly appreciated.

推荐答案

我可能是错的,但对我来说,问题不在于您的代码,而在于您的操作系统/配置.我写了一个小测试:

I could be wrong but for me the problem is not with your code, but with your os/configuration. I've written a small test:

import cv2
import numpy as np
from random import randrange
img = np.zeros((1920, 1080), dtype = np.uint8)
counter = 0
while counter < 1000:
    cv2.line(img, (randrange(0, 1920), randrange(0, 1080)), (randrange(0, 1920), randrange(0, 1080)), (randrange(0, 255)))
    cv2.imshow('test', img)
    temp = cv2.waitKey(1)
    counter += 1
    print counter

在我的机器(Core 2 duo 2,6Ghz x64、8gb ram,ssd)上,此测试花费了大约30秒.运行它,如果您获得的时间肯定比肯定多得多,则笔记本电脑/opencv配置/等有问题.我在Mac OS X上使用过OpenCV 2.4.x(我认为是10.9),并且运行良好.重新安装OpenCV是我想到的最明显的解决方案.删除OpenCV时,请使用brew重新安装它-brew install opencv --with-tbb --with-python --with-ffpmeg(或类似的内容-使用brew options opencv检查)应该可以.第一个选项告诉brew用tbb(线程构建块-用于多线程的库,有时可以显着提高速度)构建opencv,第二个选项安装python包装器,最后一个安装ffmpeg(处理编解码器等).

On my machine (Core 2 duo 2,6Ghz x64, 8gb ram, ssd) it took about 30 seconds for this test to complete. Run it and if you will get significantly bigger time than definitelly something is wrong with your laptop/opencv configuration/etc. I've used OpenCV 2.4.x on Mac OS X (it was 10.9 i think) and it was running fine. Reinstalling OpenCV is the most obvious solution which comes to my mind. When you remove OpenCV, use brew to install it again - brew install opencv --with-tbb --with-python --with-ffpmeg (or something similar - check using brew options opencv) should be fine. First options tells brew to build opencv with tbb(thread building block - library for multithreading, sometimes can significantly improve speed), second to install python wrappers, and the last one to install ffmpeg(handle codecs etc).

这篇关于在Mac OS X 10.10.2上使用waitKey的opencv imshow太慢(使用c ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆