Wrap long lines

This commit is contained in:
Tony S Yu
2012-05-08 21:28:49 -04:00
parent f8e0478542
commit ae85fa8b15
3 changed files with 17 additions and 7 deletions
+8 -3
View File
@@ -163,7 +163,8 @@ def match_template(np.ndarray[float, ndim=2, mode="c"] image,
np.ndarray[float, ndim=2, mode="c"] template, int num_type):
# convolve the image with template by frequency domain multiplication
cdef np.ndarray[np.double_t, ndim=2] result
result = np.ascontiguousarray(fftconvolve(image, np.fliplr(template), mode="valid"), dtype=np.double)
result = np.ascontiguousarray(fftconvolve(image, np.fliplr(template),
mode="valid"), dtype=np.double)
# calculate squared integral images used for normalization
cdef np.ndarray[np.double_t, ndim=2, mode="c"] integral_sum
cdef np.ndarray[np.double_t, ndim=2, mode="c"] integral_sqr
@@ -193,12 +194,16 @@ def match_template(np.ndarray[float, ndim=2, mode="c"] image,
num = result[i, j]
window_mean2 = 0
if num_type == 1:
t = sum_integral(integral_sum, i, j, i + template.shape[0], j + template.shape[1])
t = sum_integral(integral_sum, i, j,
i + template.shape[0],
j + template.shape[1])
window_mean2 = t * t * inv_area
num -= t*template_mean
# calculate squared template window sum in the image
window_sum2 = sum_integral(integral_sqr, i, j, i + template.shape[0], j + template.shape[1])
window_sum2 = sum_integral(integral_sqr, i, j,
i + template.shape[0],
j + template.shape[1])
normed = sqrt(window_sum2 - window_mean2) * template_norm
# enforce some limits
if fabs(num) < normed:
+5 -2
View File
@@ -20,10 +20,13 @@ def match_template_cv(image, template, out=None, method="norm-coeff"):
Returns
-------
output : ndarray, dtype=float
Correlation results between 0.0 and 1.0, maximum indicating the most probable match.
Correlation results between 0.0 and 1.0, maximum indicating the most
probable match.
"""
if out == None:
out = np.empty((image.shape[0] - template.shape[0] + 1,image.shape[1] - template.shape[1] + 1), dtype=image.dtype)
out = np.empty((image.shape[0] - template.shape[0] + 1,
image.shape[1] - template.shape[1] + 1),
dtype=image.dtype)
if method == "norm-corr":
cv.MatchTemplate(image, template, out, cv.CV_TM_CCORR_NORMED)
elif method == "norm-corr":
+4 -2
View File
@@ -23,7 +23,8 @@ def test_template():
if not found_positions:
found_positions.append((x, y))
for position in found_positions:
distance = np.sqrt((x - position[0]) ** 2 + (y - position[1]) ** 2)
distance = np.sqrt((x - position[0]) ** 2 +
(y - position[1]) ** 2)
if distance > delta:
found_positions.append((x, y))
result[y, x] = 0
@@ -34,7 +35,8 @@ def test_template():
print x, y
found = False
for position in found_positions:
distance = np.sqrt((x - position[0]) ** 2 + (y - position[1]) ** 2)
distance = np.sqrt((x - position[0]) ** 2 +
(y - position[1]) ** 2)
if distance < delta:
found = True
assert found