OpenCV imshow不在osx中显示图像

2024-09-30 14:21:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在从一本书中学习,并复制了以下代码(基本上是“hello world”的openCV等价物):

//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没有抛出任何错误,代码按预期运行,在击键时正确退出,所有这一切,除了缺少显示的照片之外。在

有什么提示吗?在

谢谢!在


Tags: 代码helloimgworldreturnincludemainopencv
1条回答
网友
1楼 · 发布于 2024-09-30 14:21:17

感谢@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:

^{pr2}$

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

Recompile OpenCV and test out your code.

希望这能帮助其他人解决这个问题!在

相关问题 更多 >