Debugging similar angles

This commit is contained in:
Pieter Holtzhausen
2011-08-20 11:15:50 +02:00
parent 9ed82321c0
commit e5ddf85907
+16 -11
View File
@@ -77,8 +77,7 @@ def _probabilistic_hough(np.ndarray img, int value_threshold, int line_length, \
# calculate thetas if none specified
if theta is None:
theta = np.linspace(math.pi/2, -math.pi/2, 180)
p_2 = math.pi/2
theta = p_2-np.arange(180)/180.0*p_2*2
theta = math.pi/2-np.arange(180)/180.0* math.pi
ctheta = np.cos(theta)
stheta = np.sin(theta)
cdef int height = img.shape[0]
@@ -113,6 +112,7 @@ def _probabilistic_hough(np.ndarray img, int value_threshold, int line_length, \
for i in range(num_indexes):
mask[y_idxs[i], x_idxs[i]] = 1
settle = 0
print
while 1:
# select random non-zero point
count = len(points)
@@ -125,6 +125,7 @@ def _probabilistic_hough(np.ndarray img, int value_threshold, int line_length, \
# if previously eliminated, skip
if not mask[y, x]:
continue
print "select", y, x
value = 0
max_value = value_threshold-1
max_theta = -1
@@ -135,18 +136,22 @@ def _probabilistic_hough(np.ndarray img, int value_threshold, int line_length, \
accum[accum_idx, j] += 1
value = accum[accum_idx, j]
if value > max_value:
print "max", j, value
max_value = value
max_theta = j
# if two max angles are very similar, extend the threshold for a while
if j != max_theta and value == max_value and abs(j - max_theta) == 1:
settle += 1
if settle > 100:
other_max = 0
else:
other_max = 1
# if two bordering angles have max values, extend the threshold for a while
if j != max_theta and value == max_value:
if abs(j - max_theta) <= 2:
if settle > 100:
other_max = 0
else:
other_max = 1
if j == 134 or j == 135:
print j, value, accum_idx, ctheta[j], stheta[j]
if max_value < value_threshold or other_max:
continue
settle = 0
print "THETA", max_theta, max_value
# from the random point walk in opposite directions and find line beginning and end
a = -stheta[max_theta]
b = ctheta[max_theta]
@@ -160,14 +165,14 @@ def _probabilistic_hough(np.ndarray img, int value_threshold, int line_length, \
else:
dx0 = -1
dy0 = <int>round(b * (1 << shift) / fabs(a))
y0 = (y0 << shift) #+ (1 << (shift - 1))
y0 = (y0 << shift) + (1 << (shift - 1))
else:
if b > 0:
dy0 = 1
else:
dy0 = -1
dx0 = <int>round(a * (1 << shift) / fabs(b))
x0 = (x0 << shift) #+ (1 << (shift - 1))
x0 = (x0 << shift) + (1 << (shift - 1))
# pass 1: walk the line, merging lines less than specified gap length
for k in range(2):