c/c++语言读取某一文件夹下所有图片并利用opencv全部显示出来

c语言读取某一文件夹下所有图片并利用opencv全部显示出来

代码

#include <io.h>
#include <string>
#include <vector>
#include <fstream>
#include "opencv2/core/core.hpp"    
#include "opencv2/imgproc/imgproc.hpp"    
#include "opencv2/calib3d/calib3d.hpp"    
#include "opencv2/highgui/highgui.hpp"    
#include <iostream>    
#include <fstream>    
#include <iostream>

#include <stdlib.h> //srand()和rand()函数 
#include<windows.h>

using namespace cv;
using namespace std;

class Ve 
{
    
    
	public:
		vector<string> ReadImage(cv::String pattern);
};

vector<string> Ve::ReadImage(cv::String pattern)
{
    
    
	vector<string> temp;
	vector<cv::String> fn;
	glob(pattern, fn, false);
	size_t count = fn.size(); //number of png files in images folder
	for (size_t i = 0; i < count; i++)
	{
    
    
		temp.push_back(fn[i]);
	}
	return temp;
}


int main() 
{
    
    

	cv::String pattern = "./caliberation/*.jpg";
	Ve ve;
	vector<string> img_path = ve.ReadImage(pattern);

	for (int i = 0; i < img_path.size(); i++) 
	{
    
    

		cout << img_path[i] << endl;
		imshow("img", imread(img_path[i]));
		waitKey(10);
	}

	return 0;
}

猜你喜欢

转载自blog.csdn.net/mao_hui_fei/article/details/120410212