ich dieses Beispiel bin mit: http://www.aforgenet.com/framework/features/blobs_processing.htmlC# AForge.Net Bildverarbeitung auf das Bild Zeichnung
Ich habe versucht, das letzte Beispiel mit und die Ausgabe in einem Bildfeld nach Button-Klick zeigen:
using AForge;
using AForge.Imaging;
using AForge.Imaging.Filters;
using AForge.Math.Geometry;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Image_Processing_testings
{
public partial class Form1 : Form
{
Bitmap image = null;
public Form1()
{
InitializeComponent();
Bitmap bitmap = new Bitmap("C:\\Users\\user\\Desktop\\test.png");
Bitmap gsImage = Grayscale.CommonAlgorithms.BT709.Apply(bitmap);
DifferenceEdgeDetector filter = new DifferenceEdgeDetector();
image = filter.Apply(gsImage);
// process image with blob counter
BlobCounter blobCounter = new BlobCounter();
blobCounter.ProcessImage(image);
Blob[] blobs = blobCounter.GetObjectsInformation();
// create convex hull searching algorithm
GrahamConvexHull hullFinder = new GrahamConvexHull();
// lock image to draw on it
BitmapData data = image.LockBits(
new Rectangle(0, 0, image.Width, image.Height),
ImageLockMode.ReadWrite, image.PixelFormat);
int i = 0;
// process each blob
foreach (Blob blob in blobs)
{
List<IntPoint> leftPoints, rightPoints, edgePoints = new List<IntPoint>();
// get blob's edge points
blobCounter.GetBlobsLeftAndRightEdges(blob,
out leftPoints, out rightPoints);
edgePoints.AddRange(leftPoints);
edgePoints.AddRange(rightPoints);
// blob's convex hull
List<IntPoint> hull = hullFinder.FindHull(edgePoints);
Drawing.Polygon(data, hull, Color.Red);
i++;
}
image.UnlockBits(data);
MessageBox.Show("Found: " + i + " Objects");
}
private void button1_Click_1(object sender, EventArgs e)
{
pictureBox1.Image = image;
}
}
}
Das Ergebnis ist, dass ich das Bild nach dem Filter bekomme, aber ohne ein Polygon darauf.
zählte ich die Anzahl der Blob und bekam 3 für dieses Bild:
Die Beispiele in dem von Ihnen bereitgestellten Link gehen davon aus, dass weiße Pixel zum Objekt gehören und schwarze Pixel zum Hintergrund gehören. Ihr Bild, das Sie angegeben haben, ist das Gegenteil. Daher invertieren Sie das Bild vor der Anwendung des Algorithmus und sehen, ob das funktioniert. – rayryeng
Danke! das hat funktioniert! – Yogevnn
Kein Problem. Macht es Ihnen etwas aus, wenn ich eine Antwort hinzufüge, damit Sie sie aufwerten und akzeptieren können? :) Ich hätte nichts dagegen, den Repräsentanten zu bekommen. – rayryeng