康耐德智能

 有光必有源,康耐德视觉光源!

 服务热线:0769-28680919   手机:15322933971

图片展示
搜索

更多资讯

分类标题

关注康耐德智能

         

电话:0769-28680919

传真:0769-28680910

邮箱:csray@csray.com

地址:东莞市南城区天安数码城C2栋507室


基于Halcon圆拟合提取学习

作 者:康耐德智能关注:173发表时间:2018-12-24 09:26:50来源:网络资源

1. 本文主要围绕Halcon圆拟合提取的学习心得总结,主要围绕halcon算子shape_trans,small_circle,fit_circle_contour_xld,hough_circles,add_metrology_object_circle_measure展开

2. Shape_trans

该算子检测图像变换区域中被广泛应用;

Signature

shape_trans(Region : RegionTrans : Type : )

Region (input_object)  region(-array)object

Regions to be transformed.

RegionTrans (output_object)  region(-array)object

Transformed regions.

Type (input_control)  string(string)

Type of transformation.

Default value: 'convex'

List of values: 'convex', 'ellipse', 'inner_center', 'inner_circle', 'inner_rectangle1','outer_circle', 'rectangle1', 'rectangle2'

Halcon例程1: 

                  提取前图片                                提取后图片

                              

Halcon code

threshold (Image, Region, 0, 100)

closing_circle (Region, Region, 3.5)

connection (Region, ConnectedRegions)

select_shape (ConnectedRegions, Ring, ['width','height'], 'and', [550,550], [750,750])

shape_trans (Ring, OuterCircle, 'outer_circle')

3. smallest_circle

该算子主要是拟合一个区域的最小围绕圆

Signature

smallest_circle(Regions : : : Row, Column, Radius)

 

Regions (input_object)  region(-array)object

Regions to be examined.

Row (output_control)  circle.center.y(-array)(real)

Line index of the center.

Column (output_control)  circle.center.x(-array)(real)

Column index of the center.

Radius (output_control)  circle.radius(-array)(real)

Radius of the surrounding circle.

Assertion: Radius >= 0

Halcon例程2

                 提取前图片                               提取后图片

      

Halcon code

read_image (Image, 'circular_barcode')

get_image_size (Image, Width, Height)

threshold (Image, Region, 0, 100)

closing_circle (Region, Region, 3.5)

connection (Region, ConnectedRegions)

select_shape (ConnectedRegions, Ring, ['width','height'], 'and', [550,550], [750,750])

shape_trans (Ring, OuterCircle, 'outer_circle')

complement (Ring, RegionComplement)

connection (RegionComplement, ConnectedRegions)

select_shape (ConnectedRegions, InnerCircle, ['width','height'], 'and', [450,450], [650,650])

smallest_circle (Ring, Row, Column, OuterRadius)

4. fit_circle_contour_xld

该算子对找到的圆形轮廓进行拟合成圆

Signature

fit_circle_contour_xld(Contours : : Algorithm, MaxNumPoints, MaxClosureDist, ClippingEndPoints, Iterations, ClippingFactor : Row, Column, Radius, StartPhi, EndPhi, PointOrder)

Contours (input_object)  xld_cont(-array)object

Input contours.

Algorithm (input_control)  string(string)

Algorithm for the fitting of circles.

MaxNumPoints (input_control)  integer(integer)

Maximum number of contour points used for the computation (-1 for all points).

MaxClosureDist (input_control)  real(real)

ClippingEndPoints (input_control)  integer(integer)

Number of points at the beginning and at the end of the contours to be ignored for the fitting.

Iterations (input_control)  integer(integer)

ClippingFactor (input_control)  real(real)

Clipping factor for the elimination of outliers (typical: 1.0 for Huber and 2.0 for Tukey).

Row (output_control)  circle.center.y(-array)(real)

Row coordinate of the center of the circle.

Column (output_control)  circle.center.x(-array)(real)

Column coordinate of the center of the circle.

Radius (output_control)  circle.radius(-array)(real)

Radius of circle.

StartPhi (output_control)  real(-array)(real)

