OpenCV IMShow不在OSX中显示图像 [英] OpenCV imshow not displaying image in osx

查看:255
本文介绍了OpenCV IMShow不在OSX中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在整理一本书,并复制了以下代码(基本上相当于"hello world"的openCV):

I'm working right out of a book, and copied the following code (essentially the openCV equivalent of "hello world"):

//helloCV.cpp
#include <opencv2/opencv.hpp>

int main(int argc, char** argv){

        cv::Mat img = cv::imread(argv[1], -1);
        if (img.empty()) return -1;

        cv::namedWindow("Example1", cv::WINDOW_AUTOSIZE);
        cv::imshow("Example1", img);
        cv::waitKey(0);
        cv::destroyWindow("Example1");

        return 0;

}//main 

不幸的是,当我运行这段代码时,我得到一个带有标题的窗口,里面没有任何内容:

Unfortunately, when I run this code, I get a window with the header and nothing in it:

我怀疑我在安装OpenCV时弄乱了环境或类似的东西,但是cmake没有抛出任何错误,并且代码按预期运行,在击键时正确退出了所有这些,但明显的例外是缺少显示的照片.

I suspect that I've messed up the environment or some such when installing OpenCV, but cmake is throwing no errors, and the code runs as expected, exiting correctly on a keystroke and all of that, with the glaring exception of a lack of a displayed photo.

有什么提示吗?

谢谢!

推荐答案

感谢@DanMašek在此方面的领导,以及本页面上的所有人员: http://answers.opencv.org/question/160201/video-window-not-loading-frame/

Thanks to @DanMašek for the lead on this one, and to all the people on this page: http://answers.opencv.org/question/160201/video-window-not-loading-frame/

要重复他们说的话,对我有用的是:

To repeat what they said, what worked for me was the following:

要解决此问题,请找到文件window_cocoa.mm;.如果是从源代码构建的,它将位于opencv/modules/highgui/src中.

To resolve this, locate the file window_cocoa.mm; if built from source it'll be in opencv/modules/highgui/src.

更改以下内容:

@implementation CVView
#if defined(__LP64__)
@synthesize image;
#else // 32-bit Obj-C does not have automatic synthesize
@synthesize image = _image;
#endif

为此:

@implementation CVView
@synthesize image = _image;

对CVWindow和CVSlider实现也执行相同的操作以容纳视频.

Do the same thing for the CVWindow and CVSlider implementations to accommodate videos as well.

重新编译OpenCV并测试您的代码.

Recompile OpenCV and test out your code.

希望这可以帮助其他在此问题上苦苦挣扎的人!

Hope this helps other people struggling with this issue!

这篇关于OpenCV IMShow不在OSX中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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