你好我正在做一个学校项目,在那里我们有一个机器人在火烈鸟板之间的地面上行驶.我们需要创建一个可以识别这些板块位置的算法,这样我们就可以在它们周围创建路径(我们正在使用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 Listrects = new List (); foreach (Blob blob in blobs) { if (blob.Area > 1000) { rects.Add(blob.Rectangle); } } return rects.ToArray(); } private Rectangle[] filterRectangles(Rectangle[] rects) { List Rectangles = new List (); 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; } }
Matt Warren.. 5
正如@kigurai所说,你需要更多地分析斑点以找到角落.AForge库允许您执行此操作,有关详细信息,请参阅此页面上的查找凸包.下面的截图(来自页面)显示了凸包的小样本.
alt text http://www.aforgenet.com/framework/features/imaging/convex_hulls.png
你想看看GetBlobsLeftAndRightEdges
函数和GrahamConvexHull
类.
正如@kigurai所说,你需要更多地分析斑点以找到角落.AForge库允许您执行此操作,有关详细信息,请参阅此页面上的查找凸包.下面的截图(来自页面)显示了凸包的小样本.
alt text http://www.aforgenet.com/framework/features/imaging/convex_hulls.png
你想看看GetBlobsLeftAndRightEdges
函数和GrahamConvexHull
类.