如何在检测图像中的形状时使用AForge.net解决c#中的以下错误:“错误2参数'2':无法从'AForge.IntPoint []'转换为'System.Drawing.PointF []'标记为whr胆大 [英] how to solve the following error in c# using AForge.net while detecting shapes in an image : "Error 2 Argument '2': cannot convert from 'AForge.IntPoint[]' to 'System.Drawing.PointF[]' whr marked bold

查看:271
本文介绍了如何在检测图像中的形状时使用AForge.net解决c#中的以下错误:“错误2参数'2':无法从'AForge.IntPoint []'转换为'System.Drawing.PointF []'标记为whr胆大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

位图图像=(位图)pictureBox4.Image;

//创建blob计数器实例

BlobCounter blobCounter = new BlobCounter();

blobCounter.FilterBlobs = true;

blobCounter.MinHeight = 5;

blobCounter.MinWidth = 5;

//处理扩张的图像

blobCounter.ProcessImage(image);

//获取有关检测到的对象的信息

Blob [] blobs = blobCounter.GetObjectsInformation(); < br $>


//创建一个图形对象来绘制图像和一支笔

图形g = Graphics.FromImage(图像);

Pen Redpen =新笔(Color.Red,2);



SimpleShapeChecker shapechecker = new SimpleShapeChecker();



//签入图片并在找到矩形的对象周围绘制

for(int i = 0,n = blobs.Length; i< n; i ++)>

{

List< intpoint> edgepoints = blobCounter.GetBlobsEdgePoints(blobs [i]);

List< intpoint>角点;

if(shapechecker.IsQuadrilateral(edgepoints,out cornerpoints))

{

if(shapechecker.CheckPolygonSubType(cornerpoints)== PolygonSubType .Rectangle)

{

g.DrawPolygon(Redpen, cornerpoints.ToArray());

} < br $> b $ b

}

}

Redpen.Dispose();

g.Dispose ();

Bitmap image = (Bitmap)pictureBox4.Image;
// create instance of blob counter
BlobCounter blobCounter = new BlobCounter();
blobCounter.FilterBlobs = true;
blobCounter.MinHeight = 5;
blobCounter.MinWidth = 5;
//process the dilated image
blobCounter.ProcessImage(image);
// get info about detected objects
Blob[] blobs = blobCounter.GetObjectsInformation();

// create a graphics object to draw on the image and a pen
Graphics g = Graphics.FromImage(image );
Pen Redpen = new Pen(Color.Red, 2);

SimpleShapeChecker shapechecker= new SimpleShapeChecker ();

//check in image and draw around the object found as rectangle
for(int i=0,n=blobs.Length ;i<n;i++)>
{
List<intpoint> edgepoints = blobCounter.GetBlobsEdgePoints(blobs [i ]);
List <intpoint> cornerpoints;
if (shapechecker.IsQuadrilateral(edgepoints, out cornerpoints ))
{
if (shapechecker.CheckPolygonSubType (cornerpoints ) == PolygonSubType.Rectangle)
{
g.DrawPolygon (Redpen, cornerpoints.ToArray ());
}

}
}
Redpen.Dispose();
g.Dispose();

推荐答案

尝试如下,使用 System.Drawing.Point

try as below, use System.Drawing.Point
for(int i=0,n=blobs.Length ;i<n;i++)>
{
	List<intpoint> edgepoints = blobCounter.GetBlobsEdgePoints(blobs [i ]);
	List<intpoint> cornerpoints;
	if (shapechecker.IsQuadrilateral(edgepoints, out cornerpoints ))
	{
		if (shapechecker.CheckPolygonSubType (cornerpoints ) == PolygonSubType.Rectangle)
		{
			g.DrawPolygon (Redpen, cornerpoints.Select(p => new System.Drawing.Point(p.X, p.Y)).ToArray());
		}
	}
}


我已经尝试了谷歌上提供的所有可能的解决方案...就像我们的linq .. .which工作,然后关于要添加的代码,如从system.point转换为aforge,ad还有一件事我没有得到ToPointsArray方法......因为它不存在....我是错过了任何图书馆或参考资料....请帮助......我确定这是我错过的一件小事。很抱歉有问题,但我是新手使用Aforge.Net。
I have tried all possible solutions available on google...like usin linq...which dint work , then about the code to be added like for conversion from system.point to aforge, ad one more thing i do not get the ToPointsArray method as well ...as in it does not exist ....am I missing out on any library or reference....please help....I'm sure its a small thing I'm missing out on. Sorry for the trouble but I'm new to using Aforge.Net .


这篇关于如何在检测图像中的形状时使用AForge.net解决c#中的以下错误:“错误2参数'2':无法从'AForge.IntPoint []'转换为'System.Drawing.PointF []'标记为whr胆大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