Halcon图像求边缘add_metrology_object_XX_measure-测量求边

1.测量弧:add_metrology_object_circle_measure (Operator)

name: add_metrology_object_circle_measure — Add a circle or a circular arc to a metrology model.

2.测量线:add_metrology_object_line_measure (Operator)

add_metrology_object_line_measure — Add a line to a metrology model.

read_image (Img, 'D:/00项目代码/000视觉软件/02Halocn算法20190501/04测量20190424/04_池-孔径/IMG11.jpg')
get_image_size (Img, Width, Height)
gen_rectangle1 (ROI_0, 215.769, 773.814, 323.904, 1012.06)
reduce_domain (Img, ROI_0, ImageReduced)
binary_threshold (ImageReduced, Region, 'max_separability', 'dark', UsedThreshold)
connection (Region, ConnectedRegions)
area_center (ConnectedRegions, Area, Row, Column)
distance_pp (Row[0], Column[0], Row[1], Column[1], Distance)
abss := 5/Distance

stop ()
*******************************Circle_measure**************************************************
*add_metrology_object_circle_measure
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandlecircle)
dev_clear_window ()

read_image (Imagecircle, 'D:/00项目代码/000视觉软件/02Halocn算法20190501/04测量20190424/04_池-孔径/IMG13.jpg')

* read_image (Imagecircle, '测量拟合.bmp')
rgb1_to_gray (Imagecircle, GrayImagecircle)
get_image_size (GrayImagecircle, Widthcircle, Heightcircle)
* Prepare the metrology model data structure
create_metrology_model (MetrologyHandlecircle)
* Setting the image width in advance is not
* necessary, but improves the runtime of the
* first measurement.
* It is possible to measure more than one circle/rectangle/line/ellipse
set_metrology_model_image_size (MetrologyHandlecircle, Widthcircle, Heightcircle)

draw_circle (WindowHandlecircle, DrCenCirRow, DrCenCirColumn, DrCenCirRadius)

dev_set_draw ('margin')
CircleInitRadius := DrCenCirRadius
CircleInitRow := DrCenCirRow
CircleInitColumn := DrCenCirColumn
CircleRadiusTolerance := 10

