I have several images like the one below where I want to rotate them several times for OCR. 10 degrees each time.
The problem I have now is that I can rotate the images from the center however the black letter is always at a random point in the image. So while I may be able to rotate it by 10 degrees once any more and it usually goes off the image.
How can I rotate the image below from the center of where the letter currently is?
Keep in mind its location is random.
This is the code I'm currently using for rotation
Bitmap rotatedImage = new Bitmap(bmp.Width, bmp.Height);
using (Graphics g = Graphics.FromImage(rotatedImage))
{
// Set the rotation point to the center in the matrix
g.TranslateTransform(bmp.Width / 2, bmp.Height / 2);
// Rotate
g.RotateTransform(angle);
// Restore rotation point in the matrix
g.TranslateTransform(-bmp.Width / 2, -bmp.Height / 2);
// Draw the image on the bitmap
g.DrawImage(bmp, new System.Drawing.Point(0, 0));
}
return rotatedImage;
And this is the code I've created to find the location of the first black pixel of the letter.
float limit = 0.1f;
int x = 0;
int y = 0;
bool done = false;
for (int i = 0; i < bmp.Width; i++)
{
if (done) break;
for (int j = 0; j < bmp.Height; j++)
{
if (done) break;
System.Drawing.Color c = bmp.GetPixel(i, j);
if (c.GetBrightness() < limit)
{
x = i; y = j; done = true;
}
}
}
However when I use that location in the rotation code I just get a blank white image.
Image containing letter