Angle of the start point [rad].

EndPhi (output_control)  real(-array)(real)

Angle of the end point [rad].

PointOrder (output_control)  string(-array)(string)

Point order along the boundary.

Halcon例程3

                 提取前图片                            提取后图片

    

Halcon Code

read_image (Image, 'circular_barcode')

get_image_size (Image, Width, Height)

threshold (Image, Region, 0, 100)

closing_circle (Region, Region, 3.5)

connection (Region, ConnectedRegions)

select_shape (ConnectedRegions, Ring, ['width','height'], 'and', [550,550], [750,750])

shape_trans (Ring, OuterCircle, 'outer_circle')

complement (Ring, RegionComplement)

connection (RegionComplement, ConnectedRegions)

select_shape (ConnectedRegions, InnerCircle, ['width','height'], 'and', [450,450], [650,650])

smallest_circle (Ring, Row, Column, OuterRadius)

erosion_circle(OuterCircle, RegionErosion, 5.5)

dilation_circle(OuterCircle,RegionDilation, 3.5)

difference(RegionDilation, RegionErosion, RegionDifference)

reduce_domain(Image, RegionDifference, ImageReduced)

edges_sub_pix(ImageReduced, Edges, 'canny', 1, 20, 40)

select_contours_xld(Edges, SelectedContours, 'contour_length', 100, 20000, -0.5, 0.5)

fit_circle_contour_xld(SelectedContours, 'algebraic', -1, 0, 0, 3, 2, Row1, Column1, Radius, StartPhi, EndPhi, PointOrder)

gen_circle_contour_xld(ContCircle, Row1, Column1, Radius, 0, 6.28318, 'positive', 1)

dev_display(Image)

dev_display(ContCircle)

5. Hough_circles霍夫变化找具体半径的圆

Signature

hough_circles(RegionIn : RegionOut : Radius, Percent, Mode : )

Parameters

RegionIn (input_object)  regionobject

Binary edge image in which the circles are to be detected.

RegionOut (output_object)  region(-array)object

Centres of those circles which are included in the edge image by Percent percent.

Radius (input_control)  integer(-array)(integer)

Radius of the circle to be searched in the image.

Percent (input_control)  integer(-array)(integer)

Indicates the percentage (approximately) of the (ideal) circle which must be present in the edge

Mode (input_control)  integer(-array)(integer)

The modus defines the position of the circle in question:

Halcon例程4

                提取前图片                             提取后图片

 

                                       

Halcon code

read_image (Image, 'circular_barcode')

get_image_size (Image, Width, Height)

threshold (Image, Region, 0, 100)

opening_circle(Region, RegionOpening, 3.5)

fill_up(RegionOpening, RegionFillUp)

hough_circles(RegionFillUp, RegionOut, 60, 50, 2)

6. add_metrology_object_circle_measure通过测量的方式找圆

Signature

add_metrology_object_circle_measure( : : MetrologyHandle, Row, Column, Radius, MeasureLength1, MeasureLength2, MeasureSigma, MeasureThreshold, GenParamName, GenParamValue : Index)

Parameters

MetrologyHandle (input_control, state is modified)  metrology_model(integer)

Handle of the metrology model.

Row (input_control)  circle.center.y(-array)(real / integer)

Row coordinate (or Y) of the center of the circle or circular arc.

Column (input_control)  circle.center.x(-array)(real / integer)

Column (or X) coordinate of the center of the circle or circular arc.

Radius (input_control)  circle.radius(-array)(real / integer)

Radius of the circle or circular arc.

MeasureLength1 (input_control)  number(real / integer)

Half length of the measure regions perpendicular to the boundary.

MeasureLength2 (input_control)  number(real / integer)

Half length of the measure regions tangetial to the boundary.

MeasureSigma (input_control)  number(real / integer)

Sigma of the Gaussian function for the smoothing.

MeasureThreshold (input_control)  number(real / integer)

Minimum edge amplitude.

GenParamName (input_control)  attribute.name(-array)(string)

Names of the generic parameters.

