gpt4 book ai didi

c# - 识别图像中的对象

转载 作者:太空狗 更新时间:2023-10-29 19:40:11 25 4
gpt4 key购买 nike

<分区>

你好,我正在做一个学校项目,我们有一个机器人在火烈鸟板 block 之间的地面上行驶。我们需要创建一种算法来识别这些板 block 的位置,这样我们就可以在它们周围创建路径(为此我们使用了 A Star)。

到目前为止,我们已经使用 AForged Library 并创建了以下类,唯一的问题是当它创建矩形时,它没有考虑到板并不总是与相机边框平行,并且在那种情况下,它只会创建一个覆盖整个盘子的矩形。所以我们需要通过某种方式找到对象的旋转,或者通过其他方式来识别它。我创建了一个可能有助于解释这一点的图像

图像描述问题:http://img683.imageshack.us/img683/9835/imagerectangle.png

如能提供任何帮助,我将不胜感激。

随时欢迎任何其他信息或想法。

public class PasteMap
{
private Bitmap image;
private Bitmap processedImage;
private Rectangle[] rectangels;

public void initialize(Bitmap image)
{
this.image = image;
}

public void process()
{
processedImage = image;
processedImage = applyFilters(processedImage);
processedImage = filterWhite(processedImage);
rectangels = extractRectangles(processedImage);
//rectangels = filterRectangles(rectangels);
processedImage = drawRectangelsToImage(processedImage, rectangels);
}

public Bitmap getProcessedImage
{
get
{
return processedImage;
}
}

public Rectangle[] getRectangles
{
get
{
return rectangels;
}
}

private Bitmap applyFilters(Bitmap image)
{
image = new ContrastCorrection(2).Apply(image);
image = new GaussianBlur(10, 10).Apply(image);
return image;
}

private Bitmap filterWhite(Bitmap image)
{
Bitmap test = new Bitmap(image.Width, image.Height);

for (int width = 0; width < image.Width; width++)
{
for (int height = 0; height < image.Height; height++)
{
if (image.GetPixel(width, height).R > 200 &&
image.GetPixel(width, height).G > 200 &&
image.GetPixel(width, height).B > 200)
{
test.SetPixel(width, height, Color.White);
}
else
test.SetPixel(width, height, Color.Black);
}
}
return test;
}

private Rectangle[] extractRectangles(Bitmap image)
{
BlobCounter bc = new BlobCounter();
bc.FilterBlobs = true;
bc.MinWidth = 5;
bc.MinHeight = 5;
// process binary image
bc.ProcessImage( image );
Blob[] blobs = bc.GetObjects(image, false);
// process blobs
List<Rectangle> rects = new List<Rectangle>();
foreach (Blob blob in blobs)
{
if (blob.Area > 1000)
{
rects.Add(blob.Rectangle);
}
}

return rects.ToArray();
}

private Rectangle[] filterRectangles(Rectangle[] rects)
{
List<Rectangle> Rectangles = new List<Rectangle>();
foreach (Rectangle rect in rects)
{
if (rect.Width > 75 && rect.Height > 75)
Rectangles.Add(rect);
}

return Rectangles.ToArray();
}

private Bitmap drawRectangelsToImage(Bitmap image, Rectangle[] rects)
{
BitmapData data = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
foreach (Rectangle rect in rects)
Drawing.FillRectangle(data, rect, Color.Red);
image.UnlockBits(data);
return image;
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com