我在Android平板电脑上使用AForge.portable来创建一种方法,将一张纸的图片转换为可能作为扫描图像传递的内容。我的代码如下:
public static Bitmap ConvertToScan(Bitmap img)
{
BlobCounterBase bc = new BlobCounter();
bc.ObjectsOrder = ObjectsOrder.Area;
var bm = ((System.Drawing.Bitmap)img).Clone(System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);
var grayImage = filter.Apply(bm);
SobelEdgeDetector sobelfilter = new SobelEdgeDetector();
sobelfilter.ApplyInPlace(grayImage);
bc.ProcessImage(grayImage);
Blob[] blobs = bc.GetObjectsInformation();
//I Assume the first/largest blob is what I want.
List<IntPoint> edgePoints = bc.GetBlobsEdgePoints(blobs[0]);
List<IntPoint> corners = PointsCloud.FindQuadrilateralCorners(edgePoints);
QuadrilateralTransformation qfilter = new QuadrilateralTransformation(corners, img.Width, img.Height);
Bitmap newImage = (Bitmap)qfilter.Apply((System.Drawing.Bitmap)img);
return newImage;
}
如果我在通过SobelEdgeDetector后显示grayImage,我会得到一张纸张边界的亮点。我在想通过BlobCounter传递这个图像会给我一个最大blob的edgePoints,它应该是纸上的。会发生的是,它只会产生一个blob作为整个图像。我怀疑由于论文只是一个大纲而不是一个实体,BlobCounter并没有选择它。有谁知道如何使用Aforge来检测图像中最大物体轮廓的角落?