Skip to content

Commit c407eb4

Browse files
committed
fixed accumulation, added line param calc
1 parent 3c0eed4 commit c407eb4

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

pclines.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ def normalizers():
5858
ofs = (d-ranges) / 2
5959
(x0,y0),(x1,y1) = ofs, (ranges-1)+ofs
6060
print(bbox)
61-
norm0 = Normalizer((y,y+h), (y0, y1))
61+
norm0 = Normalizer((y,y+h), (y1, y0))
6262
norm1 = Normalizer((x,x+w), (x0, x1))
63-
norm2 = Normalizer((y,y+h), (y1, y0))
63+
norm2 = Normalizer((y,y+h), (y0, y1))
6464
return norm0, norm1, norm2
6565

6666
norm0, norm1, norm2 = normalizers()
@@ -71,7 +71,7 @@ def normalizers():
7171
norm2(x[:,1])
7272
]
7373

74-
for a,b,c in zip(*x):
74+
for a,b,c in zip(*x): # remove space wraping
7575
t_part = np.linspace(a,b,d)
7676
s_part = np.linspace(b,c,d)
7777
c = np.arange(2*d-1,dtype="i")
@@ -82,19 +82,28 @@ def normalizers():
8282
return A
8383

8484

85-
def lines_parameters(shape, d, peaks):
86-
P = [u,v]
85+
def lines_parameters(peaks, d, bbox):
86+
u = peaks[:,1]
87+
v = peaks[:,0]
88+
8789
#centrovanie
8890
u = u - (d - 1)
91+
92+
x,y,w,h = bbox
93+
shape = w,h
8994
m = max(shape) - 1
9095
normV = Normalizer((0,d-1),(-m/2, m/2))
91-
v = normV.transform(v)
96+
v = normV(v)
97+
98+
f = u < 0
99+
100+
l = np.array([f*(d+u)+(1-f)*(d-u), u, -v*d], "f").T
101+
102+
tx,ty = x+0.5*w, y+0.5*h
92103

93-
if (u < d):
94-
l = [d-u, u, -v*d]
95-
else:
96-
l = [d+u, u, -v*d]
104+
l[:,2] -= l[:,0]*tx + l[:,1]*ty
97105

106+
return l
98107

99108

100109

@@ -115,9 +124,9 @@ def lines_parameters(shape, d, peaks):
115124

116125
def find_peaks(A, t):
117126
prominence = dilation(A+1)/erosion(A+1)
118-
peaks = peak_local_max(A, threshold_abs=t)
119-
c,r = peaks[:,0], peaks[:,1]
127+
peaks = peak_local_max(A, threshold_abs=t, min_distance=1)
128+
r,c = peaks[:,0], peaks[:,1]
120129
value = A[r,c]
121-
valid = prominence[r,c] > 1.5
130+
valid = prominence[r,c] > 1.3
122131
return peaks[valid], value[valid]
123132

0 commit comments

Comments
 (0)