Click here to Skip to main content
15,884,974 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
See more:
I described the problem a little to help people visualize yourselves.

Put in a picture, the picture has the letters, white background, black text.
Perform image browser to find edge left, right, top, bottom of character BMP files.
The fundamental problem, I do that's alright, but there are some problems:

Problem 1: Speed ​​browse photos.
I can find out and see how the two get-set pixel and lockbit .. is described by the lockbit will browse faster than get-set.
get-set, I make it work, but lockbits is not work.

Who has the solution to this problem does not help me.

Problem 2: the image format
As I said above is only done on the BMP as JPG format,spring term for the browser it is very different.

So, how can convert other formats of BMP is not.
Posted
Updated 23-Mar-11 0:22am
v5
Comments
Albin Abel 19-Mar-11 13:39pm    
Would you mind showing your lock bit coding. If we give a generalized answer it may not help to solve your problem.

Here is a code in the article: Unicode Optical Character Recognition
Unicode Optical Character Recognition[^][^]
According author, I have done and detected the top and bottom
1. Image line Identification
public void identify_lines()
{
    int y=image_start_pixel_y;
    int x=image_start_pixel_x;
    bool no_black_pixel;
    int line_number=0;
    line_present=true;
    while(line_present)
    {
        x=image_start_pixel_x;
        while(Convert.ToString (input_image.GetPixel (x,y))==
            "Color [A=255, R=255, G=255, B=255]")
        {
            x++;
            if(x==input_image_width)
            {
                x=image_start_pixel_x;
                y++;
            }
            if(y>=input_image_height)
            {
                line_present=false;
                break;
            }
        }
        if(line_present)
        {
            line_top[line_number]=y;
            no_black_pixel=false;
            while(no_black_pixel==false)
            {
                y++;
                no_black_pixel=true;
                for(x=image_start_pixel_x;x<input_image_width;x++)
                    if((Convert.ToString (input_image.GetPixel (x,y))==
                        "Color [A=255, R=0, G=0, B=0]"))
                no_black_pixel=false;
            }
            line_bottom[line_number]=y-1;
            line_number++;
        }
    }
    number_of_lines=line_number;
}

But now,I want to change this code get-set to lockbit because I think it will be it will be faster. If anyone has any better solutions, please tell me.
 
Share this answer
 
Comments
nctit09 21-Mar-11 0:26am    
help me...hic..:(
Dalek Dave 22-Mar-11 10:00am    
Adding code always helps!
You need to use "unsafe" and create an pointer to the pixel. So long as you know the stride, width, and pixel size(your case is 4 bytes) you just add that much to the pointer to get to the location (stride tells you Y wrapping width tells you x location combined with pixel size).

So you could have something like:


C#
unsafe
{
   byte* bPtr;
   for (int y = 0; y < imageData.Length; y++)
   {
      ptr = imageData[y];
      bPtr = (byte*)ptr.ToPointer();
      for (int x = xMin; x <= imageWidth; x+= PixelSize)
      {
          //Do stuff with the pixel bPtr[y * stride + x]
       }
    }
}



Not sure if this is exactly right.. but something along these lines is what you need.
 
Share this answer
 
v3
 
Share this answer
 
Comments
Dalek Dave 22-Mar-11 10:01am    
Good links
nctit09 23-Mar-11 6:03am    
Thank you
Espen Harlinn 24-Mar-11 3:45am    
Definitely worth reading, my 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900