Coutours 属于XLD结构
a) 图  边缘覆盖在原始图像上
b)缩放 a)中的 矩形区域,凸显控制点
c)轮廓可以分割成线。圆。椭圆等,可以得出它们的 角度 中心 半径等
Basic Concept
create XLD contours
最常用的方法是 用Extract Edges Or Lines方法,结果将转化为XLD
Process XLD Contours
典型的情况 如 a)所示,只作用于指定的区域
许多时候 ROI选择过大 如图 b) ,这个时候要把 轮廓进行分割,只选择平行的部分 如图 c)
另外的原因,处理轮廓是因为包换了不希望得到的噪声,比如低对比度。
Perform Fitting
通过 fitting 操作,(a line, a rectangle, or a circular or elliptic arc,)来逼近(a line, a rectangle, or a circular or elliptic arc)。
Extract Features

From both raw contours and processed contour parts features can be determined. Some of these consider
the contour as a linear object. Others treat a contour as the outer boundary of an object. Obviously,
the center of gravity makes sense only for a closed object, whereas the curvature is a feature of a linear
object.
例子 提取公路
***************************************************************
*   1.lines_gauss 结果图a)所示 得到许多不想要的 小片段
*   2.select_contours_xld(Lines,LongContours,'contour_length',15,1000,0,0) 选择[15,1000]轮廓长度 这样就消除了小的轮廓
*   3.union_collinear_contours_xld (LongContours, UnionContours, 30, 2, 9, 0.7, 'attr_keep') 把共线的轮廓连接在一起。结果 如图b)
*
********************************************************
read_image(Image,'mreut4_3')
get_image_size(Image,Width,Height)
dev_close_window()
dev_open_window(0,0,Width,Height,'black',WindowID)

lines_gauss(Image,Lines,1.5,2,8,'light','true','bar-shaped','true')

select_contours_xld(Lines,LongContours,'contour_length',15,1000,0,0)

union_collinear_contours_xld (LongContours, UnionContours, 30, 2, 9, 0.7, \
'attr_keep')

Extended Concept
1.Create XLD Contour
标准的方法是调用轮廓提取函数来创建轮廓。
边缘轮廓提取:edges_sub_pix, edges_color_sub_pix, or zero_crossing_sub_pix
线条提取:lines_gauss, lines_facet, or lines_color
亚像素blob分析:threshold_sub_pix
如果像素精度足够的话,可以用edge filter 如sobel_amp edges_image 或者 line filter 如bandpass_image
细化边缘然后转换XLD, gen_contours_skeleton_xld. 
gen_contour_polygon_xld  gen_contour_polygon_rounded_xld
draw_xld  draw_xld_mod 交互式生成
gen_contour_region_xld 根据region生成轮廓
2.Process XLD Contours
segment_contours_xld 这个操作有多种模式:Splitting into line segments, linear and circular segments, or linear and elliptic segments. 
select_obj 单独的一个可以用此得到。Perform Fitting 来做适配操作,比如趋近于圆的的轮廓。
get_contour_global_attrib_xld 得到轮廓趋近于什么属性如 线段,椭圆,圆等
split_contours_xld gen_polygons_xld 可以通过这个组合操作,得到自己想要的那部分轮廓,如只想要轮廓中的圆等等。
轮廓处理中很重要的一步,是抑制无关的轮廓,可以通过select_shape_xld(提供差不多30中形状特征)来完成。
通过制定单个或多个特征的最大值最小值,可以灵活的选择轮廓,select_contours_xld。
select_xld_point 用鼠标交互式选择轮廓。

如果轮廓有缺口裂缝,分裂的小块将被作为独立的对象,这位后续的处理增加了难度。
   union_collinear_contours_xld union_straight_contours_xld 合并线段
   union_adjacent_contours_xld union_cocircular_contours_xld union_cotangential_contours_xld 合并相邻轮廓

shape_trans_xld   With this operator you can, e.g., transform the contour into its surrounding circle, convex hull, or surrounding rectangle.

