如何计算图像下方的边线距离?

时间:2017-02-08 07:19:06

标签: opencv image-processing halcon

对于下图,如何获得边线长度并绘制它们的拟合线。任何建议将被认真考虑。感谢。

enter image description here

1 个答案:

答案 0 :(得分:1)

可能我来晚了,但是无论如何。 这是我解决该问题的方法。 它不是很准确,但是可以。 为了获得更高的准确性,您需要多个图像。 HDevelop代码:

read_image (Image, 'D:/exp/test/1')
access_channel (Image, Image1, 1)



*find vertical lines
derivate_gauss (Image1, DerivGauss2, 1, 'x')
threshold (DerivGauss2, Region1, -255, -2)
connection (Region1, ConnectedRegions1)

*filter out redundant features
select_shape (ConnectedRegions1, SelectedRegions, ['rect2_len1','rectangularity'], 'and', [100,0.5], [99999,1])

*select rightmost edge
*this would be our reference line
area_center (SelectedRegions, Area, Row, Column)
tuple_sort_index (Column, Indices)
select_obj (SelectedRegions, ObjectSelected, Indices[|Indices|-1]+1)
skeleton (ObjectSelected, Skeleton)
smallest_rectangle2 (Skeleton, Row1, Column1, Phi, Length1, Length2)

*hide right side of the image based on that edge
Shift:=200
Row1Shift:=Row1-(cos(Phi)*Shift)
Column1Shift:=Column1-(sin(Phi)*Shift)
gen_rectangle2 (Rectangle, Row1Shift, Column1Shift, Phi, 999, 200)
complement (Rectangle, InspectionArea)


*find horizontal lines
derivate_gauss (Image1, DerivGauss, 1, 'y')
threshold (DerivGauss, Region, 5, 255)

*find shifted edges
intersection (Region, InspectionArea, RegionIntersection)
connection (RegionIntersection, ConnectedRegions)

*filter out redundant features
select_shape (ConnectedRegions, SelectedRegions1, ['inner_radius','rectangularity'], 'and', [2,0.5], [99999,1])


*print length
smallest_rectangle2 (SelectedRegions1, Row2, Column2, Phi1, Length11, Length21)
Row2Shift:=Row2+(sin(Phi)*Length11)
Column2Shift:=Column2+(cos(Phi)*Length11)
count_obj (SelectedRegions1, Number)

tuple_gen_sequence (0, (Number-1)*20, 20, Sequence)
dev_disp_text (Length11, 'window', Sequence, 0, 'black', [], [])
dev_set_color ('red')
skeleton (SelectedRegions1, Skeleton1)
dev_display(Skeleton1)

结果:

code result