c++ - OpenCV imshow 不在 osx 中显示图像

标签 c++ macos opencv

我正在根据一本书工作,并复制了以下代码(本质上是 openCV 等同于“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 

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

我怀疑我在安装 OpenCV 时弄乱了环境或类似的环境,但是 cmake 没有抛出任何错误,并且代码按预期运行,在击键时正确退出等等,除了一个明显的异常(exception)缺少显示的照片。

有什么建议吗?

谢谢!

最佳答案

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

重复他们所说的,对我有用的是以下内容:

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

Change the following:

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

To this:

@implementation CVView
@synthesize image = _image;

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

Recompile OpenCV and test out your code.

希望这可以帮助其他正在努力解决这个问题的人!

关于c++ - OpenCV imshow 不在 osx 中显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44688437/

相关文章:

mysql - docker run mysql 图像命令不起作用 [MacBook Pro M1]

opencv - 如何在 OpenCV2 中使用 cv::Point 找到中点

c++ - cvSplit 中的 OpenCV 错误 : Assertion failed (i < src. channel ())

python - Tkinter 在第二个窗口中显示网络摄像头 View

c++ - 来自 Qt 文件的编译时错误 : expected unqualified-id before ')' token

c++ - 使用类的成员函数访问内部结构成员时出错

c++ - "Access denied"启动应用程序 - Windows Vista

c++ - 如何在c中查找同一字符串中该字符的第一次重复出现

objective-c - 优胜美地 : NSSavePanel: __NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array

swift - 如何在两个应用程序中实现模型?