Detección de borde de AFORGE.NET - ¿Cómo obtener los puntos de borde?
-
28-10-2019 - |
Pregunta
Estoy usando AFORGE para ejecutar la detección de borde en una imagen, ¿cómo obtendría la X, Y para los puntos detectados? Aparte de la forma obvia de recorrer los mapas de bits de la imagen.
Este es el código de las muestras de Aforge, pero ¿cómo puedo obtener los puntos de borde?
// 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;
}
Solución
Los filtros son simplemente lo que sugiere: Filtros (Imagen -> Proceso -> NewImage)
No sé, si hay algo similar para los bordes, pero Aforge tiene un detector de esquina. Mi muestra carga una imagen, ejecuta el detector de esquina y muestra pequeñas cajas rojas en cada esquina. (Necesitará un control de cuadro de imagen llamado "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;
}
Puede que no sea exactamente lo que estás buscando, pero tal vez ayude.
Otros consejos
¿Son los bordes que desea detectar desde cierta forma? Porque si es así, puedes usar un blobcounter y razonar cuáles son las coordenadas de la forma.
//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);
}
}
Ojalá esto ayude.
Después de escribir esto, vi la fecha de las preguntas, pero ya que ya he escrito todo lo que solo lo publicaré. Ojalá sea bien a alguien.