Reputation: 105
For below image, how to get the edge lines length and draw the fitting line of them. Any advice will be appreciated. Thanks.
Upvotes: 1
Views: 448
Reputation: 634
Probably, i'm bit late, but anyway. Here is my solution to that problem. It is not very accurate, but it works. To reach better accuracy you need more than one image. Code for 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)
The result:
Upvotes: 1