HALCON从入门到入门-找边找圆工具的使用

测试效果

步骤解析

1.创建计算模型

create_metrology_model (MetrologyHandle)

2.设置模型的图像宽高

set_metrology_model_image_size (MetrologyHandle, Width, Height)

3.添加测量工具,这里是添加了圆形检测工具

add_metrology_object_rectangle2_measure (MetrologyHandle, RectangleInitRow, RectangleInitColumn, RectangleInitPhi, RectangleInitLength1, RectangleInitLength2, RectangleTolerance, 5, .5, 1, [], [], MetrologyRectangleIndices)

4.添加矩形 检测工具

add_metrology_object_rectangle2_measure (MetrologyHandle, RectangleInitRow, RectangleInitColumn, RectangleInitPhi, RectangleInitLength1, RectangleInitLength2, RectangleTolerance, 5, .5, 1, [], [], MetrologyRectangleIndices)

5.设置检测模型参数

set_metrology_object_param (MetrologyHandle, MetrologyCircleIndices, 'num_instances', 2)

6.设置检测模型方向 (由明到暗还是相反)

set_metrology_object_param (MetrologyHandle, MetrologyCircleIndices, 'measure_transition', 'uniform')

7.设置最小得分

set_metrology_object_param (MetrologyHandle, MetrologyCircleIndices, 'min_score', .9)

8.将这个测量模型应用到图像上

apply_metrology_model (Image, MetrologyHandle)

9.获取测量结果

get_metrology_object_result (MetrologyHandle, MetrologyRectangleIndices, 'all', 'result_type', 'all_param', RectangleParameter)

10.把找到的点获取到 显示出来

get_metrology_object_measures (Contour, MetrologyHandle, 'all', 'all', Row1, Column1)

gen_cross_contour_xld (Cross, Row1, Column1, 6, 0.785398)

测试代码

