【opencv/c++/机器学习】人工神经网络ANN识别数字

目录

 

前言

一.模型训练

二.数字预测


前言

本级环境:win10/vs2017/opencv3.4.0/c++

训练样本:数字0-9   共十组   每组50张图片

一.模型训练

代码:

注意:win7与win10句柄的定义类型有所区别,具体的代码中已注释

#include <io.h>
#include <string>
#include <iostream>
#include <opencv2\opencv.hpp>
#include <opencv2\ml.hpp>
using namespace cv;
using namespace ml;
using namespace std;
int main()
{
	//////******************遍历文件夹下的图片读取训练样本******************//////
	//将图片大小转化为8*16越大训练时间越长
	const int imageRows = 8;
	const int imageCols = 16;
	//图片共有10类   数字0-9
	const int classSum = 10;//******201907111731******
	//每类共50张图片
	const int imagesSum = 50;
	//每一行一个训练图片
	float trainingData[classSum*imagesSum][imageRows*imageCols] = { {0} };
	//训练样本标签
	float labels[classSum*imagesSum][classSum] = { {0} };
	Mat src, resizeImg, trainImg;
	for (int i = 0; i < classSum; i++)
	{
		//目标文件夹路径
		std::string inPath = "E:\\333333神经网络ann\\test\\Numpicture\\";
		char temp[256];
		int k = 0;
		sprintf_s(temp, "%d", i);
		inPath = inPath + temp + "\\*.png";
		//用于查找的句柄
		//lon
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值