APH Networks | community: Explaining GetPixel Optical Character Recognition - APH Networks | community

Jump to content

Review Instructions

This section of the forums is dedicated to members for reviewing software, hardware or technology related things. Please do not copy and paste reviews from other sites. Also, use good grammar and photos/screenshots if possible and make it very detailed, you never know, your review might be added to APH Reviews! You will also be credited! If you have any questions or concerns, please contact the site administrator.
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Explaining GetPixel Optical Character Recognition

#1 User is offline   Lord Nikon 

  • APH Prestige
  • Group: Members
  • Posts: 516
  • Joined: 01-October 05

Posted 18 March 2006 - 09:19 PM

Well you guys saw my OCR functions in C++ and C# and you might be wondering how it works so bare with me as I explain it as much as I can. Im not making this for begginers so Im not going to explain every little detail :yes:

--------------------------------
The main part of the program is bascially this 'for' loop:
int X = 25;
				int Y = 25;

				Bitmap^ OBJPic = gcnew Bitmap(picCaptcha->Image);
				Color Brightest = System::Drawing::Color::White;
				Color colCur;
				Boolean IsBlack = false;
				for (int curX = 0; curX < OBJPic->Width && IsBlack == false; curX += 4
				{
					for (int curY = 0; curY < OBJPic->Height && IsBlack == false; curY +=  4
					{
						colCur = OBJPic->GetPixel(curX,curY);
						if (colCur.GetBrightness() < Brightest.GetBrightness())
						{
							Brightest = colCur;
							X = curX;
							Y = curY;
							IsBlack = (Brightest == System::Drawing::Color::Black);
						}
					}
				}


--------------------------------
Explanation
1. The first part gets the bitmap of the picturebox and assings it to the Bitmap object called "OBJPic".
2. The second part declares a variable called "colBrightest" and assings the color black to it, I know it's not the brightest color. But it's simply called that because a color can't get any darker than black so as soon the the scanner gets a pixel thats black it'll stop because nothing can get darker than black.
3. If you know much about C++ for loops then you can tell I get 2 for loops to scan every pixel of the picture while the the X and Y coords are in range with the picture's height and width and while the current pixel is not black(although it will stop once it finds a black pixel).
4. Now hard coded inside the for loop we assign current pixel's color to a color variable called colColor. If the brightness of the current color is lower than the brightness of black then black becomes the color of the current color and we assign proper values to the X and Y variables.
5. This step is pretty simple but bascially if current color is black then IsBlack becomes true and the for loops will stop.


--------------------------------

Right well thats pretty much what the function does it is slow but you can make more effecient coding by different means which I will post later.


--------------------------------
After you have aquired the right coords you can use this dBox function to draw a small box arround the found pixel.:
void dBox(int X, int Y)
			 {
				 if (X != 0 && Y != 0)
				 {
					Bitmap^ OBJBox = gcnew Bitmap(picCaptcha->Image);
					OBJBox->SetPixel(X - 2, Y + 2, System::Drawing::Color::Black);
					OBJBox->SetPixel(X - 1, Y + 2, System::Drawing::Color::Black);
					OBJBox->SetPixel(X, Y + 2, System::Drawing::Color::Black);
					OBJBox->SetPixel(X + 1, Y + 2, System::Drawing::Color::Black);
					OBJBox->SetPixel(X + 2, Y + 2, System::Drawing::Color::Black);
					OBJBox->SetPixel(X + 2, Y + 1, System::Drawing::Color::Black);
					OBJBox->SetPixel(X + 2, Y, System::Drawing::Color::Black);
					OBJBox->SetPixel(X + 2, Y - 1, System::Drawing::Color::Black);
					OBJBox->SetPixel(X + 2, Y - 2, System::Drawing::Color::Black);
					OBJBox->SetPixel(X + 1, Y - 2, System::Drawing::Color::Black);
					OBJBox->SetPixel(X, Y - 2, System::Drawing::Color::Black);
					OBJBox->SetPixel(X - 1, Y - 2, System::Drawing::Color::Black);
					OBJBox->SetPixel(X - 2, Y - 2, System::Drawing::Color::Black);
					OBJBox->SetPixel(X - 2, Y - 1, System::Drawing::Color::Black);
					OBJBox->SetPixel(X - 2, Y, System::Drawing::Color::Black);
					OBJBox->SetPixel(X - 2, Y + 1, System::Drawing::Color::Black);
					picCaptcha->Image= gcnew Bitmap(OBJBox);
				}
				 else { MessageBox::Show("The fed X or Y coordinate(s) are out of range"); }
			 }


--------------------------------

Note: Both for loops step by 4 so that means that every 4 pixels will be scanned. If there are 24 pixels in one line and the X Step is 4 then out of the 24 pixels only 6 pixels will be scanned. This causes the program to be less accurate but much faster because it scans less pixels. You can always make it more accurate by stepping by 1 instead.

Well thats it I hope you learned a thing or two.
Questions or comments?

This post has been edited by Lord Nikon: 18 March 2006 - 09:20 PM

Posted Image
APH Authorization ActiveX Control:Complete[Uses only Winsock]
0

#2 User is offline   chconline 

  • Editor-in-Chief
  • Group: Executive Staff Team
  • Posts: 26,184
  • Joined: 22-October 04
  • Gender:Male
  • Location:Calgary, Alberta

Posted 18 March 2006 - 09:29 PM

Thats pretty sharp... although I dont understand like half the thngs. lol

Published next week.
Posted Image

#3 User is offline   Lord Nikon 

  • APH Prestige
  • Group: Members
  • Posts: 516
  • Joined: 01-October 05

Posted 18 March 2006 - 09:35 PM

View Postchconline, on Mar 18 2006, 08:29 PM, said:

Thats pretty sharp... although I dont understand like half the thngs. lol

Published next week.

Well like I said you have to know C++ before you can try to understand this :yes:
Posted Image
APH Authorization ActiveX Control:Complete[Uses only Winsock]
0

#4 User is offline   Mythbusters 

  • Newbie
  • Group: Members
  • Posts: 3
  • Joined: 14-June 08

Posted 14 June 2008 - 09:56 AM

Could you explain it in Vb6? (a)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic