无法在opencv中读取图像?

时间:2015-05-11 09:28:40

标签: c++ opencv opencv3.0

我正在openCV和VB2013中编写我的第一个代码,但我无法读取图像。我正在尝试使用示例代码。

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
if (argc != 2)
{
    cout << " Usage: display_image ImageToLoadAndDisplay" << endl;
    return -1;
}

Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR);   // Read the file

if (!image.data)                              // Check for invalid input
{
    cout << "Could not open or find the image" << std::endl;
    return -1;
}

namedWindow("Display window", WINDOW_AUTOSIZE);// Create a window for display.
imshow("Display window", image);                   // Show our image inside it.

waitKey(0);                                          // Wait for a keystroke in the window
return 0;
}

这向我显示:

enter image description here

这是我存储图片的地方:

enter image description here

1 个答案:

答案 0 :(得分:0)

要么我们必须给出图像的位置。 或者我们可以使用命令行,我们必须再次给出图像的位置。 或者我们可以这样使用代码。enter link description here