最近因为项目需求,研究了一个小工具,自动计算解析度。
read_image (Image, 'D:/TT/Desktop/halcon/计算解析度/擷取.PNG')
InputTuple:=['179, 77, 410, 513','3']
CalculateResolution (Image, OutputImage, InputTuple, OutputTuple)
新建函数,计算解析度
CalculateResolution (InputImage, OutputImage, InputTuple, OutputTuple)
InputImage:输入的图片;
OutputImage:输出的图片;
InputTuple:输入的参数;
OutputTuple:输出的参数
gen_empty_obj (MatchContours)
tuple_number (InputTuple, InputTuple)
lib_convert_roi (RoiRect, InputTuple[0], Roi)
reduce_domain (InputImage, RoiRect, ImageReduced)
lib_find_line_2d (ImageReduced, Contour1, Cross1, Roi, '↓', 'positive', 'first', 10, 2, 10, 10, Line1)
lib_find_line_2d (ImageReduced, Contour2, Cross2 ,Roi, '↑', 'positive', 'first', 10, 2, 10, 10, Line2)
concat_obj (Contour1, Contour2, MatchContours)
Reals:=InputTuple[1]
Wide:=Line2[0]-Line1[0]
Resolution:=Reals/Wide
OutputTuple := [Reals,Wide,Resolution]
ShowText := ['实际PAD宽度','宽度','解析度'] + ':' + OutputTuple
lib_draw_open (InputImage, 1, WindowVector.at(0))
lib_draw_shape (MatchContours, 'margin', 'green', 3, WindowVector.at(0))
lib_draw_result (ShowText, 'OK', 20, WindowVector.at(0))
lib_draw_close (OutputImage, WindowVector)
return ()
原图:
输出图片:
因篇幅问题不能全部显示,请点此查看更多更全内容