问题描述
我正在写一本书,并复制了以下代码(本质上是hello world"的 openCV 等价物):
//helloCV.cpp#include int main(int argc, char** argv){cv::Mat img = cv::imread(argv[1], -1);如果 (img.empty()) 返回 -1;cv::namedWindow("Example1", cv::WINDOW_AUTOSIZE);cv::imshow("Example1", img);简历::等待键(0);cv::destroyWindow("Example1");返回0;}//主要的
不幸的是,当我运行这段代码时,我得到了一个带有标题的窗口,里面什么也没有:
我怀疑在安装 OpenCV 时我搞砸了环境或某些类似的东西,但是 cmake 没有抛出任何错误,并且代码按预期运行,在击键时正确退出等等,除了一个明显的例外缺少显示的照片.
有什么建议吗?
谢谢!
感谢 @DanMaek 在这方面的领导,以及此页面上的所有人:http://answers.opencv.org/question/160201/video-window-not-loading-frame/一个>
重复他们所说的,对我有用的是以下内容:
<块引用>要解决此问题,请找到文件 window_cocoa.mm;如果从源代码构建,它将在 opencv/modules/highgui/src 中.
更改以下内容:
@implementation CVView#如果已定义(__LP64__)@合成图像;#else//32 位 Obj-C 没有自动合成@合成图像 = _image;#万一
<块引用>
为此:
@implementation CVView@合成图像 = _image;
<块引用>
对 CVWindow 和 CVSlider 实现做同样的事情以适应视频.
重新编译 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:
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.
Any tips?
Thanks!
Thanks to @DanMaek 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:
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.
Hope this helps other people struggling with this issue!
这篇关于OpenCV imshow 不在 osx 中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!