#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[10240];
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[0]==B && DATA[1]==G &&DATA[2]==R)
{
DATA[0]=255;
DATA[1]=255;
DATA[2]=255;
RetHexBinay.Append("1");
}else{
DATA[0]=0;
DATA[1]=0;
DATA[2]=0;
RetHexBinay.Append("0");
}
}
}
return 1;
}
//头文件
#ifndef STURCT_OCR1
#define STURCT_OCR1
typedef struct _OCR
{
char name[256];
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 |