mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Fixed bug in centroid and added tests.
Stuff works. Yay! Moving on to other things now.
This commit is contained in:
parent
88d9c02a1b
commit
140ceb3b77
@ -366,8 +366,8 @@ int imlib_centroid(image_t *img, int *x_center, int *y_center, rectangle_t *r)
|
|||||||
int y = (rect.y + i);
|
int y = (rect.y + i);
|
||||||
if(IM_GET_GS_PIXEL(img, x, y)) {
|
if(IM_GET_GS_PIXEL(img, x, y)) {
|
||||||
sum += 1;
|
sum += 1;
|
||||||
x_center += x;
|
x_sum += x;
|
||||||
y_center += y;
|
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);
|
int y = (rect.y + i);
|
||||||
if(IM_GET_RGB565_PIXEL(img, x, y)) {
|
if(IM_GET_RGB565_PIXEL(img, x, y)) {
|
||||||
sum += 1;
|
sum += 1;
|
||||||
x_center += x;
|
x_sum += x;
|
||||||
y_center += y;
|
y_sum += y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
31
usr/tests/test_binary_1.py
Normal file
31
usr/tests/test_binary_1.py
Normal 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)
|
||||||
44
usr/tests/test_binary_2.py
Normal file
44
usr/tests/test_binary_2.py
Normal 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)
|
||||||
Loading…
Reference in New Issue
Block a user