![Halcon慢慢来(边缘检测)_第1张图片](http://img.e-com-net.com/image/info8/247163f04f8f4edc9a6ce499bcf1a252.jpg)
![Halcon慢慢来(边缘检测)_第2张图片](http://img.e-com-net.com/image/info8/2d49ba5e4ddf497e83ed7bd7c2865a10.jpg)
read_image(Image,'data/flower')
rgb1_to_gray (Image, GrayImage)
sobel_amp(GrayImage,Amp,'sum_abs',3)
threshold(Amp,Edg,100,255)
skeleton (Edg, Skeleton)
dev_clear_window ()
dev_display (Skeleton)
![Halcon慢慢来(边缘检测)_第3张图片](http://img.e-com-net.com/image/info8/895d8989a3914cbba31605a529239c53.jpg)
sobel_amp(Imaqe : EdqeAmplitude : Fi1terType, Size : )
![Halcon慢慢来(边缘检测)_第4张图片](http://img.e-com-net.com/image/info8/f7d509e2dedd4cbd9bbf72982522bfc1.jpg)
![Halcon慢慢来(边缘检测)_第5张图片](http://img.e-com-net.com/image/info8/5f26813b5b034792b0e7a2a634a3c8af.jpg)
![Halcon慢慢来(边缘检测)_第6张图片](http://img.e-com-net.com/image/info8/1b6210f0b5f84d99a35c5987041bd561.jpg)
edges_image(Image : ImaAmp, ImaDir : Filter, Alpha, NMs, LoW, High :)
![Halcon慢慢来(边缘检测)_第7张图片](http://img.e-com-net.com/image/info8/cff1372009e940c785b44ac19c456fc9.jpg)
![在这里插入图片描述](http://img.e-com-net.com/image/info8/8348861082984e9497ae5a55e73f68a6.jpg)
![Halcon慢慢来(边缘检测)_第8张图片](http://img.e-com-net.com/image/info8/17a1a4b322a945da911f5847c18e92e3.jpg)
dev_close_window ()
read_image(Image,'data/flower')
rgb1_to_gray (Image, GrayImage)
gen_image_proto (Image, ImageCleared, 1)
dev_open_window (0, 0, 256, 256, 'black', WindowHandle1)
dev_open_window (0, 256, 256, 256, 'black', WindowHandle2)
dev_open_window (0, 512, 256, 256, 'black', WindowHandle3)
edges_image (GrayImage, ImaAmpGray, ImaDirGray, 'canny', 1, 'none', -1, -1)
edges_image (GrayImage, ImaAmpGrayNMS, ImaDirGrayHyst, 'canny', 1, 'nms',20, 40)
*对非极大值抑制后的边缘梯度图像进行了阈值处理
threshold (ImaAmpGrayNMS, RegionGray, 1, 255)
*提取边缘轮廓
skeleton (RegionGray, EdgesGray)
*用于结果显示和对比
dev_set_window (WindowHandle1)
dev_display (ImageCleared)
dev_display (ImaAmpGray)
dev_set_window (WindowHandle2)
dev_display (ImageCleared)
dev_display (ImaAmpGrayNMS)
dev_set_window (WindowHandle3)
dev_display (ImageCleared)
dev_display (EdgesGray)
![Halcon慢慢来(边缘检测)_第9张图片](http://img.e-com-net.com/image/info8/fd12c129ae9746efb1bd4891bc3dcbd9.jpg)
edges_color(Image : ImaAmp , ImaDir : Filter , Alpha , NMs , Low , High :)
![Halcon慢慢来(边缘检测)_第10张图片](http://img.e-com-net.com/image/info8/5e7e2c6540a748e6a2b886979f4fb7b7.jpg)
derivate_gauss (Image : DerivGauss : Sigma , component :)
![Halcon慢慢来(边缘检测)_第11张图片](http://img.e-com-net.com/image/info8/71f8d16989b34e128384d852d3ca84c0.jpg)
![Halcon慢慢来(边缘检测)_第12张图片](http://img.e-com-net.com/image/info8/6ad1c867e77241aab8f8581337397a86.jpg)
![Halcon慢慢来(边缘检测)_第13张图片](http://img.e-com-net.com/image/info8/6686cea59a214eb6adbbd3d1142fbc29.jpg)
laplace ( Image : ImageLaplace : ResultType , MaskSize , FilterMask :)
![Halcon慢慢来(边缘检测)_第14张图片](http://img.e-com-net.com/image/info8/903561e890894367b373197454d06eb5.jpg)
![Halcon慢慢来(边缘检测)_第15张图片](http://img.e-com-net.com/image/info8/f4b33461f8c84ba595e08d533c1ad87f.jpg)
read_image (Image, 'data/flower')
laplace (Image, ImageLaplace, 'signed', 11, 'n_8_isotropic')
zero_crossing (ImageLaplace, RegionCrossing)
![Halcon慢慢来(边缘检测)_第16张图片](http://img.e-com-net.com/image/info8/f730a559aee14e69a81b21d871bf43d6.jpg)
laplace_of_gauss ( Image : Imageaplace : Sigma :)
![Halcon慢慢来(边缘检测)_第17张图片](http://img.e-com-net.com/image/info8/e78b33c3a7474a59a4f9e1398d573baa.jpg)
![Halcon慢慢来(边缘检测)_第18张图片](http://img.e-com-net.com/image/info8/0592ee690a814e0198eb9c5dfeaaf681.jpg)
read_image (Image, 'data/flower')
laplace_of_gauss(Image,Laplace,2.0)
zero_crossing(Laplace,ZeroCrossings)
![Halcon慢慢来(边缘检测)_第19张图片](http://img.e-com-net.com/image/info8/442dd473392d4e68931604b0d42b7a74.jpg)
![Halcon慢慢来(边缘检测)_第20张图片](http://img.e-com-net.com/image/info8/9f07cb04fcd144cfae1ce83dc2529351.jpg)
edges_sub_pix ( Image : Edges , Filter , Alpha , Low , High :)
![Halcon慢慢来(边缘检测)_第21张图片](http://img.e-com-net.com/image/info8/0bdbcc35976240e88f9c1ff34e1744de.jpg)
![Halcon慢慢来(边缘检测)_第22张图片](http://img.e-com-net.com/image/info8/4641f92a72f74e51a267c3fb80ef969e.jpg)
![Halcon慢慢来(边缘检测)_第23张图片](http://img.e-com-net.com/image/info8/774d9ef9b9964ff4b594bf8da005617e.jpg)
read_image (Image, 'data/flower')
*转换为单通道灰色图像
rgb1_to_gray (Image, GrayImage)
*进行亚像素边缘提取。分别使用了不同的滞后阈值以便进行对比
edges_sub_pix (GrayImage, Edges1, 'lanser2', 0.5, 5, 50)
edges_sub_pix (GrayImage, Edges2, 'lanser2', 0.5, 25, 50)
edges_sub_pix (GrayImage, Edges3, 'lanser2', 0.5, 5, 25)
*将提取结果显示在窗口中
dev_display (Edges1)
stop()
dev_display (Edges2)
stop()
dev_display (Edges3)
![Halcon慢慢来(边缘检测)_第24张图片](http://img.e-com-net.com/image/info8/16722715703b439eb1f5e0d96f2c5aac.jpg)
![在这里插入图片描述](http://img.e-com-net.com/image/info8/26a74444a5ed4781a8b0c0d56e2cf342.jpg)
![Halcon慢慢来(边缘检测)_第25张图片](http://img.e-com-net.com/image/info8/2cf0625f9d0a4d3cb5d48ef491d14c16.jpg)
read_image (Image, 'data/flower')
*使用canny算子进行亚像素边缘提取
edges_color_sub_pix (Image, Edges1, 'canny', 0.5, 5, 50)
*使用canny算子进行亚像素边缘提取
edges_color_sub_pix (Image, Edges2, 'sobel_fast', 0.5, 40, 70)
dev_clear_window ()
dev_display (Edges1)
dev_display (Edges2)
![Halcon慢慢来(边缘检测)_第26张图片](http://img.e-com-net.com/image/info8/1fa6998b823a4ceb8976feeb36fd16c5.jpg)
lines_ gauss ( Image : Lines : Sigma , Low , High , LightDark , ExtractWidth, LineModel, CompleteJunetions : )
![Halcon慢慢来(边缘检测)_第27张图片](http://img.e-com-net.com/image/info8/9918f28ebb6b4aaf9eb1aca295ced81e.jpg)
![Halcon慢慢来(边缘检测)_第28张图片](http://img.e-com-net.com/image/info8/dd6ab9ac0433431ebdca2762e80ea444.jpg)
![Halcon慢慢来(边缘检测)_第29张图片](http://img.e-com-net.com/image/info8/94d7e2d68a6f42779012e2f2d358ff76.jpg)
read_image (Image, 'data/flower')
rgb1_to_gray (Image, GrayImage)
dev_open_window (0, 512, 512, 512, 'black', WindowHandle1)
*进行边缘检测
lines_gauss(GrayImage,Lines,1.5,1,8,'light','true','bar-shaped','true')
*在窗口将轮廓线条绘制出来
dev_set_color ('red')
dev_clear_window()
dev_display (Lines)
![Halcon慢慢来(边缘检测)_第30张图片](http://img.e-com-net.com/image/info8/930bd83a1f66441e9e3ca49295d76e5f.jpg)
![Halcon慢慢来(边缘检测)_第31张图片](http://img.e-com-net.com/image/info8/c02183681db141f8aa963ad54cce5831.jpg)
![Halcon慢慢来(边缘检测)_第32张图片](http://img.e-com-net.com/image/info8/86d07bdd0c4140ed9eea479cb0988d0b.jpg)
![Halcon慢慢来(边缘检测)_第33张图片](http://img.e-com-net.com/image/info8/8ea7f16dc3954c99bf2d4521f30d2651.jpg)
![Halcon慢慢来(边缘检测)_第34张图片](http://img.e-com-net.com/image/info8/9740e67a10fc458db6fecb18745cdf91.jpg)
![Halcon慢慢来(边缘检测)_第35张图片](http://img.e-com-net.com/image/info8/f2cdd9d864b44c4eac29026546d88adf.jpg)
dev_close_window ()
read_image (Image, 'data/shapes')
rgb1_to_gray (Image, GrayImage)
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width , Height, 'black', WindowHandle)
*提取出的亚像素边缘edge的图像,得到了一个初始的轮廓
edges_sub_pix (GrayImage, Edges, 'canny', 2.5, 15, 40)
*对上一步的轮廓进行分割
segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 4, 2)
*提取出轮廓中较长的部分线段
select_contours_xld (ContoursSplit, SelectedContours, 'contour_length', 20, Width / 2, -0.5, 0.5)
*对相邻的轮廓段进行连接
union_adjacent_contours_xld (SelectedContours, UnionContours, 20, 1, 'attr_keep')
![Halcon慢慢来(边缘检测)_第36张图片](http://img.e-com-net.com/image/info8/1562a7942a2d47e7a572fcac01456fbc.jpg)
![Halcon慢慢来(边缘检测)_第37张图片](http://img.e-com-net.com/image/info8/e8fb29a8c29143d2997d2f6c270ba2c7.jpg)
![Halcon慢慢来(边缘检测)_第38张图片](http://img.e-com-net.com/image/info8/e25fe1e3f9d64124a4a6b1f822a14e11.jpg)
![Halcon慢慢来(边缘检测)_第39张图片](http://img.e-com-net.com/image/info8/d6319fdb3c604661a843b9e497d8425b.jpg)
dev_close_window ()
*读取了图像并创建显示窗口
read_image (Image, 'data/flower')
rgb1_to_gray (Image, GrayImage)
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width , Height, 'black', WindowHandle)
dev_set_color ('white')
*对图像进行阈值处理
threshold (GrayImage, Region, 130, 255)
*使用闭运算进行填充
closing_circle (Region, Region, 20.5)
*获取前景目标的初始轮廓
gen_contour_region_xld (Region, Contour, 'border')
*拟合圆形轮廓
fit_circle_contour_xld (Contour, 'atukey', -1, 2, 0, 10, 1, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
*生成该拟合的圆形轮廓
gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, 4 * acos(0), 'positive', 1)
![Halcon慢慢来(边缘检测)_第40张图片](http://img.e-com-net.com/image/info8/0291c23424bd462c85dd34d46dc5850e.jpg)