* Add the metrology circle objects to the model
* as defined above
add_metrology_object_circle_measure (MetrologyHandlecircle, 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 (MetrologyHandlecircle, MetrologyCircleIndices, 'num_instances', 10)
* 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 (MetrologyHandlecircle, MetrologyCircleIndices, 'measure_transition', 'uniform')
* Setting the minimum score can make the results more robust
set_metrology_object_param (MetrologyHandlecircle, MetrologyCircleIndices, 'min_score', .9)
* Perform the measurement circle
apply_metrology_model (GrayImagecircle, MetrologyHandlecircle)
* Access the results of the circle measurement
get_metrology_object_result (MetrologyHandlecircle, 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 (Contoursfittingscircle, MetrologyHandlecircle, '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 (Contourscircle, MetrologyHandlecircle, 'all', 'all', Rowcircle, Columncircle)
gen_cross_contour_xld (Contourscircle, Rowcircle, Columncircle, 6, 0.785398)
dev_clear_window ()
dev_display (Imagecircle)
fit_circle_contour_xld (Contoursfittingscircle, 'algebraic', -1, 0, 0, 3, 2, Row51, Column51, Radius1, StartPhi, EndPhi, PointOrder)
dev_set_color ('green')
gen_circle_contour_xld (ContCircle1, Row51, Column51, Radius1, 0, 6.28318, 'positive', 1)
gen_cross_contour_xld (Cross1, Row51, Column51, 6, 0.785398)

* gen_contour_region_xld (ConnectedRegions, Contours2, 'border')

* dev_set_draw ('fill')
* gen_region_contour_xld (Contoursfittingscircle, Region1, 'filled')


* dev_display (GrayImagecircle)
* dev_display (Contourscircle)
* dev_display (Contoursfittingscircle)
* dev_display (Contourscircle)
clear_metrology_model (MetrologyHandlecircle)

*******************************Circle_measure**************************************************
stop ()

stop ()
*******************************Circle_measure**************************************************
*add_metrology_object_circle_measure
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandlecircle)
dev_clear_window ()

* read_image (Imagecircle, 'E:/000MyWorkFiles/00Projects/01Halocn算法/04测量/池-孔径/IMG13.jpg')

* read_image (Imagecircle, '测量拟合.bmp')
rgb1_to_gray (Imagecircle, GrayImagecircle)
get_image_size (GrayImagecircle, Widthcircle, Heightcircle)
* Prepare the metrology model data structure
create_metrology_model (MetrologyHandlecircle)
* Setting the image width in advance is not
* necessary, but improves the runtime of the
* first measurement.
* It is possible to measure more than one circle/rectangle/line/ellipse
set_metrology_model_image_size (MetrologyHandlecircle, Widthcircle, Heightcircle)

draw_circle (WindowHandlecircle, DrCenCirRow, DrCenCirColumn, DrCenCirRadius)

dev_set_draw ('margin')
CircleInitRadius := DrCenCirRadius
CircleInitRow := DrCenCirRow
CircleInitColumn := DrCenCirColumn
CircleRadiusTolerance := 10

* Add the metrology circle objects to the model
* as defined above
add_metrology_object_circle_measure (MetrologyHandlecircle, 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 (MetrologyHandlecircle, MetrologyCircleIndices, 'num_instances', 10)
* 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 (MetrologyHandlecircle, MetrologyCircleIndices, 'measure_transition', 'uniform')
* Setting the minimum score can make the results more robust
set_metrology_object_param (MetrologyHandlecircle, MetrologyCircleIndices, 'min_score', .9)
* Perform the measurement circle
apply_metrology_model (GrayImagecircle, MetrologyHandlecircle)
* Access the results of the circle measurement
get_metrology_object_result (MetrologyHandlecircle, 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 (Contoursfittingscircle1, MetrologyHandlecircle, '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 (Contourscircle, MetrologyHandlecircle, 'all', 'all', Rowcircle, Columncircle)
gen_cross_contour_xld (Contourscircle, Rowcircle, Columncircle, 6, 0.785398)

dev_display (Imagecircle)

fit_circle_contour_xld (Contoursfittingscircle1, 'algebraic', -1, 0, 0, 3, 2, Row52, Column52, Radius2, StartPhi, EndPhi, PointOrder)
dev_set_color ('green')
gen_circle_contour_xld (ContCircle2, Row52, Column52, Radius2, 0, 6.28318, 'positive', 1)
gen_cross_contour_xld (Cross2, Row52, Column52, 6, 0.785398)

* dev_display (GrayImagecircle)
* dev_display (Contourscircle)
* dev_display (Contoursfittingscircle1)
* dev_display (Contourscircle)
clear_metrology_model (MetrologyHandlecircle)

*******************************Circle_measure**************************************************
stop ()

dev_display (Imagecircle)

dev_display (Cross1)
dev_display (ContCircle1)

dev_display (Cross2)
dev_display (ContCircle2)

* real_rad1 := Radius1*abss
* real_rad2 := Radius2*abss



****************开始***********Line01**************************************************
*add_metrology_object_line_measure ---->  line01
stop ()
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandleline01)
dev_clear_window ()
read_image (Imageline01, 'D:/00项目代码/000视觉软件/02Halocn算法20190501/04测量20190424/04_池-孔径/IMG13.jpg')
get_image_size (Imageline01, Width, Height)
rgb1_to_gray (Imageline01, GrayImageline01)
get_image_size (GrayImageline01, Widthline01, Heightline01)
dev_set_draw ('margin')
lineTolerance01 := 30

draw_line (WindowHandleline01, DrLineStartRow01, DrLineStartColumn01, DrLineEndRow01, DrLineEndColumn01)
* Prepare the metrology model data structure
create_metrology_model (MetrologyHandleLine01)
* Setting the image width in advance is not
* necessary, but improves the runtime of the
* first measurement.
* It is possible to measure more than one circle/rectangle/line/ellipse
set_metrology_model_image_size (MetrologyHandleLine01, Widthline01, Heightline01)
* Add the metrology line  objects to the model  with dir
* as defined above
add_metrology_object_line_measure (MetrologyHandleLine01, DrLineStartRow01, DrLineStartColumn01, DrLineEndRow01,DrLineEndColumn01,lineTolerance01, 5, 1, 30, [], [], MetrologyLineIndices01)
* Perform the measurement rectangle
apply_metrology_model (GrayImageline01, MetrologyHandleLine01)
* get_metrology_object_result
get_metrology_object_result (MetrologyHandleLine01, MetrologyLineIndices01, 'all', 'result_type', 'all_param', LineParameter)
* Display the results 
* Get measured contours
get_metrology_object_result_contour (ContoursfittingLine01, MetrologyHandleLine01, '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 Line
get_metrology_object_measures (ContoursLine01, MetrologyHandleLine01, 'all', 'all', RowLine, ColumnLine)
gen_cross_contour_xld (CrossLine01, RowLine, ColumnLine, 6, 0.785398)

get_contour_xld (ContoursfittingLine01, Row1, Col1)


dev_display (GrayImageline01)
dev_display (ContoursLine01)
dev_display (ContoursfittingLine01)
dev_display (CrossLine01)
* Clean up memory
clear_metrology_model (MetrologyHandleLine01)
********************结束***********Line01**************************************************
stop ()

****************开始***********Line01**************************************************
*add_metrology_object_line_measure ---->  line01
stop ()
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandleline01)
dev_clear_window ()
read_image (Imageline01, 'D:/00项目代码/000视觉软件/02Halocn算法20190501/04测量20190424/04_池-孔径/IMG13.jpg')
get_image_size (Imageline01, Width, Height)
rgb1_to_gray (Imageline01, GrayImageline01)
get_image_size (GrayImageline01, Widthline01, Heightline01)
dev_set_draw ('margin')
lineTolerance01 := 30

draw_line (WindowHandleline01, DrLineStartRow01, DrLineStartColumn01, DrLineEndRow01, DrLineEndColumn01)
* Prepare the metrology model data structure
create_metrology_model (MetrologyHandleLine01)
* Setting the image width in advance is not
* necessary, but improves the runtime of the
* first measurement.
* It is possible to measure more than one circle/rectangle/line/ellipse
set_metrology_model_image_size (MetrologyHandleLine01, Widthline01, Heightline01)
* Add the metrology line  objects to the model  with dir
* as defined above
add_metrology_object_line_measure (MetrologyHandleLine01, DrLineStartRow01, DrLineStartColumn01, DrLineEndRow01,DrLineEndColumn01,lineTolerance01, 5, 1, 30, [], [], MetrologyLineIndices01)
* Perform the measurement rectangle
apply_metrology_model (GrayImageline01, MetrologyHandleLine01)
* get_metrology_object_result
get_metrology_object_result (MetrologyHandleLine01, MetrologyLineIndices01, 'all', 'result_type', 'all_param', LineParameter)
* Display the results 
* Get measured contours
get_metrology_object_result_contour (ContoursfittingLine02, MetrologyHandleLine01, '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 Line
get_metrology_object_measures (ContoursLine01, MetrologyHandleLine01, 'all', 'all', RowLine, ColumnLine)
gen_cross_contour_xld (CrossLine01, RowLine, ColumnLine, 6, 0.785398)



dev_display (GrayImageline01)
dev_display (ContoursLine01)
dev_display (ContoursfittingLine01)
dev_display (CrossLine01)
* Clean up memory
clear_metrology_model (MetrologyHandleLine01)
********************结束***********Line01**************************************************
stop ()



distance_pl (Row1, Col1, RowLine[0], ColumnLine[0], RowLine[33], ColumnLine[33], Distance2)
distance_pp ( Row52, Column52, Row51, Column51, Distance3)
dev_clear_window ()
dev_display (Imagecircle)
dev_set_color ('green')
gen_arrow_contour_xld (Arrow, 309, 467, 976, 453, 30, 30)
gen_arrow_contour_xld (Arrow, 976, 453,309, 467,  30, 30)

real_disl := abss*Distance2
real_discc := abss*Distance3
disp_message (3600,'宽度(mm):'+real_disl[10], 'image', 641,200,'green', 'false')

gen_arrow_contour_xld (Arrow, Row52, Column52, Row51, Column51,10, 10)
gen_arrow_contour_xld (Arrow, Row51, Column51, Row52, Column52,10, 10)
disp_message (3600,'中心距(mm):'+real_disl[10], 'image', 453,636,'green', 'false')

dev_display (GrayImageline01)
dev_set_color ('red')
dev_display (ContoursfittingLine02)
dev_display (ContoursfittingLine01)

dev_display (Cross1)
dev_display (ContCircle1)

dev_display (Cross2)
dev_display (ContCircle2)

real_rad1 := Radius1*abss*2
real_rad2 := Radius2*abss*2

gen_arrow_contour_xld (Arrow, 507, 637, 484, 615, 10, 10)
gen_arrow_contour_xld (Arrow, 400, 636, 428, 611,  10, 10)

disp_message (3600,'直径1(mm):'+real_rad1, 'image', 388,653,'green', 'false')
disp_message (3600,'直径2(mm):'+real_rad2, 'image', 518,651,'green', 'false')

 

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: Halcon中的图像增强算子mult_image是用于对图像进行增强处理的一种方法。该算子可以根据亮度、对比度、颜色平衡等参数,改善图像的质量和细节。 mult_image算子的基本原理是通过增加或减少图像像素值的方式,来调整图像的亮度和对比度。算子将原始图像的像素值乘以一个缩放因子,然后再加上一个偏移值,从而改变图像的亮度。此外,mult_image还可以通过调整R、G、B三个颜色通道的增益来平衡图像的色彩。这些参数可以根据实际需要进行调整,以达到理想的图像增强效果。 使用mult_image算子进行图像增强的步骤如下: 1. 选择待处理的图像作为输入。 2. 设置亮度缩放因子和偏移值,可以通过试验和调整这些参数来获得最佳结果。 3. 设置颜色增益,可以根据图像的具体情况进行调整。 4. 将输入图像和参数传入mult_image算子中。 5. 根据算子的输出结果,可观察到图像亮度和对比度的变化,以及颜色平衡的调整效果。 总之,通过Halcon的mult_image算子,我们可以对图像进行灵活的增强处理,以改善图像的质量和细节。这个算子提供了多个参数选项,可以根据具体需进行调整,并且具有较高的灵活性和效果。 ### 回答2: Halcon是一种用于机器视觉的图像处理软件,拥有丰富的图像增强算子。其中,mult_image是一种常用的图像增强算子。 mult_image算子的作用是通过对输入图像中的每个像素进行乘法操作,改变图像的亮度和对比度,从而增强图像的视觉效果。该算子是通过将每个像素的灰度值与一个乘法因子相乘来实现的。 使用mult_image算子可以实现多种图像增强效果,例如增强图像的对比度、改变图像的亮度和色彩饱和度等。通过调整乘法因子的值,可以控制图像增强的程度和效果。 对于亮度增强,可以选择乘法因子大于1的值,使得图像的亮度增加。而对于亮度减弱,可以选择乘法因子小于1的值,使得图像的亮度降低。 对于对比度增强,可以选择乘法因子大于1的值,使得图像的灰度值分布更加分散。而对于对比度减弱,可以选择乘法因子小于1的值,使得图像的灰度值分布更加集中。 总之,mult_image算子是Halcon中一种常用的图像增强算子,通过对输入图像中的每个像素进行乘法操作,改变图像的亮度和对比度,从而增强图像的视觉效果。使用该算子可以实现多种图像增强效果,通过调整乘法因子的值来控制增强的程度和效果。 ### 回答3: halcon图像增强算子mult_image是一种用于增强图像质量的功能强大的算子。该算子可以通过合并图像的不同频率成分来提高图像的清晰度和对比度。 mult_image算子基于频域滤波的原理工作。它采用了小波变换或傅里叶变换来分解图像,并对不同频率的分量进行增强处理。通过调整算子参数,可以在增强图像的细节同时还保持图像的平滑度。 mult_image算子的主要参数包括分解层数、增强系数和滤波参数。分解层数决定了图像分解的细节层数,增强系数用于控制增强强度,滤波参数用于指定滤波器类型和滤波器尺寸。 使用mult_image算子可以有效地减少图像中的噪声,并增强图像边缘信息。在工业检测和机器视觉等领域中,mult_image算子可以帮助检测和分析图像中的细微特征,从而提高图像处理的准确性和可靠性。 总的来说,halcon图像增强算子mult_image是一种功能强大的算子,可以通过合并不同频率的图像成分来增强图像质量。它在工业检测和机器视觉等领域有着广泛的应用,可以提高图像处理的效果和准确性。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值