日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > C# >内容正文

C#

halcon联合C#测量十字Mark中心

發(fā)布時(shí)間:2023/12/10 C# 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 halcon联合C#测量十字Mark中心 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

halcon聯(lián)合C#測(cè)量十字Mark中心

函數(shù)說(shuō)明

public void FitRectangleMeasure(HWindow 窗口句柄, HImage 圖像, out double 中心Y坐標(biāo), out double 中心X坐標(biāo))

操作步驟,首先繪制兩個(gè)矩形測(cè)量框;之后就可進(jìn)行自動(dòng)計(jì)算。

public void FitRectangleMeasure(HWindow hWindow, HImage hImage, out double Row, out double Col){try{int rtCount = 2;double[] rtRows = new double[rtCount];double[] rtCols = new double[rtCount];double[] rtAngles = new double[rtCount];double[] rtLen1s = new double[rtCount];double[] rtLen2s = new double[rtCount];hWindow.SetColor("red");hWindow.SetDraw("margin");HTuple hv_Row1, hv_Column1, hv_Row2, hv_Column2, hv_RectangleParameter;//繪制測(cè)量矩形for (int rtIndex = 0; rtIndex < rtCount; rtIndex++){HOperatorSet.DrawRectangle1Mod(hWindow, 1000, 1000, 1200, 1200, out hv_Row1, out hv_Column1, out hv_Row2, out hv_Column2);double dRowCenter = (hv_Row1.D + hv_Row2.D) / 2;double dColCenter = (hv_Column1.D + hv_Column2.D) / 2;double dL1 = (hv_Column2.D - hv_Column1.D) / 2;double dL2 = (hv_Row2.D - hv_Row1.D) / 4;rtRows[rtIndex] = dRowCenter;rtCols[rtIndex] = dColCenter;rtAngles[rtIndex] = 0;rtLen1s[rtIndex] = dL1;rtLen2s[rtIndex] = dL2;}//測(cè)量寬度int nHalfBorder = (int)(Math.Min(rtLen1s[0], rtLen2s[0]) + Math.Min(rtLen1s[1], rtLen2s[1])) / 2;//矩形測(cè)量句柄的創(chuàng)建HTuple hv_MetrologyHandle = null, hv_MetrologyRectangleIndices = null;HOperatorSet.CreateMetrologyModel(out hv_MetrologyHandle);HOperatorSet.AddMetrologyObjectRectangle2Measure(hv_MetrologyHandle, new HTuple(rtRows),new HTuple(rtCols), new HTuple(rtAngles), new HTuple(rtLen1s), new HTuple(rtLen2s), nHalfBorder, nHalfBorder / 4,1, 10, new HTuple(), new HTuple(), out hv_MetrologyRectangleIndices);HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle, hv_MetrologyRectangleIndices, "num_instances", 1);HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle, hv_MetrologyRectangleIndices, "min_score", 0.1);HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle, hv_MetrologyRectangleIndices, "measure_transition", "uniform");HOperatorSet.ApplyMetrologyModel(hImage, hv_MetrologyHandle);//測(cè)量出的信息HObject ho_MeasureContours;//測(cè)量框 HObject ho_Cross; //測(cè)量出來(lái)的交界點(diǎn)HOperatorSet.GenEmptyObj(out ho_MeasureContours);HOperatorSet.GenEmptyObj(out ho_Cross);ho_MeasureContours.Dispose();ho_Cross.Dispose();HOperatorSet.GetMetrologyObjectMeasures(out ho_MeasureContours, hv_MetrologyHandle, "all", "all", out hv_Row1, out hv_Column1);HOperatorSet.GenCrossContourXld(out ho_Cross, hv_Row1, hv_Column1, 20, 0.785398);hWindow.DispObj(ho_MeasureContours);//hWindow.DispObj(ho_Cross);HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle, "all", "all", "result_type","all_param", out hv_RectangleParameter);//測(cè)量出來(lái)的矩形框HObject ho_ResultContour;HOperatorSet.GenEmptyObj(out ho_ResultContour);ho_ResultContour.Dispose();HOperatorSet.GetMetrologyObjectResultContour(out ho_ResultContour, hv_MetrologyHandle, "all", "all", 1.5);hWindow.DispObj(ho_ResultContour);//測(cè)量出矩形的數(shù)據(jù)HTuple hv_Sequence, hv_RectangleRow, hv_RectangleColumn, hv_RectanglePhi, hv_RectangleLength1, hv_RectangleLength2;hv_Sequence = HTuple.TupleGenSequence(0, (new HTuple(hv_RectangleParameter.TupleLength())) - 1, 5);hv_RectangleRow = hv_RectangleParameter.TupleSelect(hv_Sequence);hv_RectangleColumn = hv_RectangleParameter.TupleSelect(hv_Sequence + 1);hv_RectanglePhi = hv_RectangleParameter.TupleSelect(hv_Sequence + 2);hv_RectangleLength1 = hv_RectangleParameter.TupleSelect(hv_Sequence + 3);hv_RectangleLength2 = hv_RectangleParameter.TupleSelect(hv_Sequence + 4);if (hv_RectangleRow.TupleLength() == rtCount){Row = (hv_RectangleRow[0].D + hv_RectangleRow[1].D) / 2;Col = (hv_RectangleColumn[0].D + hv_RectangleColumn[1].D) / 2;}else{Row = 0;Col = 0;}HOperatorSet.ClearMetrologyModel(hv_MetrologyHandle);//釋放HObjectho_MeasureContours.Dispose();ho_Cross.Dispose();ho_ResultContour.Dispose();}catch{Row = 0;Col = 0;}}

不懂的話可以問(wèn)我哦,下邊評(píng)論看到了第一時(shí)間回復(fù)。如果覺(jué)得有用點(diǎn)贊哦。

PS

我的博客不定時(shí)分享日常工作中覺(jué)得有價(jià)值的內(nèi)容,包括C#、C++、halcon、運(yùn)動(dòng)控制等等內(nèi)容,喜歡的點(diǎn)贊,關(guān)注我。

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的halcon联合C#测量十字Mark中心的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。