• 大小: 11.57MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-06-15
  • 语言: 其他
  • 标签: opencv  图像处理  

资源简介

已经训练好样本,可以识别当前图像或者视频的数字,或者是实时聪摄像头获取的视频。改videocapture()括号的参数是图片名或者视频名或者是0代表当前摄像头

资源截图

代码片段和文件信息

//opencv2.4.9 + vs2012 + 64位
#include 
#include 
#include 

using namespace cv;
using namespace std;

char* WcharToChar(const wchar_t* wp)  
{  
    char *m_char;
    int len= WideCharToMultiByte(CP_ACP0wpwcslen(wp)NULL0NULLNULL);  
    m_char=new char[len+1];  
    WideCharToMultiByte(CP_ACP0wpwcslen(wp)m_charlenNULLNULL);  
    m_char[len]=‘\0‘;  
    return m_char;  
}  

wchar_t* CharToWchar(const char* c)  
{   
wchar_t *m_wchar;
    int len = MultiByteToWideChar(CP_ACP0cstrlen(c)NULL0);  
    m_wchar=new wchar_t[len+1];  
    MultiByteToWideChar(CP_ACP0cstrlen(c)m_wcharlen);  
    m_wchar[len]=‘\0‘;  
    return m_wchar;  
}  

wchar_t* StringToWchar(const string& s)  
{  
    const char* p=s.c_str();  
    return CharToWchar(p);  
}  

