原因是工作目录未选择对,导致必须使用绝对路径才能正常读取代码同级本地图像。
之后将图像和代码放到同级就可以直接读取啦!
这个不用绝对路径也能读取啦!
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main() {
Mat img = imread("test.jpg");
if (img.empty()) {
cout << "Error" << endl;
return -1;
}
namedWindow("pic", WINDOW_FULLSCREEN);
imshow("pic", img);
waitKey();
return 0;
}