ocean 发表于 2014-3-3 16:34:43

点阵字库提取与字符串识别

#include "stdafx.h"
#include "MyOcr.h"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include "HextoBinary.h"
#include "GobalStruct.h"
#include <atlfile.h>
MyOcr::MyOcr()
{
        HexText.Empty();
        BinText.Empty();
        this->pExocr=new OCREx;
        memset(this->pExocr,0,sizeof(OCREx)*10240);


}
/************************************************************************/
/* 把指定图像的颜色二值化,并返回2进制字符串                               */
/************************************************************************/
bool MyOcr::ToDIC1_Iplimage(IplImage* mat,byte R,byte G,byte B,CAtlString& RetHexBinay)
{
        //cols行Rows列
        //计算图像一行需要被赋值的个数
        //int rowLength = mat->cols*mat->channels();
       int MaxW, MaxH;
       MaxW=mat->width;
       MaxH=mat->height;
       RetHexBinay.Empty();
       for (int y=0;y<MaxH;y++)
       {
               byte* DATA=(byte*)((DWORD)mat->imageData+mat->widthStep*y);
               for(int x=0;x<MaxW;x++)
               {
                       if (DATA==B &&DATA==G&&DATA==R)
                       {
                               DATA=255;
                               DATA=255;
                               DATA=255;
                               RetHexBinay.Append("1");
                       }else{
                                       
                               DATA=0;
                               DATA=0;
                               DATA=0;
                               RetHexBinay.Append("0");

                       
                       }
               }
       }

return 1;
}


//头文件
#ifndef STURCT_OCR1
#define STURCT_OCR1






typedef struct _OCR
{

        char name;
        bool HasData;
        int x;
        int y;
        int findMcout;
        int MinX;
        int MinY;
        int MaxX;
        int MaxY;

}OCR,*POCR;




typedef struct _OCREx
{
OCR* pocr;
int OcrNumber;

}OCREx;

///////////////////////字典工具里的变量///////////////////////////////////////////////////

#endif

matson 发表于 2014-3-3 17:59:29

典型的windows MFC程序,多年没玩过了。。

ocean 发表于 2014-3-4 00:12:01

语言具有相通性
页: [1]
查看完整版本: 点阵字库提取与字符串识别