int main()
{
const string fileform = “*.png“;
    const string perfileReadPath = “charSamples“;

    const int sample_mun_perclass = 20;//训练字符每类数量
    const int class_mun = 10;//训练字符类数

    const int image_cols = 8;
    const int image_rows = 16;
    string  fileReadName
            fileReadPath;
    char temp[256];

    float trainingData[class_mun*sample_mun_perclass][image_rows*image_cols] = {{0}};//每一行一个训练样本
    float labels[class_mun*sample_mun_perclass][class_mun]={{0}};//训练样本标签

    for(int i=0;i<=class_mun-1;++i)//不同类
    {
//读取每个类文件夹下所有图像
int j = 0;//每一类读取图像个数计数
        sprintf(temp “%d“ i);
fileReadPath = perfileReadPath + “/“ + temp + “/“ + fileform;
cout<<“文件夹“< HANDLE hFile;
LPCTSTR lpFileName = StringToWchar(fileReadPath);//指定搜索目录和文件类型,如搜索d盘的音频文件可以是“D:\\*.mp3“
WIN32_FIND_DATA pNextInfo;  //搜索得到的文件信息将储存在pNextInfo中;
hFile = FindFirstFile(lpFileName&pNextInfo);//请注意是 &pNextInfo  不是 pNextInfo;
if(hFile == INVALID_HANDLE_VALUE)
{
exit(-1);//搜索失败
}
//do-while循环读取
do
{
if(pNextInfo.cFileName[0] == ‘.‘)//过滤.和..
continue;
j++;//读取一张图
//wcout< printf(“%s\n“WcharToChar(pNextInfo.cFileName));
//对读入的图片进行处理
Mat srcImage = imread( perfileReadPath + “/“ + temp + “/“ + WcharToChar(pNextInfo.cFileName)CV_LOAD_IMAGE_GRAYSCALE);
Mat resizeImage;
Mat trainImage;
Mat result;

resize(srcImageresizeImageSize(image_colsimage_rows)(00)(00)CV_INTER_AREA);//使用象素关系重采样。当图像缩小时候,该方法可以避免波纹出现
threshold(resizeImagetrainImage0255CV_THRESH_BINARY|CV_THRESH_OTSU);

for(int k = 0; k            {
trainingData[i*sample_mun_perclass+(j-1)][k] = (float)trainImage.data[k];
                //trainingData[i*sample_mun_perclass+(j-1)][k] = (float)trainImage.at((int)k/8(int)k%8);//(float)train_image.data[k];
                //cout<(k/8k%8)<            }

} while (FindNextFile(hFile&pNextInfo) && j

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件    1432166  2016-05-13 09:16  ann数字识别\ConsoleApplication1\bpcharModel.xml

     文件     223273  2016-05-12 17:14  ann数字识别\ConsoleApplication1\ConsoleApplication1\22.jpg

     文件     243619  2016-05-12 17:23  ann数字识别\ConsoleApplication1\ConsoleApplication1\232.jpg

     文件       5932  2016-05-13 09:16  ann数字识别\ConsoleApplication1\ConsoleApplication1\anncpp.cpp

     文件        376  2013-11-07 08:35  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\10_0.792674_gray_14967_5950_step5_recog_4_0_0.890217_0.705652.png

     文件        413  2013-11-10 08:12  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\11_0.971377_gray_20751_8531_step5_recog_4_0_0.996446_0.967925.png

     文件        413  2013-11-09 08:47  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\12_0.953826_gray_975_407_step5_recog_5_0_0.987086_0.941508.png

     文件        376  2013-11-06 07:31  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\13_0.924615_gray_5457_2092_step5_recog_6_0_0.987233_0.912810.png

     文件        413  2013-11-07 10:29  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\14_0.749970_gray_17934_7138_step5_recog_4_0_0.787806_0.590831.png

     文件        398  2013-11-07 01:38  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\15_0.877296_gray_8040_2899_step5_recog_4_0_0.969689_0.850704.png

     文件        390  2013-11-09 16:11  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\16_0.949891_gray_12542_5631_step5_recog_5_0_0.989526_0.939942.png

     文件        413  2013-11-05 23:09  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\17_0.906434_gray_1645_517_step5_recog_3_0_0.985269_0.893081.png

     文件        413  2013-11-04 07:38  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\18_0.494551_gray_4696_2106_step5_recog_5_D_0.340885_0.168585.png

     文件        413  2013-11-10 17:49  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\19_0.968513_gray_35240_14963_step5_recog_4_0_0.994962_0.963633.png

     文件        390  2013-11-05 11:37  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\1_0.822474_gray_13564_5332_step5_recog_2_0_0.891312_0.733081.png

     文件        452  2013-11-07 09:17  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\20_0.737201_gray_16436_6504_step5_recog_3_0_0.828133_0.610500.png

     文件        328  2013-11-09 09:13  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\21_0.750968_gray_1741_702_step5_recog_5_0_0.724394_0.543997.png

     文件        578  2013-11-06 07:23  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\22_0.610848_gray_4813_1822_step5_recog_6_0_0.772820_0.472076.png

     文件        429  2013-11-08 21:58  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\23_0.976079_gray_9338_3994_step5_recog_4_0_0.996512_0.972675.png

     文件        404  2013-11-05 10:21  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\24_0.876098_gray_12240_4810_step5_recog_6_0_0.960593_0.841573.png

     文件        398  2013-11-10 13:17  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\25_0.978677_gray_28271_11796_step5_recog_3_0_0.997614_0.976341.png

     文件        845  2013-11-07 07:07  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\26_0.915550_gray_9737_3597_step5_recog_6_0_0.984816_0.901648.png

     文件        413  2013-11-06 16:41  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\27_0.942230_gray_2943_1159_step5_recog_4_0_0.982740_0.925967.png

     文件        390  2013-11-06 07:09  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\28_0.845480_gray_4035_1484_step5_recog_2_0_0.902136_0.762738.png

     文件        436  2013-11-07 08:11  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\29_0.736003_gray_13772_5440_step5_recog_4_0_0.816986_0.601304.png

     文件        413  2013-11-04 17:45  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\2_0.734930_gray_10773_4652_step5_recog_6_0_0.932386_0.685239.png

     文件        595  2013-11-08 12:21  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\30_0.669019_gray_4754_2801_step5_recog_4_0_0.669949_0.448209.png

     文件        443  2013-11-04 11:41  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\31_0.941303_gray_3574_1589_step5_recog_5_0_0.991813_0.933597.png

     文件        390  2013-11-10 14:35  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\32_0.910823_gray_30504_12844_step5_recog_2_0_0.938536_0.854839.png

     文件        413  2013-11-09 00:43  ann数字识别\ConsoleApplication1\ConsoleApplication1\charSamples\0\33_0.944410_gray_10675_4406_step5_recog_5_0_0.977869_0.923509.png

............此处省略1805个文件信息

评论

共有 条评论