C # image processing - smart solution?

I have an image with letters in it, the letters of two colors are black and blue, I want to read the blue colored letters from the image.

Can someone suggest me a way to do this in C #. I am studying GDI +, but still have not received any logic for developing this program.

I tried OCRing, but the problem with generic OCRs is that they do not recognize color differences.

I only want to read the blue characters ....

Any guidance is much appreciated.

+4
source share
3 answers

Try this;) But this unsafe code.

void RedAndBlue() { OpenFileDialog ofd; int imageHeight, imageWidth; if (ofd.ShowDialog() == DialogResult.OK) { Image tmp = Image.FromFile(ofd.FileName); imageHeight = tmp.Height; imageWidth = tmp.Width; } else { // error } int[,] bluePixelArray = new int[imageWidth, imageHeight]; int[,] redPixelArray = new int[imageWidth, imageHeight]; Rectangle rect = new Rectangle(0, 0, tmp.Width, tmp.Height); Bitmap temp = new Bitmap(tmp); BitmapData bmpData = temp.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); int remain = bmpData.Stride - bmpData.Width * 3; unsafe { byte* ptr = (byte*)bmpData.Scan0; for (int j = 0; j < bmpData.Height; j++) { for (int i = 0; i < bmpData.Width; i++) { bluePixelArray[i, j] = ptr[0]; redPixelArray[i, j] = ptr[2]; ptr += 3; } ptr += remain; } } temp.UnlockBits(bmpData); temp.Dispose(); } 
+9
source

Change the image color to gray, then use OCR

 public Bitmap MakeGrayscale(Bitmap original) { //make an empty bitmap the same size as original Bitmap newBitmap = new Bitmap(original.Width, original.Height); for (int i = 0; i < original.Width; i++) { for (int j = 0; j < original.Height; j++) { //get the pixel from the original image Color originalColor = original.GetPixel(i, j); //create the grayscale version of the pixel int grayScale = (int)((originalColor.R * .3) + (originalColor.G * .59) + (originalColor.B * .11)); //create the color object Color newColor = Color.FromArgb(grayScale, grayScale, grayScale); //set the new image pixel to the grayscale version newBitmap.SetPixel(i, j, newColor); } } return newBitmap; } 
+1
source

Perhaps you could change the palette so that it only had a black and white image

0
source

All Articles