如何从图像中获取最大的对象并找到裁剪图像的中心像素 [英] How get biggest object from the image and find center pixel of Cropped image

查看:147
本文介绍了如何从图像中获取最大的对象并找到裁剪图像的中心像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从图像中裁剪出最大的对象并找到裁剪图像的中心像素
我使用AForge库(opencv)使用BlobCounter函数完成了此操作,但无法正常运行

http://img24.imageshack.us/img24/4666/cropimageh.jpg [ ^ ]

下面有代码

How Crop biggest object from the image and find center pixel of Cropped image
I did it using BlobCounter function using AForge library (opencv ) but not working

http://img24.imageshack.us/img24/4666/cropimageh.jpg[^]

below has code

   System.Drawing.Bitmap aq = (Bitmap)pictureBox1.Image;
   Invert a = new Invert();
    aq = a.Apply(aq);
    AForge.Imaging.Image.FormatImage(ref aq);

    /// apply grayscale
    IFilter filter = Grayscale.CommonAlgorithms.BT709;
    aq = filter.Apply(aq);

    Threshold th = new Threshold(220);
    aq = th.Apply(aq);

    ///find the biggest object
    BlobCounter bl = new BlobCounter(aq);
    int i = bl.ObjectsCount;
    ExtractBiggestBlob fil2 = new ExtractBiggestBlob();

    int x = 0;
    int y = 0;
    int h = 0;
    if (i > 0)
    {
        fil2.Apply(aq);
        x = fil2.BlobPosition.X;
        y = fil2.BlobPosition.Y;

        h = fil2.Apply(aq).Height;
    }

    System.Drawing.Bitmap Bitmapsource = (Bitmap)pictureBox1.Image;
    Rectangle section = new Rectangle(new Point(x - h, y - h), new Size(1 * h, 1 * h));

    Bitmap CroppedImage = CropImage(Bitmapsource, section);
    pictureBox2.Image = CroppedImage;
}
    //get crap image


    public Bitmap CropImage(Bitmap source, Rectangle section)  {
    Bitmap bmp = new Bitmap(section.Width, section.Height);
    Graphics g = Graphics.FromImage(bmp);
    g.DrawImage(source, 0, 0, section, GraphicsUnit.Pixel);
    return bmp;}
}



我想做的事..
从原始图像中获取图像并获取中心像素

http://img829.imageshack.us/img829/5199/centerpicel.jpg [ ^ ]



this the thing i want to do..
crap image from original and get center pixel

http://img829.imageshack.us/img829/5199/centerpicel.jpg[^]

推荐答案

我没有AForge方面的经验,但是总体上没有图像处理方面的经验.
-首先,我不确定转换为灰度是否是个好主意.您可能会丢失大量信息.
-尝试逐步构建和测试您的应用.在 aforge文档 [
I have no experience in AForge, but in image processing in general.
- first of all, I am not sure that converting to grayscale is a good idea. You might loos significant information.
- try to build and test your app step by step. In the aforge documentation[^] the sample contains only two statements: create the extractor filter and apply it to the image. The result will be the bigest object. Save it, or show it in your test app, to see if it works.
- did you intentionally re-apply the filter (h = fil2.Apply(aq).Height;)? Better save it on the first apply.
- are you sure that the height of the result is equal to it''s width?
- by the way, what is the center pixel of an object?


如何获得最大的物体?嗯,一个可视对象的范围可以从简单到复杂,我敢打赌,代码应在其设计的上下文中使用,例如,不要指望代码能找到人脸的中心像素. :)

尝试使用简单的图像,更像是合成图像,而不是像网络摄像头或数码相机那样的嘈杂图像.我遇到的大多数当前计算机视觉算法都容易产生噪音,因此更适合于所谓的玩具问题".

如果您需要使用真实世界的图像,则您的应用程序需要做更多的预处理以提取相关功能,并且在更复杂的情况下,需要将一些有关可能的或预定义的对象的知识用作原型.
How to get the biggest object? Mmmmm,a visual object can range from simple to complex, I bet that code should be used in the context in which it was designed, don''t expect that code to find the center pixel of a face, for example. :)

Try using simple images, more like synthesized images unlike noisy images such as the leaf from web cameras or digital cameras. Most of the current computer vision algorithms I have come across are prone to noise and hence are more suited to what are known as "toy problems".

If you need to use real world imagery then your app need to do a lot more of preprocessing to extract relevant features and some knowledge about possible or predefined objects need to be used as prototypes in more complex situations.


嗨!我对OpenCV有一点经验,并且已经开发了许多测试应用程序.由于这只是测试,所以我没有深入研究该问题,但是顺便说一句,我的态度更轻松.
首先使用轮廓并使用Canny边缘检测算法创建边缘图像.然后遍历所有轮廓并将矩形或更好的2DBox存储在变量cvBox2D(结构)的数组中.现在比较矩形的大小,您可以检查height和width是否更大,或者比较height width和Area,以便您有更多参数来最终确定哪一个是最大轮廓.将该轮廓存储在另一个轮廓变量中.
现在要找到中心像素,请使用简单的近似方法.只需使用相同的2D框变量,结构内部就会建立一个名为"center"的参数.
希望它会在某些方面对您有所帮助.
谢谢.
Hi! I have a little experience with OpenCV and I have developed many test applications. Since it were only test I didn''t delve deep in that matter, but by the way I have an easier soution.
First of all use the contours and create an edged image using canny edge detection algorithm. Then loop through all the contours and store a rectangle or better 2DBox in an array of variable cvBox2D (struct). Now compare the size of rectangle, you can check if height AND width are greater or compare the height width and Area so that you have more parameter to finally decide which one is biggest contour. Store this contour in another contour variable.
Now to find the center pixel, Use a simple approximate method. Just use the same 2D box variable, there''s a parameter called ''center'' built inside the struct.
Hope it will help you in some ways.
Thank you.


这篇关于如何从图像中获取最大的对象并找到裁剪图像的中心像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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