每次都提示找不到文件,但是文件名是对的且放在源码同级目录下
https://blog.csdn.net/weixin_41519463/article/details/86553704
每次都提示找不到文件,肯定是路径错了,根据上面博文的提示,把文件放在项目文件夹中,而不是源码文件夹中
图中的第一个1.png加载不了,在src文件夹下
下面的1.png,路径为String imageName = "src//1.png";
其余两张,路径为String imageName = "2.jpeg";
或String imageName = ".//3.jpg";
(.//表示项目目录下的文件夹下)
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <string>
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
String imageName = ".//3.jpg"; // by default
if (argc > 1) {
imageName = argv[1];
cout << "there is a file" << std::endl;
}
Mat image;
image = imread(imageName, IMREAD_COLOR); // Read the file
if (image.empty()) // 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;
}