【Halcon】 Halcon直线检测(LD)


dev_update_off ()  
dev_close_window () 
dev_open_window (0, 0, 800, 600, 'white', WindowHandle)  
dev_set_draw ('margin') 

read_image( Image,'fabrik')
*ROI
dev_display(Image)
draw_rectangle1(WindowHandle,row, col, Length1, length2)

rectangle1_domain(Image, ImageReduced, row, col, Length1, length2)
sobel_dir(ImageReduced,EdgeAmplitude,EdgeDirection,'sum_abs', 3)
dev_set_color('red')
threshold(EdgeAmplitude, Region, 55,255)
reduce_domain(EdgeDirection,Region,EdgeDirectionReduced)
hough_lines_dir( EdgeDirectionReduced,HoughImage, Lines, 4, 2, 'mean', 3, 25, 5, 5, 'true', Angle, Dist)
gen_region_hline(LinesHNF, Angle,Dist)

dev_display(LinesHNF)



* Detect lines in an image with the help of the Hough transform
* using the edge direction as additional information and return it both
* in HNF and as regions
* 
read_image (Image, 'fabrik')
rectangle1_domain (Image, ImageReduced, 170, 280, 310, 360)
* Detect edges (amplitude and direction) using the Sobel operator
sobel_dir (ImageReduced, EdgeAmplitude, EdgeDirection, 'sum_abs', 3)
dev_set_color ('red')
threshold (EdgeAmplitude, Region, 55, 255)
* Reduce the direction image to the edge region
reduce_domain (EdgeDirection, Region, EdgeDirectionReduced)
* Start the Hough transform using the edge direction information
hough_lines_dir (EdgeDirectionReduced, HoughImage, Lines, 4, 2, 'mean', 3, 25, 5, 5, 'true', Angle, Dist)
* Store input lines described in HNF
gen_region_hline (LinesHNF, Angle, Dist)
dev_display (Image)
dev_set_colored (12)
* Display the lines
dev_set_draw ('margin')
dev_display (LinesHNF)
* Display the edge pixels that contributed to the corresponding lines
dev_set_draw ('fill')
dev_display (Lines)

read_image (Image, 'fabrik')
rectangle1_domain (Image, ImageReduced, 230, 180, 330, 280)
* Detect edges (amplitude) using the Sobel operator
sobel_amp (ImageReduced, EdgeAmplitude, 'thin_sum_abs', 3)
dev_set_color ('red')
threshold (EdgeAmplitude, Region, 10, 255)
hough_lines (Region, 4, 50, 5, 5, Angle, Dist)
dev_set_color ('blue')
* Store input lines described in HNF
gen_region_hline (Regions, Angle, Dist)



dev_update_off ()    
dev_close_window ()   
dev_open_window (0, 0, 600, 400, 'white', WindowHandle)    
dev_set_draw ('margin')

read_image (Image, '01.bmp')  
dev_display(Image)
draw_rectangle1(WindowHandle, Row1, Column1, Row2, Column2)
rectangle1_domain (Image, ImageReduced,  Row1, Column1, Row2, Column2)

reduce_domain(Image,ImageReduced , ImageReduced1)
*从Image图像中裁剪一个矩形区域
crop_domain(ImageReduced1, ImageROI)

write_image (ImageROI, 'bmp', 0, '0')
dev_display(ImageROI)

smooth_image (ImageROI, ImageSmooth, 'gauss', 0.8)
dev_display(ImageSmooth)
draw_rectangle1(WindowHandle, Row21, Column21, Row22, Column22)
rectangle1_domain (ImageSmooth, ImageRe2,  Row21, Column21, Row22, Column22)

reduce_domain(ImageSmooth,ImageRe2 , ImageReRe2)
*从Image图像中裁剪一个矩形区域
*crop_domain(ImageReRe2, ImageROI2)
dev_display(ImageReRe2)

sobel_dir(ImageReRe2, EdgeAmplitude, EdgeDirection, 'sum_abs', 3)
dev_set_color('red')  
threshold(EdgeAmplitude, Region, 100,255)  
reduce_domain(EdgeDirection,Region,EdgeDirectionReduced)  
hough_lines_dir( EdgeDirectionReduced, HoughImage, Lines, 4, 2, 'mean', 3, 25, 5, 5, 'true', Angle, Dist)  
gen_region_hline(LinesHNF, Angle,Dist)  
  
dev_display(LinesHNF)


  • 1
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Halcon中的霍夫直线检测是一种图像处理算法,可以用来检测图像中的直线。它基于霍夫变换和阈值操作,通过寻找图像中的直线特征来实现直线检测。具体步骤如下: 1. 首先,使用read_image函数读取图像,并使用get_image_size函数获取图像的宽度和高度信息。 2. 使用dev_open_window函数打开一个窗口来显示图像。 3. 使用rectangle1_domain函数指定一个矩形区域,限定直线检测的范围。 4. 使用sobel_amp函数对图像进行边缘检测,得到边缘幅值。 5. 使用dev_set_color函数设置绘制对象的颜色。 6. 使用threshold函数对边缘图像进行阈值操作,得到二值化的边缘图像。 7. 使用hough_lines函数进行霍夫变换,检测图像中的直线,得到直线的角度和距离信息。 8. 使用dev_set_color函数设置绘制对象的颜色。 9. 使用gen_region_hline函数将检测到的直线转化为区域,方便后续处理。 10. 使用dev_display函数显示图像和检测到的直线区域。 11. 最后使用stop函数停止程序的执行。 以上是Halcon中霍夫直线检测的基本步骤。具体的参数设置和处理细节可以根据实际情况进行调整。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [halcon霍夫直线检测](https://blog.csdn.net/weixin_43491924/article/details/95973856)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [【Halcon】霍夫直线检测hough_lines](https://blog.csdn.net/Taily_Duan/article/details/51306128)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值