无法使用 C++ 运行 Opencv句法
- 我在 Visual studio 2010 (vc10) 上使用 Opencv 2.3.1
- 我已经根据许多教程配置了 opencv,并且可以编译&运行 C 语法程序,如:
#include "StdAfx.h"
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main ()
{
IplImage* img = cvLoadImage("D:\cat_helmet.jpg", CV_LOAD_IMAGE_UNCHANGED);
cvNamedWindow("display", CV_WINDOW_AUTOSIZE);
cvShowImage("display", img );
cvWaitKey(0);
return 0;
}
但是,我无法运行 C++ 语法程序,如
#include "StdAfx.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( )
{
namedWindow( "Display window", CV_WINDOW_AUTOSIZE );
Mat image;
image = imread("D:\cat_helmet", CV_LOAD_IMAGE_COLOR);
if(! image.data )
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
imshow( "Display window", image );
waitKey(0);
return 0;
}
我收到错误消息(在函数调用中:namedWindow、imread、imshow)
<代码> FirstOpencv2.3.exe 中 0x5361fcc3 处的首次机会异常:0xC0000005:读取位置 0x2079616c 时发生访问冲突。
<代码> FirstOpencv2.3.exe 中 0x5361fcc3 处出现未处理的异常:0xC0000005:读取位置 0x2079616c 时发生访问冲突。 ?
我该如何解决这个问题
- Im using Opencv 2.3.1 on Visual studio 2010 (vc10)
- I have configured opencv based on many tutorials and can compile & run C-syntax program like:
#include "StdAfx.h"
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main ()
{
IplImage* img = cvLoadImage("D:\cat_helmet.jpg", CV_LOAD_IMAGE_UNCHANGED);
cvNamedWindow("display", CV_WINDOW_AUTOSIZE);
cvShowImage("display", img );
cvWaitKey(0);
return 0;
}
However, I cannot run the C++ syntax program like
#include "StdAfx.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( )
{
namedWindow( "Display window", CV_WINDOW_AUTOSIZE );
Mat image;
image = imread("D:\cat_helmet", CV_LOAD_IMAGE_COLOR);
if(! image.data )
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
imshow( "Display window", image );
waitKey(0);
return 0;
}
I got the error messages (in the function calls: namedWindow, imread, imshow)
First-chance exception at 0x5361fcc3 in FirstOpencv2.3.exe: 0xC0000005: Access violation reading location 0x2079616c.
Unhandled exception at 0x5361fcc3 in FirstOpencv2.3.exe: 0xC0000005: Access violation reading location 0x2079616c.
How can I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您说您已经遵循了大量的指南和教程。我在这方面取得了巨大的成功
http://www.anlak。 com/using-opencv-2-3-1-with-visual-studio-2010-tutorial/
问题是,这个人会带您穿过“公园”,并帮助您解决两个主要问题,同时设置 OpenCV 2.3.1;其中之一是将 .dll 文件放置在项目文件夹中。另一个是缺少 .dll“tbb_debug.dll”(该 .dll 的缺失被认为是 OpenCV 2.3.1 中的错误)。
他还提供了一些不错的代码片段供您尝试(使用 C++ 语法)。
祝你好运。
You say that you have followed a multitude of guides and tutorials. I've had great success with this one
http://www.anlak.com/using-opencv-2-3-1-with-visual-studio-2010-tutorial/
The thing is that this guy walks you through the 'park' and helps you unravel two major issues whilst setting up OpenCV 2.3.1; one of which is placement of .dll files in your project folder. The other is a missing .dll 'tbb_debug.dll' (the absense of this .dll is considered a bug in OpenCV 2.3.1).
He also provides some decent code-snippets for your to try out (in c++ syntax).
Good luck.
上面的回答没有任何意义。我也面临着同样的问题。此异常的主要原因是您试图显示空图像(由 imread 读取)。程序中的主要问题是
我认为 imread 函数的行为不符合预期的行。另一件事是,在浏览参考资料时,我发现了以下链接:
http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imread#Mat imread(const string& filename, int flags)
这里,imread是通过引用调用的方式使用的。我不是 C++ 专家,但我觉得这可能是问题所在。
这段代码对我有用。另外,我将该文件放在可执行文件旁边以降低复杂性。
The above mentioned answers doesn't make sense. I am also facing the same problem. The main reason for this exception is that you are trying to display image (read by imread) which is empty. The main problem in the program is the line
I think imread function is not behaving the way it is expected. One more thing, while going through the references i came across a following link:
http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imread#Mat imread(const string& filename, int flags)
Here, imread is used via call by reference method. I am not a C++ expert, but i feel it could be the problem.
This code worked for me. Also, I put the file next to executable to decrease complexity.