* This example shows the usage of the metrology model
* to measure circles and rectangles with subpixel
* accuracy under challenging conditions easily.
* 
* Display initializations
dev_update_off ()
read_image (Image, 'pads')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
* 
* Define the approximate position and the measure
* tolerance for the circles
RowCircle := [52:89:500]
CircleInitRow := [RowCircle,RowCircle]
CircleInitColumn := [gen_tuple_const(6,348),gen_tuple_const(6,438)]
gen_cross_contour_xld (Cross1, CircleInitRow, CircleInitColumn, 6, 0.785398)
CircleInitRadius := [gen_tuple_const(6,23),gen_tuple_const(6,23)]
CircleRadiusTolerance := 12
* Define the approximate position and the measure
* tolerance for the rectangles
RectangleInitRow := [410,410]
RectangleInitColumn := [215,562]
RectangleInitPhi := [0,0]
RectangleInitLength1 := [85,85]
RectangleInitLength2 := [88,88]
RectangleTolerance := 10
* 
* Prepare the metrology model data structure
create_metrology_model (MetrologyHandle)
* Setting the image width in advance is not
* necessary, but improves the runtime of the
* first measurement.
set_metrology_model_image_size (MetrologyHandle, Width, Height)
* Add the metrology rectangle objects to the model
* as defined above
add_metrology_object_rectangle2_measure (MetrologyHandle, RectangleInitRow, RectangleInitColumn, RectangleInitPhi, RectangleInitLength1, RectangleInitLength2, RectangleTolerance, 5, .5, 1, [], [], MetrologyRectangleIndices)
* Add the metrology circle objects to the model
* as defined above
add_metrology_object_circle_measure (MetrologyHandle, CircleInitRow, CircleInitColumn, CircleInitRadius, CircleRadiusTolerance, 5, 1.5, 2, [], [], MetrologyCircleIndices)
* It is possible to measure more than one circle/rectangle/line/ellipse
* instance per metrology object in one call.
* Since we like to measure two circles per object,
* we set 'num_instances' to 2.
set_metrology_object_param (MetrologyHandle, MetrologyCircleIndices, 'num_instances', 2)
* Setting 'measure_transition' to 'uniform' assures
* that only consistent circles are returned, that have
* either only edges from bright to dark or vice versa.
* Since the consistency check increases runtime, it is
* switched of by default.
* In this example however, it is safer to switch it on,
* because both negative and positive edges are present.
set_metrology_object_param (MetrologyHandle, MetrologyCircleIndices, 'measure_transition', 'uniform')
* Setting the minimum score can make the results more robust
set_metrology_object_param (MetrologyHandle, MetrologyCircleIndices, 'min_score', .9)
* 
* Perform the measurement
* 
apply_metrology_model (Image, MetrologyHandle)
* 
get_metrology_object_result (MetrologyHandle, MetrologyRectangleIndices, 'all', 'result_type', 'all_param', RectangleParameter)
* Extract the parameters for better readability
Sequence := [0:5:|RectangleParameter| - 1]
RectangleRow := RectangleParameter[Sequence]
RectangleColumn := RectangleParameter[Sequence + 1]
RectanglePhi := RectangleParameter[Sequence + 2]
RectangleLength1 := RectangleParameter[Sequence + 3]
RectangleLength2 := RectangleParameter[Sequence + 4]
* 
* Access the results of the circle measurement
get_metrology_object_result (MetrologyHandle, MetrologyCircleIndices, 'all', 'result_type', 'all_param', CircleParameter)
* Extract the parameters for better readability
Sequence := [0:3:|CircleParameter| - 1]
CircleRow := CircleParameter[Sequence]
CircleColumn := CircleParameter[Sequence + 1]
CircleRadius := CircleParameter[Sequence + 2]
* 
* Display the results
* 
* Get measured contours
get_metrology_object_result_contour (Contours, MetrologyHandle, 'all', 'all', 1.5)
* Get the contours of the measure regions
* and the coordinates of the edge points
* that were the basis for fitting the circles and rectangles
get_metrology_object_measures (Contour, MetrologyHandle, 'all', 'all', Row1, Column1)
gen_cross_contour_xld (Cross, Row1, Column1, 6, 0.785398)
* Display everything
Color := ['gray','cyan','green']
dev_display (Image)
dev_set_line_width (1)
dev_set_color (Color[0])
dev_display (Contour)
dev_set_color (Color[1])
dev_display (Cross)
dev_set_line_width (2)
dev_set_color (Color[2])
dev_display (Contours)
Message := Color[2] + ': Measurement result'
Message[1] := Color[1] + ': Edge candidate points'
Message[2] := Color[0] + ': Measure regions'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
"Halcon入门到精通.pdf" 是一本关于Halcon 软件的学习资料,在网络上我们可以通过网盘来分享和下载这本书。 网盘是一种在线存储和分享文件的工具。通过网盘,用户可以将文件上传到服务器上,然后生成一个文件链接。其他用户则可以通过该链接下载文件。与传统的文件传输方式相比,网盘具有上传下载快速、方便、安全的特点。 对于"Halcon入门到精通.pdf"这样的学习资料,使用网盘来分享是非常合适的。首先,这样可以让更多的人获得学习机会,无论是学习软件的初学者还是想进一步提高的专业人士。其次,通过网盘分享,可以避免传统的文件复制和邮件发送过程中的版本混淆和文件丢失问题。最后,网络上的网盘资源丰富,用户可以通过搜索引擎或文件分享网站到自己所需的学习资料。 使用网盘下载"Halcon入门到精通.pdf"时,建议大家首先确保所使用的网盘链接来源可靠。在下载之前最好对文件进行一定的检查,以确保文件的完整性和安全性。此外,强烈建议大家在下载和使用学习资料的过程中遵守相关的法律和规定,不要进行非法的复制和传播行为。 总而言之,网盘是一个方便快捷的文件分享和下载工具。对于"Halcon入门到精通.pdf"这样的学习资料,使用网盘来分享和获取是非常适合的。希望这份回答能对您有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黄晓魚

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值