一、前言
C#之Winform + Halcon实现图像直线查找功能
1、创建计量模型 HMetrologyModel
2、添加计量对象到线测量
3、设置计量对象参数
4、设置查找参数:边缘阈值、边缘选择、过度方式
5、显示测量点
二、运行结果
三、代码
double r1 = 50.00, c1 = 300.0;
double r2 = 150.0, c2 = 300.0;
double measureLength1 = 10, measureLength2 = 10;
double measureSigma = 1, measureThreshold = 10;
HTuple genParamName = new HTuple();
HTuple genParamValue = new HTuple();
//*创建计量模型
HMetrologyModel metrologyHandle =new HMetrologyModel();
//*添加计量对象到线测量()
metrologyHandle.AddMetrologyObjectLineMeasure(r1,c1,r2,c2,
measureLength1, measureLength2, measureSigma, measureThreshold,
genParamName, genParamValue);
//*设置计量对象参数
metrologyHandle.SetMetrologyObjectParam( 0, "measure_length1",100);
metrologyHandle.SetMetrologyObjectParam(0, "measure_length2",20);
metrologyHandle.SetMetrologyObjectParam(0, "measure_distance",10);
//*边缘阈值
metrologyHandle.SetMetrologyObjectParam(0, "measure_threshold",10);
//*边缘选择
metrologyHandle.SetMetrologyObjectParam(0, "measure_select","first");
//*过度方式
metrologyHandle.SetMetrologyObjectParam(0, "measure_transition","positive");
//ho_image为自己创建的HImage对象实例 HImage ho_image = new HImage()
//
metrologyHandle.ApplyMetrologyModel(ho_image);
//*显示测量点
HXLDCont contours = new HXLDCont();
contours = metrologyHandle.GetMetrologyObjectMeasures(0, "all", out HTuple row, out HTuple column);
HXLDCont xldCont = new HXLDCont();
xldCont.GenCrossContourXld(row, column, 10, 0.785398);
HTuple result = metrologyHandle.GetMetrologyObjectResult(0, "all", "result_type",
new HTuple(new string[] { "row_begin", "column_begin", "row_end", "column_end" }));
//*获得测量直线
double row_begin = result[0];
double column_begin = result[1];
double row_end = result[2];
double column_end = result[3];
HXLDCont xldLine = new HXLDCont();
xldLine.GenContourPolygonXld(
new HTuple(new double[] { row_begin, row_end }),
new HTuple(new double[] { column_begin, column_end })
);
//设置颜色并显示
//自己封装的方法
hWTool.DispObj(contours,"blue");//测量的直线范围
hWTool.DispObj(xldLine, "blue");//测量出来的直线
hWTool.DispObj(xldCont, "green");//测量出来的点
//hWindowControl1为HWindowControl对象实例
//hWindowControl1.HalconWindow.SetColor("blue");
//hWindowControl1.HalconWindow.DispObj(xldLine);//测量出来的直线
//hWindowControl1.HalconWindow.SetColor("red");
//hWindowControl1.HalconWindow.DispObj(contours);//测量的直线范围
// hWindowControl1.HalconWindow.SetColor("green");
//hWindowControl1.HalconWindow.DispObj(xldCont);//测量出来的点
标签:metrologyHandle,C#,double,HTuple,halcon,column,查找,new,row
From: https://www.cnblogs.com/whojie/p/18594913