halcon延长线段,获取直线交点

halcon延长线段,获取直线交点

* 图像增强
mult_image (ImageB, ImageB, ImageResult4, 0.005, 0)
* 图像增强
emphasize (ImageResult4, ImageEmphasize1, 7, 7, 1)
* 阈值分割(分割出整块板)
threshold (ImageEmphasize1, Region3, 0, 10)
* 闭操作
closing_rectangle1 (Region3, RegionClosing3, 100, 100)
* 填充
fill_up (RegionClosing3, RegionClosing3)
* 开操作
opening_rectangle1 (RegionClosing3, RegionOpening3, 200, 200)
* 连通
connection (RegionOpening3, ConnectedRegions2)
* 选择面积最大的区域(选出整块板子)
select_shape_std (ConnectedRegions2, SelectedRegions5, 'max_area', 70)
* 获取外接矩形坐标(用于获取左上角点,进行生成仿射变换矩阵)
smallest_rectangle1 (SelectedRegions5, Row11, Column11, Row2, Column2)
* 生成矩形
gen_rectangle1 (Rectangle, Row11, Column11, Row2, Column2)

* 获取板子的矩形边缘轮廓
boundary (SelectedRegions5, RegionBorder, 'inner')
* 生成十字叉(获取板子内接矩形的左上角点)
gen_cross_contour_xld (Cross1, Row11, Column11, 60, 0)
* 生成硬矩形区域
gen_rectangle1 (ROI_0, -697.79, 2029.74, 2227.98, 4042.85)
* 交集(获取板子上边缘线)
intersection (ROI_0, RegionBorder, RegionIntersection1)
* 获取区域方向(获取上边缘线的角度)
orientation_region (RegionIntersection1, Phi1)
* 直线
gen_contour_region_xld (RegionIntersection1, Contours2, 'center')
get_contour_xld (Contours2, Row17, Col2)
* gen_region_line (RegionLines2, Row17[0], Col2[0],  Row17[|Row17|-1], Col2[|Col2|-1])
* 左点
RowBegin := min(Row17)
ColBegin:=min(Col2)

* gen_cross_contour_xld (Cross7, RowBegin, ColBegin, 600, Phi1)
* 右点
RowEnd :=max(Row17)
ColEnd :=max(Col2)
* gen_cross_contour_xld (Cross6, RowEnd, ColEnd, 600, Phi1)
if (RowEnd-RowBegin==0)
    k:=0
    gen_contour_polygon_xld (Contour2,[RowEnd,RowEnd], [0,Width])
else
    k:=(ColEnd-ColBegin) /(RowEnd-RowBegin) 
    b:=(ColEnd-k*RowEnd)
    RowBegin:=0
    RowEnd:=Height-1
    ColBegin:=k*RowBegin+b
    ColEnd:=k*RowEnd+b
    gen_contour_polygon_xld (Contour2,[RowBegin,RowEnd], [ColBegin,ColEnd])
endif




gen_rectangle1 (ROI_2, 2614, 152, 4500, 2093)
* 交集(获取板子上边缘线)
intersection (ROI_2, RegionBorder, RegionIntersection2)


gen_contour_region_xld (RegionIntersection2, Contours3, 'center')

fit_line_contour_xld (Contours3, 'tukey', -1, 0, 5, 2, RowBegin1, ColBegin1, RowEnd1, ColEnd1, Nr, Nc, Dist)

get_contour_xld (Contours3, Row18, Col3)

RowBegin2 := min(Row18)
ColBegin2:=min(Col3)
gen_cross_contour_xld (Cross6, RowBegin2, ColBegin2, 600, Phi1)
RowEnd2 :=max(Row18)
ColEnd2 :=max(Col3)
gen_cross_contour_xld (Cross7, RowEnd2, ColEnd2, 600, Phi1)


if (RowEnd2-RowBegin2==0)
    k:=0
    gen_contour_polygon_xld (Contour2,[RowEnd2,RowEnd2], [0,Width])
else
    * 斜率
    k:=(ColEnd2-ColBegin2) /(ColEnd2-RowBegin2) 
    * b
    b:=(ColEnd2-k*RowEnd2)
    * 起始y
    RowBegin2:=0
    * 结束y
    RowEnd2:=Height-1
    * 起始x
    ColBegin2:=k*RowBegin2+b
    * 结束x
    ColEnd2:=k*RowEnd2+b
    gen_contour_polygon_xld (Contour3,[RowBegin2,RowEnd2], [ColBegin2,ColEnd2])
endif

intersection_lines (RowBegin, ColBegin, RowEnd, ColEnd, RowBegin2, ColBegin2, RowEnd2, ColEnd2, Row16, Column14, IsOverlapping)


gen_cross_contour_xld (Cross5, Row16, Column14, 600, Phi1)

在这里插入图片描述

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值