【发布时间】:2011-12-13 11:42:36
【问题描述】:
- 我在 Visual Studio 2010 (vc10) 上使用 Opencv 2.3.1
- 我已经根据很多教程配置了opencv,可以编译和运行C-syntax程序,比如:
#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)
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.
我该如何解决这个问题?
【问题讨论】:
-
"D:\cat_helmet"绝对是错误的。"D:\\cat_helmet.jpg". -
在 namedWindow() 命令中出现访问冲突错误。两种声明图像文件的方式都可以。我成功编译并运行了上面的前一段代码。
-
你是把opencv_core231.dll和opencv_highgui231.dll放在run目录下,还是把这些dll放在path里,这样就可以动态链接了?
-
考虑查看我们的教程,了解如何在 VS2010 上安装/配置 OpenCV 2.3:stackoverflow.com/questions/7011238/…
-
@karlphillip:我几天前就跟着你的教程。太棒了,谢谢 :) 现在,我已经转移到 Ubuntu 11.10,仍然使用 Opencv 2.3 并且可以正确运行代码。可能是 Opencv 的 C++ 接口对于 Windows 仍然不稳定。任何想在 ubuntu 上使用 opencv 的人都可以在这里看到一个很棒的教程:ozbots.org/opencv-installation
标签: c++ c visual-studio-2010 opencv