我正在使用Aforge对图像进行边缘检测,如何获得检测到的边缘点的x,y?除了循环显示图像位图的明显方法之外。
这是Aforge样本的代码,但我如何获得边缘点?
// On Filters->Sobel edge detector
private void sobelEdgesFiltersItem_Click( object sender, System.EventArgs e )
{
// save original image
Bitmap originalImage = sourceImage;
// get grayscale image
sourceImage = Grayscale.CommonAlgorithms.RMY.Apply( sourceImage );
// apply edge filter
ApplyFilter( new SobelEdgeDetector( ) );
// delete grayscale image and restore original
sourceImage.Dispose( );
sourceImage = originalImage;
// this is the part where the source image is now edge detected. How to get the x,y for //each point of the edge?
sobelEdgesFiltersItem.Checked = true;
}
答案 0 :(得分:6)
过滤器只是顾名思义:过滤器(图片 - >处理 - > NewImage)
我不知道,如果边缘有类似的东西,但AForge有一个角落探测器。我的样本加载图像,运行角点检测器并在每个角落周围显示小红框。 (你需要一个名为“pictureBox”的PictureBox控件。)
public void DetectCorners()
{
// Load image and create everything you need for drawing
Bitmap image = new Bitmap(@"myimage.jpg");
Graphics graphics = Graphics.FromImage(image);
SolidBrush brush = new SolidBrush(Color.Red);
Pen pen = new Pen(brush);
// Create corner detector and have it process the image
MoravecCornersDetector mcd = new MoravecCornersDetector();
List<IntPoint> corners = mcd.ProcessImage(image);
// Visualization: Draw 3x3 boxes around the corners
foreach (IntPoint corner in corners)
{
graphics.DrawRectangle(pen, corner.X - 1, corner.Y - 1, 3, 3);
}
// Display
pictureBox.Image = image;
}
这可能不是你想要的,但也许它会有所帮助。
答案 1 :(得分:0)
您想要从特定形状检测边缘吗?因为如果是这样,你可以使用BlobCounter并推断出形状的坐标是什么。
//Measures and sorts the spots. Adds them to m_Spots
private void measureSpots(ref Bitmap inImage)
{
//The blobcounter sees white as blob and black as background
BlobCounter bc = new BlobCounter();
bc.FilterBlobs = false;
bc.ObjectsOrder = ObjectsOrder.Area; //Descending order
try
{
bc.ProcessImage(inImage);
Blob[] blobs = bc.GetObjectsInformation();
Spot tempspot;
foreach (Blob b in blobs)
{
//The Blob.CenterOfGravity gives back an Aforge.Point. You can't convert this to
//a System.Drawing.Point, even though they are the same...
//The location(X and Y location) of the rectangle is the upper left corner of the rectangle.
//Now I should convert it to the center of the rectangle which should be the center
//of the dot.
Point point = new Point((int)(b.Rectangle.X + (0.5 * b.Rectangle.Width)), (int)(b.Rectangle.Y + (0.5 * b.Rectangle.Height)));
//A spot (self typed class) has an area, coordinates, circularity and a rectangle that defines its region
tempspot = new Spot(b.Area, point, (float)b.Fullness, b.Rectangle);
m_Spots.Add(tempspot);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
希望这有帮助。
输入后,我看到了问题的日期,但看到我已经输入了所有内容我将发布它。希望这对某人有好处。