Mat img = imread(fileName);
地址\单或\\双都可以
是否加载成功
if(image.empty()) //Check for invalid input
{
cout << "找不到图片请检查路径\n";
return-1;
}
是否有数据
if (!image.data)
{
cout << "加载图片失败" << endl;
//cout << "找不到图片请检查路径\n";
return 0;
//return-1;
}
// opencvtest.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include<opencv2/highgui.hpp>
#include<opencv2/core.hpp>
#include<opencv2/imgcodecs.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat image;
image = imread("D:\8968.jpg"); //read the file 地址也可以用D:\\8969.jpg
//if(image.empty()) //Check for invalid input
if (!image.data)
{
cout << "加载图片失败" << endl;
//cout << "找不到图片请检查路径\n";
return 0;
//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
//std::cout << "Hello World!\n";
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file