vid*_*dzz 8 c++ opencv loadimage mat
我想在 openCV 中使用 Mat 加载图像
我的代码是:
Mat I = imread("C:/images/apple.jpg", 0);
namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", I );
Run Code Online (Sandbox Code Playgroud)
我在消息框中收到以下错误:
Unhandled exception at 0x70270149 in matching.exe: 0xC0000005: Access violation
reading location 0xcccccccc.
Run Code Online (Sandbox Code Playgroud)
请注意,我包括:
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <iostream>
#include <math.h>
Run Code Online (Sandbox Code Playgroud)
kar*_*lip 10
我已经谈过这个这么多次前,我想这是毫无意义的做一遍,但代码防守:如果一个方法/函数调用失败,请确保您知道什么时候会发生:
Mat I = imread("C:\\images\\apple.jpg", 0);
if (I.empty())
{
std::cout << "!!! Failed imread(): image not found" << std::endl;
// don't let the execution continue, else imshow() will crash.
}
namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", I );
waitKey(0);
Run Code Online (Sandbox Code Playgroud)
请注意,Windows 的路径使用反斜杠\而不是/*nix 系统上使用的标准。传递文件名时需要转义反斜杠:C:\\images\\apple.jpg
编辑:
如果cv::imread()是抛出异常,我知道唯一可行的解决方案是下载 OpenCV 源代码并在机器上构建它,因为重新安装 OpenCV 并不能解决问题。