GenParamValue (input_control)  attribute.value(-array)(real / integer / string)

Values of the generic parameters.

Index (output_control)  integer(integer)

Index of the created metrology object.

Halcon例程5

               提取前图片                            提取后图片

 

 

Halcon code

read_image (Image, 'circular_barcode')

get_image_size (Image, Width, Height)

draw_circle(3600, Row2, Column2, Radius1)

gen_circle(Circle, Row2, Column2, Radius1)

* Create the data structure that is needed to measure geometric shapes.

create_metrology_model (MetrologyHandle)

set_metrology_model_image_size (MetrologyHandle, Width, Height)

*Add a circle or a circular arc to a metrology model

add_metrology_object_circle_measure (MetrologyHandle, Row2, Column2, Radius1, 100, 5, 3, 60, [], [], MetrologyCircleIndices)

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

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

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

set_metrology_object_param (MetrologyHandle, MetrologyCircleIndices, 'measure_distance', 20)

apply_metrology_model (Image, MetrologyHandle)

 

get_metrology_object_result (MetrologyHandle, MetrologyCircleIndices, 'all', 'result_type', 'all_param', CircleParameter)

get_metrology_object_result_contour (Contours, MetrologyHandle, 'all', 'all', 1.5)

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

sort_contours_xld(Contours, SortedContours, 'upper_left', 'true', 'row')

count_obj(SortedContours,Number)

*筛选所找到的轮廓

if(Number>0)

    select_obj(SortedContours,ObjectSelected, 1)

    fit_circle_contour_xld (ObjectSelected, 'algebraic', -1, 0, 0, 3, 2, CircleRow, CircleColumn, CircleRadius, StartPhi1, EndPhi1, PointOrder1)

    gen_circle_contour_xld(ContCircle1, CircleRow, CircleColumn, CircleRadius, 0, 6.28318, 'positive', 1)

 

endif

clear_metrology_model (MetrologyHandle)


概念介绍

何谓霍夫变换

霍夫变换是一种特征检测(feature extraction),被广泛应用在图像分析(image analysis)、电脑视觉(computer vision)以及数位影像处理(digital image processing)。霍夫变换是用来辨别找出物件中的特征,例如:线条。他的算法流程大致如下,给定一个物件、要辨别的形状的种类,算法会在参数空间(parameter space)中执行投票来决定物体的形状,而这是由累加空间(accumulator space)里的局部***值(local maximum)来决定。

现在广泛使用的霍夫变换是由RichardDudaPeterHart在公元1972年发明,并称之为广义霍夫变换(generalizedHoughtransform),广义霍夫变换和更早前1962年的PaulHough的专利有关。经典的霍夫变换是侦测图片中的直线,之后,霍夫变换不仅能识别直线,也能够识别任何形状,常见的有圆形、椭圆形。1981年,因为DanaH.Ballard的一篇期刊论文"Generalizing the Hough transform to detect arbitrary shapes",让霍夫变换开始流行于电脑视觉界。 


理论

在自动化分析数位图片的问题里,其中一个常有的子问题是侦测某些简单的直线、圆形、椭圆形。在多数情况下,边缘侦测器(edge detector)会先用来做图片前处理,将原本的图片变成只含有边缘的图片。因为图片的不完美或是边缘侦测的不完美,导致有些点(point)或像素(pixel)缺漏,或是有噪声使得边缘侦测器所得的边界偏离了实际的边界。所以无法直观的将检测出的边缘分成直线、圆形、椭圆形的集合,而霍夫变换解决上述问题,借由霍夫变换算法中的投票步骤,在复杂的参数空间中找到图形的参数,电脑可以由参数得知该边缘(edge)是哪种形状。 

广东省东莞市南城区黄金路1号天安数码城C2-507

电话:0769-28680919

手机:15322933971

邮箱:csray@csray.com

版权所有:东莞康耐德智能控制有限公司

粤ICP备18080826号-1

在线客服
联系方式
热线电话
0769-28680919
手机服务
15322933971
上班时间
周一到周五
二维码
二维码
在线客服