对于下图,如何获取边缘线长度并绘制它们的拟合线。任何建议将被认真考虑。谢谢。
问问题
363 次
1 回答
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)
结果:
于 2018-06-27T12:59:57.890 回答