OpenCV学习(十三)之根据路径连续加载图像放入vector中,最后再一张一张显示出来

实验环境:VS2010 + OpenCV2.4.9

#include <iostream>
#include <afx.h>
#include <vector>
#include <string>
#include "cv.h"
#include "highgui.h"

using namespace std;
using namespace cv;

vector<Mat> tMat;

void loadImage()
{
	CString path;
	path = L"test\\*.jpg";

	CFileFind finder;
	bool selectFlag = finder.FindFile(path);
	while(selectFlag)
	{
		selectFlag = finder.FindNextFileW();
		if(selectFlag)
		{
			CString str = finder.GetFilePath();
			CT2A pszConvertedAnsiString(str);
			std::string fileName(pszConvertedAnsiString);
			//加载为灰度图
			Mat img = imread(fileName,CV_LOAD_IMAGE_GRAYSCALE);
			tMat.push_back(img);
			cout << "Load Image Successful!" << endl;
		}
	}
}

int main(int argc, char** argv)
{
	loadImage();

	//cout << tMat.size() << endl;
	//vector<string> wndName(tMat.size());
	//int count = 0;
	//for(int i = 0;i < tMat.size();i++)
	//{
	//	if(tMat.at(i).empty())
	//	{	
	//		cout << "!!!" << endl;
	//		continue;
	//	}
	//	else
	//	{
	//		wndName.at(i) = i;
	//		namedWindow(wndName.at(i),CV_WINDOW_AUTOSIZE);
	//		imshow(wndName.at(i),tMat.at(i));
	//		++count;
	//	}
	//}
	为什么这种方法读出来的图片数目多一个,
	但是第一个和第二个为空。why?也就是说总的能显示出来的图片少了一个
	tMat也是从第二个开始显示的
	//cout << "count is: " << count << endl;

	vector<string> wndName(tMat.size());
	for(int i = 0;i < tMat.size();i++)
	{
		string typex= "Type: ";
		char name = 'i';
		putText(tMat[i],typex,Point( tMat[i].rows/2,tMat[i].cols/4),CV_FONT_HERSHEY_COMPLEX, 1, Scalar(255, 255, 255));
		wndName[i] = i;
		namedWindow(wndName[i],CV_WINDOW_AUTOSIZE);
		imshow(wndName[i],tMat[i]);	//显示图片
	}

	waitKey();
	system("pause");
	return 1;
}
主函数中注释掉的code和下面的code实则是一样的,只是保留了调试的代码而已。但是的确通过这种方法加载读入并显示的的时候,少了一张图片,不知道为什么????╮(╯▽╰)╭

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值