对于相交的轮廓
intersection_closed_contours_xld 两个轮廓的交叉部分。
difference_closed_contours_xld   两个轮廓不同的部分。
union2_closed_contours_xld  合并两个轮廓
3.Perform Fitting
With the operator fit_line_contour_xld you can determine the parameters of a line segment. The
operator provides different optimization methods, most of which are suppressing outliers. It returns the
coordinates of the start and the end point of the fitted line segment and the normal form of the line. To
visualize the results, you can use the operator gen_contour_polygon_xld.

To fit a rectangle into a contour, the operator fit_rectangle2_contour_xld can be used. It provides
various optimization methods as well. The returned parameters comprise mainly the center position, the
extent, and the orientation of the rectangle. To generate the obtained rectangle for a visualization, you
can use the operator gen_rectangle2_contour_xld.

For the fitting of circular and elliptic segments the operators fit_circle_contour_xld and
fit_ellipse_contour_xld are available. They also provide various optimization methods. For a
circular segment the center and the radius are returned together with the angle range of the visible part.

In addition, a second radius and the orientation of the main axis are returned for elliptic segments. To
visualize the results of both operators, you can use either the operator gen_ellipse_contour_xld or
the operator gen_circle_contour_xld.
4.Extract Features
HALCON offers various operators to access the feature values. Commonly used shape features are
calculated by area_center_xld, compactness_xld, convexity_xld, eccentricity_xld, di-
ameter_xld, and orientation_xld. The hulls of the contours can be determined with small-
est_circle_xld or smallest_rectangle2_xld. Features based on geometric moments are calcu-
lated, e.g., by moments_xld.
5.Convert And Access XLD Contours
Finally, it might be necessary to access the raw data of the contours or to convert contours into another
data type, e.g., into a region.
You can access the coordinates of the control points with the operator get_contour_xld. It returns
the row and column coordinates of all control points of a contour in two tuples of floating-point val-
ues. In case of a contour array (tuple), you must loop over all the contours and select each one using
select_obj.
To convert contours to regions, simply call the operator gen_region_contour_xld. The operator
paint_xld paints the contour with anti-aliasing into an image.
The operators for edge and line extraction not only return the XLD contours but also so-called
attributes. Attributes are numerical values; they are associated either with each control point
(called contour attribute) or with each contour as a whole (global contour attribute). The operators
get_contour_attrib_xld and get_contour_global_attrib_xld enable you to access these val-
ues by specifying the attribute name. More information on this topic can be found in the description of
the step Determine Contour Attributes on page 74.
例子:把轮廓分割成 线段和圆的形式 Example: solution_guide/basics/measure_metal_part.hdev
*****************************************************************************************
*    segment_contours_xld(Contours : ContoursSplit :
*                                            Mode,        List of values: 'lines', 'lines_circles', 'lines_ellipses'
*                                         SmoothCont, 如果>0,contours将做平滑处理,印制较小的分块,能更好的fit 圆和椭圆
*                                        MaxLineDist1, MaxLineDist2 : )
*    思路:edges_sub_pix 生成轮廓
*               select_obj获取单个轮廓
*                get_contour_global_attrib_xld获取该轮廓的属性,判断是线段还是圆
*        fit_circle_contour_xld  gen_ellipse_contour_xld 找出该轮廓最可能逼近的圆 生成圆
*        fit_line_contour_xld    gen_contour_polygon_xld 找出该轮廓最可能逼近的线段,生成线段。
*****************************************************************************************

read_image(Image,'metal-parts/metal-parts-01')
get_image_size(Image,Width,Height)

dev_update_window('off')
dev_close_window()
dev_open_window(0,0,Width,Height,'black',WindowID)
dev_display(Image)
* 提取轮廓
edges_sub_pix (Image, Edges, 'lanser2', 0.5, 40, 90)

segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 4, 2)
sort_contours_xld (ContoursSplit, SortedContours, 'upper_left', 'true', 'column')

count_obj(SortedContours,NumSegments)
NumCirCles :=0
NumLines :=0

