123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- #include "StdAfx.h"
- #include "OcrLine.h"
- OcrLine::OcrLine(PBYTE pBits,POINT pt,SIZE size):OcrBase(pBits,size)
- {
- m_pt = pt;
- m_MatchCount = m_PixesCount;
- }
- OcrLine::~OcrLine(void)
- {
- }
- void OcrLine::MakeSundayLine()
- {
- DWORD *pColor = (DWORD *)m_pBits;
- map<DWORD,ULONG>::iterator iter;
- for(ULONG i = 0;i < m_PixesCount;i++)
- {
- iter = m_SundayKeyLine.find(pColor[i]);
- if(iter == m_SundayKeyLine.end())
- {
- //not exist and need update
- m_SundayKeyLine[pColor[i]] = i;
- }
- else
- {
- //exist
- if(m_SundayKeyLine[pColor[i]] < i)
- {
- m_SundayKeyLine[pColor[i]] = i;
- }
- }
- }
- }
- void OcrLine::GetLineKey(COLORPOINT &startpt,COLORPOINT &endpt)
- {
- PBYTE pBits = m_pBits;
- startpt.pt = m_pt;
- memcpy((&startpt.color),m_pBits,sizeof(OCRCOLOR));
- pBits += ((m_PixesCount - 1)*sizeof(OCRCOLOR));
- endpt.pt.y = startpt.pt.y;
- endpt.pt.x = startpt.pt.x + m_LimitedSize.cx - 1;
- memcpy((&endpt.color),pBits,sizeof(OCRCOLOR));
- }
- BOOL OcrLine::CheckKeyMatch(OcrScreen &fullPic, POINT &start1, OCRCOLOR color)
- {
- int i = 0;
- ULONG count = 0;
- COLORPOINT temp[2];
- COLORPOINT screen1[2];
- GetLineKey(temp[0],temp[1]);
-
- for(i = 0;i < 2;i++)
- {
- temp[i].pt.x += start1.x;
- temp[i].pt.y += start1.y;
- screen1[i] = temp[i];
- fullPic.GetPointColor(screen1[i]);
- if(CheckTwoColors(temp[i].color,screen1[i].color,color) == TRUE)
- {
- count += 1;
- }
- }
- if(count == 2)
- {
- return TRUE;
- }
- return FALSE;
- }
- ULONG OcrLine::CheckSundayLine(OcrScreen &fullPic, POINT &start1, OCRCOLOR color)
- {
- ULONG i = 0;
- ULONG Offset;
- POINT orgPt;
- COLORPOINT temp;
- COLORPOINT screen1;
- temp.pt = m_pt;
- temp.pt.x += start1.x;
- temp.pt.y += start1.y;
- orgPt = temp.pt;
- for(i = 0;i < m_PixesCount;i++)
- {
- memcpy(&(temp.color),&m_pBits[i*sizeof(OCRCOLOR)],sizeof(OCRCOLOR));
- screen1 = temp;
- fullPic.GetPointColor(screen1);
- if(CheckTwoColors(temp.color,screen1.color,color) == FALSE)
- {
- //step1 :move forward the diff1
- Offset = temp.pt.x - orgPt.x;
- screen1.pt.x += (m_PixesCount - 1);
- fullPic.GetPointColor(screen1);
-
- //step2:
- if(color == 0)
- {
- map<OCRCOLOR,ULONG>::iterator iter = m_SundayKeyLine.find(screen1.color);
- if(iter != m_SundayKeyLine.end())
- {
- //found one
- Offset += (screen1.pt.x - temp.pt.x);
- Offset -= ((iter->second));
- return Offset;
- }
- }
- else
- {
- ULONG bigminus = 0;
- map<OCRCOLOR,ULONG>::iterator iter = m_SundayKeyLine.begin();
- while(iter != m_SundayKeyLine.end())
- {
- if(CheckTwoColors(iter->first,screen1.color,color) == TRUE)
- {
- if(iter->second > bigminus)
- {
- bigminus = iter->second;
- }
- }
- ++iter;
- }
- //found one
- Offset += (screen1.pt.x - temp.pt.x);
- Offset -= bigminus;
- return Offset;
- }
- //not found
- Offset += m_PixesCount;
- return Offset;
- }
- ++temp.pt.x;
- }
- return 0;
- }
- void OcrLine::CheckMatch(OcrScreen &fullPic, POINT &start1, OCRCOLOR color)
- {
- ULONG i = 0;
- COLORPOINT temp;
- COLORPOINT screen1;
- temp.pt = m_pt;
- temp.pt.x += start1.x;
- temp.pt.y += start1.y;
- for(i = 0;i < m_PixesCount;i++)
- {
- memcpy(&(temp.color),&m_pBits[i*sizeof(OCRCOLOR)],sizeof(OCRCOLOR));
- screen1 = temp;
- fullPic.GetPointColor(screen1);
- if(CheckTwoColors(temp.color,screen1.color,color) == FALSE)
- {
- --m_MatchCount;
- }
-
- ++temp.pt.x;
- }
- }
- void OcrLine::ClearRecord()
- {
- m_MatchCount = m_PixesCount;
- }
|