像素坐标批准的C#算法 [英] pixel coordinates approved algorithms in C #

查看:86
本文介绍了像素坐标批准的C#算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我稍微描述了这个问题,以帮助人们形象地展现自己.

放入图片中,图片中包含字母,白色背景,黑色文字.
执行图像浏览器以查找字符BMP文件的左,右,上,下边缘.
基本的问题,我做到了,但是有一些问题:

问题1:快速浏览照片.
我可以发现并看到锁位描述的两个get-set像素和lockbit ..将比get-set浏览得更快.
进行设置,我使它起作用,但是锁位不起作用.

谁能解决这个问题对我没有帮助.

问题2:图片格式
正如我上面所说,仅在BMP上以JPG格式完成,浏览器的春季术语却大不相同.

因此,如何转换BMP的其他格式却不是.

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.

推荐答案

以下是文章中的代码:Unicode光学字符识别
Unicode光学字符识别[^] [
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;
}


但是现在,我想将此代码get-set更改为lockbit,因为我认为它将更快.如果有人有更好的解决方案,请告诉我.


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.


您需要使用不安全"并创建指向像素的指针.只要您知道步幅,宽度和像素大小(您的情况是4个字节),您只需在指针上添加那么多就可以到达该位置(步幅告诉您Y环绕宽度告诉您x位置与像素大小相结合).

因此,您可能会遇到以下情况:


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:


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.


在C#中使用位图时,您一定应该阅读Christian Graus的系列文章. CodeProject.他们描述了如何快速访问单个像素以及许多其他图像处理技术.看到这里:
使用C#和GDI +的傻瓜图像处理-第1部分-每个像素过滤器 [使用C#和GDI +进行虚拟的傻瓜图像处理-第2部分-卷积过滤器 [使用C#和GDI +的傻瓜图像处理第3部分-边缘检测过滤器 [使用C#和GDI +进行虚拟的傻瓜图像处理-第4部分-双线性过滤器和调整大小 [ ^ ]
使用C#和GDI +的傻瓜图像处理第5部分-包括漩涡在内的位移过滤器 [ ^ ]
使用C#和GDI +的傻瓜图像处理-第6部分-HSL颜色空间 [ ^ ]
When working with bitmaps in C#, you should definitely read Christian Graus'' series of articles here on CodeProject. They describe how to access single pixels in a fast way and a lot of other image manipulation technologies. See here:
Image Processing for Dummies with C# and GDI+ Part 1 - Per Pixel Filters[^]
Image Processing for Dummies with C# and GDI+ Part 2 - Convolution Filters[^]
Image Processing for Dummies with C# and GDI+ Part 3 - Edge Detection Filters[^]
Image Processing for Dummies with C# and GDI+ Part 4 - Bilinear Filters and Resizing[^]
Image Processing for Dummies with C# and GDI+ Part 5 - Displacement filters, including swirl[^]
Image Processing for Dummies with C# and GDI+ Part 6 - The HSL color space[^]


这篇关于像素坐标批准的C#算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