OcrLine.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #include "StdAfx.h"
  2. #include "OcrLine.h"
  3. OcrLine::OcrLine(PBYTE pBits,POINT pt,SIZE size):OcrBase(pBits,size)
  4. {
  5. m_pt = pt;
  6. m_MatchCount = m_PixesCount;
  7. }
  8. OcrLine::~OcrLine(void)
  9. {
  10. }
  11. void OcrLine::MakeSundayLine()
  12. {
  13. DWORD *pColor = (DWORD *)m_pBits;
  14. map<DWORD,ULONG>::iterator iter;
  15. for(ULONG i = 0;i < m_PixesCount;i++)
  16. {
  17. iter = m_SundayKeyLine.find(pColor[i]);
  18. if(iter == m_SundayKeyLine.end())
  19. {
  20. //not exist and need update
  21. m_SundayKeyLine[pColor[i]] = i;
  22. }
  23. else
  24. {
  25. //exist
  26. if(m_SundayKeyLine[pColor[i]] < i)
  27. {
  28. m_SundayKeyLine[pColor[i]] = i;
  29. }
  30. }
  31. }
  32. }
  33. void OcrLine::GetLineKey(COLORPOINT &startpt,COLORPOINT &endpt)
  34. {
  35. PBYTE pBits = m_pBits;
  36. startpt.pt = m_pt;
  37. memcpy((&startpt.color),m_pBits,sizeof(OCRCOLOR));
  38. pBits += ((m_PixesCount - 1)*sizeof(OCRCOLOR));
  39. endpt.pt.y = startpt.pt.y;
  40. endpt.pt.x = startpt.pt.x + m_LimitedSize.cx - 1;
  41. memcpy((&endpt.color),pBits,sizeof(OCRCOLOR));
  42. }
  43. BOOL OcrLine::CheckKeyMatch(OcrScreen &fullPic, POINT &start1, OCRCOLOR color)
  44. {
  45. int i = 0;
  46. ULONG count = 0;
  47. COLORPOINT temp[2];
  48. COLORPOINT screen1[2];
  49. GetLineKey(temp[0],temp[1]);
  50. for(i = 0;i < 2;i++)
  51. {
  52. temp[i].pt.x += start1.x;
  53. temp[i].pt.y += start1.y;
  54. screen1[i] = temp[i];
  55. fullPic.GetPointColor(screen1[i]);
  56. if(CheckTwoColors(temp[i].color,screen1[i].color,color) == TRUE)
  57. {
  58. count += 1;
  59. }
  60. }
  61. if(count == 2)
  62. {
  63. return TRUE;
  64. }
  65. return FALSE;
  66. }
  67. ULONG OcrLine::CheckSundayLine(OcrScreen &fullPic, POINT &start1, OCRCOLOR color)
  68. {
  69. ULONG i = 0;
  70. ULONG Offset;
  71. POINT orgPt;
  72. COLORPOINT temp;
  73. COLORPOINT screen1;
  74. temp.pt = m_pt;
  75. temp.pt.x += start1.x;
  76. temp.pt.y += start1.y;
  77. orgPt = temp.pt;
  78. for(i = 0;i < m_PixesCount;i++)
  79. {
  80. memcpy(&(temp.color),&m_pBits[i*sizeof(OCRCOLOR)],sizeof(OCRCOLOR));
  81. screen1 = temp;
  82. fullPic.GetPointColor(screen1);
  83. if(CheckTwoColors(temp.color,screen1.color,color) == FALSE)
  84. {
  85. //step1 :move forward the diff1
  86. Offset = temp.pt.x - orgPt.x;
  87. screen1.pt.x += (m_PixesCount - 1);
  88. fullPic.GetPointColor(screen1);
  89. //step2:
  90. if(color == 0)
  91. {
  92. map<OCRCOLOR,ULONG>::iterator iter = m_SundayKeyLine.find(screen1.color);
  93. if(iter != m_SundayKeyLine.end())
  94. {
  95. //found one
  96. Offset += (screen1.pt.x - temp.pt.x);
  97. Offset -= ((iter->second));
  98. return Offset;
  99. }
  100. }
  101. else
  102. {
  103. ULONG bigminus = 0;
  104. map<OCRCOLOR,ULONG>::iterator iter = m_SundayKeyLine.begin();
  105. while(iter != m_SundayKeyLine.end())
  106. {
  107. if(CheckTwoColors(iter->first,screen1.color,color) == TRUE)
  108. {
  109. if(iter->second > bigminus)
  110. {
  111. bigminus = iter->second;
  112. }
  113. }
  114. ++iter;
  115. }
  116. //found one
  117. Offset += (screen1.pt.x - temp.pt.x);
  118. Offset -= bigminus;
  119. return Offset;
  120. }
  121. //not found
  122. Offset += m_PixesCount;
  123. return Offset;
  124. }
  125. ++temp.pt.x;
  126. }
  127. return 0;
  128. }
  129. void OcrLine::CheckMatch(OcrScreen &fullPic, POINT &start1, OCRCOLOR color)
  130. {
  131. ULONG i = 0;
  132. COLORPOINT temp;
  133. COLORPOINT screen1;
  134. temp.pt = m_pt;
  135. temp.pt.x += start1.x;
  136. temp.pt.y += start1.y;
  137. for(i = 0;i < m_PixesCount;i++)
  138. {
  139. memcpy(&(temp.color),&m_pBits[i*sizeof(OCRCOLOR)],sizeof(OCRCOLOR));
  140. screen1 = temp;
  141. fullPic.GetPointColor(screen1);
  142. if(CheckTwoColors(temp.color,screen1.color,color) == FALSE)
  143. {
  144. --m_MatchCount;
  145. }
  146. ++temp.pt.x;
  147. }
  148. }
  149. void OcrLine::ClearRecord()
  150. {
  151. m_MatchCount = m_PixesCount;
  152. }