for i :=1 to NumSegments by 1
    select_obj(SortedContours,SingleSegment,i)
    * Attrib = -1 线段 0 椭圆 1圆
    get_contour_global_attrib_xld(SingleSegment,'cont_approx',Attrib)
    if(Attrib =1)
        NumCirCles :=NumCirCles +1
        *对单个轮廓做 圆逼近
        fit_circle_contour_xld (SingleSegment, 'atukey', -1, 0, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
        *根据逼近结果生成一个圆轮廓
        gen_ellipse_contour_xld (ContEllipse, Row, Column, 0, Radius, Radius, 0, 6.28318, 'positive', 1.5)
        dev_set_color('white')
        dev_display(ContEllipse)
        set_tposition(WindowID,Row,Column)
        write_string(WindowID,'Circle'+NumCirCles)
        ResultText :='Cricle'+NumCirCles+':radius='+Radius
    else
        NumLines :=NumLines+1
        fit_line_contour_xld (SingleSegment, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)    
        gen_contour_polygon_xld (Line, [RowBegin,RowEnd], [ColBegin,ColEnd])     
        distance_pp(RowBegin,ColBegin,RowEnd,ColEnd,Length)
        dev_set_color('yellow')
        dev_display(Line)
        set_tposition(WindowID,(RowBegin + RowEnd)/2,(ColBegin +ColEnd)/2)
        write_string(WindowID,'Line'+NumLines)
        ResultText :='Line' + NumLines + ':Length=' + Length
    endif
    set_tposition(WindowID,300 +i*15,230)
    write_string(WindowID,ResultText)
endfor

例子 Close garp in a contour Example: solution_guide/basics/close_contour_gaps.hdev

dev_update_window('off')
dev_close_window()

*人为生成的一张图片,背景是是教深的灰度值,前景相对背景亮一点
*而且其中一部分做了中值处理。
gen_rectangle1 (Rectangle, 30, 20, 100, 100)
region_to_bin (Rectangle, BinImage, 130, 100, 120, 130)
rectangle1_domain(BinImage,ImageReduced,20,48,40,52)
mean_image(ImageReduced,SmoothedImage,15,15)
paint_gray(SmoothedImage,BinImage,Image)

*现在来找前景轮廓
*low = 22
*hight =30
*这两个值是梯度值,既边缘的梯度。本例中前景和背景的灰度差事30,既hight=30大于该值的
*边缘一直边缘,low=22 小于改值的边缘舍去,在此之间的边缘则看情况。
edges_sub_pix(Image,Edges,'lanser2',1.1,22,30)

*把轮廓分成 线段
segment_contours_xld (Edges, ContoursSplit, 'lines', 5, 4, 2)
*连接共线的 线段,达到封闭缺口的目的
union_collinear_contours_xld (ContoursSplit, UnionContours, 10, 1, 2, 0.1, 'attr_keep')

sort_contours_xld (UnionContours, SortedContours, 'upper_left', 'true', 'column')

dev_display(Image)

*依次显示线段 左上角 从左到右
count_obj(SortedContours,NumObjects)
Colors :=['yellow','white','white','yellow']
NumColors :=|Colors|
for i:=1 to NumColors by 1
    select_obj(SortedContours,Line,i)
    Color :=Colors[(i-1)%NumColors]
    dev_set_color(Color)
    dev_display(Line)
endfor

例子 航拍图像中的公路提取
Example: hdevelop/Applications/Object-Recognition-2D/roads.hdev

转载于:https://www.cnblogs.com/hu16683845/p/9454780.html

Contour Processing相关推荐

  1. OpenCV 1.x 2.x 编程简介(矩阵/图像/视频的基本读写操作)

    OpenCV 编程简介(矩阵/图像/视频的基本读写操作) Introduction to programming with OpenCV OpenCV编程简介 作者: Gady Agam Depart ...

  2. HALCON示例程序measure_metal_part_extended.hdev金属零件尺寸测量

    HALCON示例程序measure_metal_part_extended.hdev金属零件尺寸测量 示例程序源码(加注释) 关于显示类函数解释 dev_update_off () read_imag ...

  3. OpenCV 编程简单介绍(矩阵/图像/视频的基本读写操作)

    PS. 因为csdn博客文章长度有限制,本文有部分内容被截掉了. 在OpenCV中文站点的wiki上有可读性更好.而且是完整的版本号,欢迎浏览. OpenCV Wiki :<OpenCV 编程简 ...

  4. (4)图像增强- Part1. 对比度增强

    Image Enhancement 导读: 本章主要总结了图像增强技术中的点处理技术,包括灰度直方图的获取.直方图均衡化.直方图规范化和对比度调整等内容.C++和Python语言环境下,使用OpenC ...

  5. Halcon-边缘检测算子

    边缘检测的定义 :使用数学方法提取图像像元中具有亮度值(灰度)空间方向梯度大的边.线特征的过程. 边缘 是指周围像素灰度有阶跃变化或屋顶等变化的那些像素的集合.图像的边缘对应着图像灰度的不连续性.显然 ...

  6. opencv超好学习资料

    日志 返回日志列表 opencv超好学习资料 2010-9-25 13:40阅读(0) 赞赞赞赞 转载 分享 评论 复制地址 举报 编辑 上一篇 |下一篇:opencv安装方法 w... v首页 资讯 ...

  7. Image Processing and Computer Vision_Review:Local Invariant Feature Detectors: A Survey——2007.11...

    翻译 局部不变特征探测器:一项调查 摘要 -在本次调查中,我们概述了不变兴趣点探测器,它们如何随着时间的推移而发展,它们如何工作,以及它们各自的优点和缺点.我们首先定义理想局部特征检测器的属性.接下来 ...

  8. 温度场有限容积法程序入门之六:后处理.花絮.Contour Plotter and 3D Function Grapher Together - the Applet and the Souce Co

    2007年秋,开始接触数值计算,看到Contour图形,我觉得很神奇,很好看.一个师兄会,可是没教我,强烈的好奇心驱使下,零零碎碎看了相关文献,都看不懂.大约2009年深秋,我读到的最早且能看懂的关于 ...

  9. Image Processing and Analysis_8_Edge Detection:Finding Edges and Lines in Images by Canny——1983...

    此主要讨论图像处理与分析.虽然计算机视觉部分的有些内容比如特 征提取等也可以归结到图像分析中来,但鉴于它们与计算机视觉的紧密联系,以 及它们的出处,没有把它们纳入到图像处理与分析中来.同样,这里面也有 ...

最新文章

  1. oracle的乐观锁和悲观锁
  2. 外星人计算机产品介绍,你对外星人电脑了解吗?感兴趣快看看!
  3. BI 界震动 - Power BI Premium 个人版只要每月 120 元
  4. RBSP、SODB、EBSP三者的区别和联系 SPS: sequence parameter sets
  5. 【计算机网络复习】1.1.1 概念、组成、功能和分类
  6. 数据库表迁移到阿里云的方法有哪些
  7. 微信小程序 --- 音乐的播放和控制
  8. 贝叶斯概率推断(一):贝叶斯思维
  9. 【Java】Java语言程序设计(基础篇)全书笔记
  10. HTML5 九宫格拼图游戏
  11. 本地运行Flink-DIMAPP出现问题
  12. SLAM综述阅读笔记四:A Survey on Deep Learning for Localization and Mapping: Towards the Age of Spatial 2020
  13. Jetpack Room
  14. 提取动漫视频里的BGM
  15. Excel教学视频学习
  16. 抖音直播带货怎么选品?抖音直播选品的方法和技巧有哪些呢?
  17. 民间炒股高手绝招(转)
  18. Java 图片添加数字暗水印工具类
  19. P3380 【模板】二逼平衡树(树套树)
  20. 电壁挂炉,在南方城市销售火爆的原因分析

热门文章

  1. ikbc c104win键盘失灵以及数字键失灵
  2. Linux,你了解多少!
  3. 记笔记-文件记笔记方法
  4. Unity3D之简单AR游戏
  5. 物理学的困惑: 弦理论崛起了, 科学却衰落了
  6. 鼠标悬停字体抖动_快速提示:解决悬停状态下的字体粗细问题
  7. win7系统访问局域网中的wamp服务器
  8. 解决Macbook Pro蓝牙不可用问题
  9. Vue集成百度的Ueditor的前后端实现
  10. Unity 2D骨骼动画2:创建真实动画