C++实现基于模板匹配的手写数字识别

#include<iostream>
#include<fstream>
#include<opencv2/opencv.hpp>
#include<io.h>                          //api和结构体
#include<string>


using namespace std;
using namespace cv;


void readTestImg(const cv::String& imgpath,int num)
{
	cv::String train_path = "D:/code/cv/课程数据集/手写数字/训练集";
	ostringstream newos;
	newos << num;
	train_path = train_path + "/" + newos.str() + "_train.txt";
	ifstream myfile(train_path, ios::in);
	string temp;
	string res;
	while (getline(myfile, temp)) {
		res += temp;
		res += '\n';
	}
	//cout << res;
	myfile.close();
	//1-125
	//一些比较
	int faslenums = 0, truenums = 0;
	double sums = 0;
	for (int label = 1; label < 126; label++)
	{
		cv::String path;
		cv::Mat img;
		ostringstream os; //构造一个输出字符串流,流内容为空
		os << label;
		path = imgpath + "/"+os.str()+".bmp";
		os.clear();
		//cout <<"图片路径: "+path << endl;
		img = cv::imread(path);
		cvtColor(img, img, COLOR_BGR2GRAY
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值