halcon曲别针定位(角度位置)
By
admin
at 2019-10-02 • 0人收藏 • 3014人看过
import win.ui; /*DSG{{*/ var winform = win.form(text="aardio form";right=759;bottom=469) winform.add( button={cls="button";text="Button";left=12;top=72;right=124;bottom=147;z=2}; picturebox={cls="picturebox";left=180;top=0;right=760;bottom=470;z=1} ) /*}}*/ import HOperatorSetX; //halcon var HOperatorSetX = com.CreateObject("{6ebd90e2-d219-11d2-ade5-0000c00f4ef9}") //读取图片 var Clip = HOperatorSetX.ReadImage("C:\Users\Public\Documents\MVTec\HALCON-13.0\examples\images\clip"); //读取图片原始大小 var Width, Height = HOperatorSetX.GetImageSize(Clip); //将picturebox绑定到halcon窗口 var WindowHandle = HOperatorSetX.OpenWindow(0,0,winform.picturebox.width, winform.picturebox.height,winform.picturebox.hwnd,"transparent",""); import console console.open() winform.button.oncommand = function(id,event){ //动态阈值分割 var Dark, UsedThreshold = HOperatorSetX.BinaryThreshold( Clip, 'max_separability', 'dark' ); //断开 var Single = HOperatorSetX.Connection( Dark ); //选择区域 var Selected = HOperatorSetX.SelectShape( Single, 'area', 'and', 5000, 10000 ); //显示图片 HOperatorSetX.DispObj( Clip , WindowHandle ); HOperatorSetX.SetColor( WindowHandle , 'green' ); HOperatorSetX.DispObj( Selected , WindowHandle ); //获取区域角度 var Phi = HOperatorSetX.OrientationRegion( Selected ); //中心区域坐标 var Area, Row, Column = HOperatorSetX.AreaCenter( Selected ); HOperatorSetX.SetLineWidth( WindowHandle , 3 ); HOperatorSetX.SetDraw( WindowHandle , 'margin' ); HOperatorSetX.SetColor( WindowHandle , 'blue' ); Length = 80 for(i=1;#Row;1){ //画箭头 HOperatorSetX.DispArrow( WindowHandle, Row[i], Column[i], Row[i] - Length * math.sin(Phi[i]), Column[i] + Length * math.cos(Phi[i]), 4 ); } } winform.show(); win.loopMessage(); return winform;
登录后方可回帖