版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
在Linux里,按下面这样写,可能图片读不出来,img为空,但是在Windows里是可以的。
#include <iostream>
#include <fstream>
#include <opencv2/opencv.hpp>
#include <string>
using namespace std;
using namespace cv;
int main()
{
fstream file("name.txt",ios::in);
string name;
while(getline(file,name))
{
Mat img=imread(name,0);
imshow("img",img);
waitKey();
}
return 0;
}
需要对name进行转换,然后可以正常读取图片,不清楚是为什么。
#include <iostream>
#include <fstream>
#include <opencv2/opencv.hpp>
#include <string>
using namespace std;
using namespace cv;
int main()
{
fstream file("name.txt",ios::in);
string name;
while(getline(file,name))
{
string n;
istringstream ss(name);
ss>>n; //转换
Mat img=imread(n,0);
imshow("img",img);
waitKey();
}
return 0;
}