nameWindow() 导致 opencv 2.3.1 崩溃? (XP、C 上的 Eclipse+MinGW)
我终于设法让 opencv 2.3.1 与 eclipse、mingw 和 32 位 XP 一起工作。当一切正常时,我会发布一份操作指南,因为我找不到该工具链的操作指南。
问题在于,任何在窗口中显示结果的尝试都会导致未处理的异常。图像保存得很好,而且我能够在它们上运行 Sobel 内核,所以其他一切看起来都很好。当调用namedWindow时它似乎崩溃了。
我将 libopencv_core231、libopencv_highgui231、libopencv_imgproc231 和 libopencv_legacy231 与链接器一起包含在内。
这是代码:
#include <cv.h>
#include <highgui.h>
#include <iostream>
using namespace cv;
int main(int argc, char **argv)
{
std::cout<<"Hello"<<std::endl;
//Create image
Mat lena, lenasobel;
//Load lena image
lena = imread("C:\\lena.jpeg");
if(lena.data)
std::cout<<"File has "<<lena.cols<<" rows and "<<lena.rows<<" columns. "<<lena.channels()<<" channels."<<std::endl;
if(!lena.data)
std::cout<<"File Not Read."<<std::endl;
lenasobel=lena.clone();
Sobel(lena,lenasobel,lenasobel.depth(),1,1,3);
std::vector<int> jpg_type;
jpg_type.push_back(100);
jpg_type.push_back(CV_IMWRITE_JPEG_QUALITY);
imwrite("C:\\lenaout.jpeg",lenasobel,jpg_type);
//Save works!
namedWindow( "lena" , CV_WINDOW_AUTOSIZE);
imshow( "lena" ,lena);
return 0;
}
有人有什么想法吗?我不知道下一步该做什么!
I've finally managed to get opencv 2.3.1 to work with eclipse, mingw and 32 bit XP. I'll put up a howto when everzthing works, as I couldn't find one for this toolchain.
The trouble is that any attempt to show the results in a window causes an unhandled exception. The images save fine, and I was able to run an Sobel kernel on them so everything else seems fine. It seems to crash when namedWindow is called.
I'm including libopencv_core231, libopencv_highgui231, libopencv_imgproc231 and libopencv_legacy231 with the linker.
Here is the code:
#include <cv.h>
#include <highgui.h>
#include <iostream>
using namespace cv;
int main(int argc, char **argv)
{
std::cout<<"Hello"<<std::endl;
//Create image
Mat lena, lenasobel;
//Load lena image
lena = imread("C:\\lena.jpeg");
if(lena.data)
std::cout<<"File has "<<lena.cols<<" rows and "<<lena.rows<<" columns. "<<lena.channels()<<" channels."<<std::endl;
if(!lena.data)
std::cout<<"File Not Read."<<std::endl;
lenasobel=lena.clone();
Sobel(lena,lenasobel,lenasobel.depth(),1,1,3);
std::vector<int> jpg_type;
jpg_type.push_back(100);
jpg_type.push_back(CV_IMWRITE_JPEG_QUALITY);
imwrite("C:\\lenaout.jpeg",lenasobel,jpg_type);
//Save works!
namedWindow( "lena" , CV_WINDOW_AUTOSIZE);
imshow( "lena" ,lena);
return 0;
}
Does anyone have any ideas? I'm not sure what to do next!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是由于这个一直存在的 bug 造成的。实际上,我必须设置 BUILD_TYPE=Debug 并禁用所有 SSE 优化才能让 OpenCV 与 Eclipse + MinGW 一起使用。
This is probably due to this bug that has been hanging around. I actually had to set
BUILD_TYPE=Debug
and disable all SSE optimizations to get OpenCV to work with Eclipse + MinGW.您不需要调用namedWindow。无论如何,当你调用 imshow 时它就会被创建。
另外,使用
lena.empty()
检查lena是否正确地在内存中。这是一个很好的做法,有时由于引用计数,lena.data 可能是一个过时的指针(比如说,如果你打开大规模优化......然后你将很难识别它,它只能正常工作< /em> 处于调试模式...)。You don't need to call namedWindow. It gets created when you call imshow anyway.
Also, use
lena.empty()
to check if lena is properly in the memory. It is a good practice and sometimes lena.data can be a stale pointer due to refcount (say, if you turn on massive optimizations... and then you'll be in trouble identifying it, it will work fine only in debug mode...).