Fixed bug in centroid and added tests.

Stuff works. Yay! Moving on to other things now.
This commit is contained in:
Kwabena W. Agyeman 2016-02-20 16:04:45 -05:00
parent 88d9c02a1b
commit 140ceb3b77
3 changed files with 79 additions and 4 deletions

View File

@ -366,8 +366,8 @@ int imlib_centroid(image_t *img, int *x_center, int *y_center, rectangle_t *r)
int y = (rect.y + i);
if(IM_GET_GS_PIXEL(img, x, y)) {
sum += 1;
x_center += x;
y_center += y;
x_sum += x;
y_sum += y;
}
}
}
@ -378,8 +378,8 @@ int imlib_centroid(image_t *img, int *x_center, int *y_center, rectangle_t *r)
int y = (rect.y + i);
if(IM_GET_RGB565_PIXEL(img, x, y)) {
sum += 1;
x_center += x;
y_center += y;
x_sum += x;
y_sum += y;
}
}
}

View File

@ -0,0 +1,31 @@
import pyb, sensor, image, math
sensor.reset()
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.GRAYSCALE)
low_threshold = (0, 50)
high_threshold = (205, 255)
while(True):
# Test low threshold
for i in range(100):
img = sensor.snapshot()
img.binary([low_threshold])
sum, x, y, rads = img.orientation_radians()
img.draw_keypoints([(x, y, rads)], color = 127, size = 20)
# Test high threshold
for i in range(100):
img = sensor.snapshot()
img.binary([high_threshold])
sum, x, y, rads = img.orientation_radians()
img.draw_keypoints([(x, y, rads)], color = 127, size = 20)
# Test not low threshold
for i in range(100):
img = sensor.snapshot()
img.binary([low_threshold], invert = 1)
sum, x, y, rads = img.orientation_radians()
img.draw_keypoints([(x, y, rads)], color = 127, size = 20)
# Test not high threshold
for i in range(100):
img = sensor.snapshot()
img.binary([high_threshold], invert = 1)
sum, x, y, rads = img.orientation_radians()
img.draw_keypoints([(x, y, rads)], color = 127, size = 20)

View File

@ -0,0 +1,44 @@
import pyb, sensor, image, math
sensor.reset()
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.RGB565)
red_threshold = (0,100, 0,127, 0,127) # L A B
green_threshold = (0,100, -128,0, 0,127) # L A B
blue_threshold = (0,100, -128,127, -128,0) # L A B
while(True):
# Test red threshold
for i in range(100):
img = sensor.snapshot()
img.binary([red_threshold])
sum, x, y, rads = img.orientation_radians()
img.draw_keypoints([(x, y, rads)], color = (255, 0, 0), size = 20)
# Test green threshold
for i in range(100):
img = sensor.snapshot()
img.binary([green_threshold])
sum, x, y, rads = img.orientation_radians()
img.draw_keypoints([(x, y, rads)], color = (0, 255, 0), size = 20)
# Test blue threshold
for i in range(100):
img = sensor.snapshot()
img.binary([blue_threshold])
sum, x, y, rads = img.orientation_radians()
img.draw_keypoints([(x, y, rads)], color = (0, 0, 255), size = 20)
# Test not red threshold
for i in range(100):
img = sensor.snapshot()
img.binary([red_threshold], invert = 1)
sum, x, y, rads = img.orientation_radians()
img.draw_keypoints([(x, y, rads)], color = (255, 0, 0), size = 20)
# Test not green threshold
for i in range(100):
img = sensor.snapshot()
img.binary([green_threshold], invert = 1)
sum, x, y, rads = img.orientation_radians()
img.draw_keypoints([(x, y, rads)], color = (0, 255, 0), size = 20)
# Test not blue threshold
for i in range(100):
img = sensor.snapshot()
img.binary([blue_threshold], invert = 1)
sum, x, y, rads = img.orientation_radians()
img.draw_keypoints([(x, y, rads)], color = (0, 0, 255), size = 20)