mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Fixed set pixel.
This commit is contained in:
parent
a4ea3e0e20
commit
a035aae493
@ -214,22 +214,22 @@ static mp_obj_t py_image_get_pixel(mp_obj_t img_obj, mp_obj_t x_obj, mp_obj_t y_
|
||||
}
|
||||
}
|
||||
|
||||
static mp_obj_t py_image_set_pixel(mp_obj_t img_obj, mp_obj_t x_obj, mp_obj_t y_obj, mp_obj_t color_obj)
|
||||
static mp_obj_t py_image_set_pixel(uint n_args, const mp_obj_t *args)
|
||||
{
|
||||
image_t *arg_img = py_image_cobj(img_obj);
|
||||
image_t *arg_img = py_image_cobj(args[0]);
|
||||
PY_ASSERT_FALSE_MSG(IM_IS_JPEG(arg_img),
|
||||
"Operation not supported on JPEG");
|
||||
|
||||
int arg_x = mp_obj_get_int(x_obj);
|
||||
int arg_y = mp_obj_get_int(y_obj);
|
||||
int arg_x = mp_obj_get_int(args[1]);
|
||||
int arg_y = mp_obj_get_int(args[2]);
|
||||
if ((!IM_X_INSIDE(arg_img, arg_x)) || (!IM_Y_INSIDE(arg_img, arg_y))) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
if (IM_IS_GS(arg_img)) {
|
||||
IM_SET_GS_PIXEL(arg_img, arg_x, arg_y, mp_obj_get_int(color_obj));
|
||||
IM_SET_GS_PIXEL(arg_img, arg_x, arg_y, mp_obj_get_int(args[3]));
|
||||
} else {
|
||||
mp_obj_t *arg_color; mp_obj_get_array_fixed_n(color_obj, 3, &arg_color);
|
||||
mp_obj_t *arg_color; mp_obj_get_array_fixed_n(args[3], 3, &arg_color);
|
||||
int red = IM_R825(mp_obj_get_int(arg_color[0]));
|
||||
int green = IM_G826(mp_obj_get_int(arg_color[1]));
|
||||
int blue = IM_B825(mp_obj_get_int(arg_color[2]));
|
||||
|
||||
@ -2,6 +2,21 @@ import pyb, sensor, image
|
||||
sensor.reset()
|
||||
sensor.set_framesize(sensor.QVGA)
|
||||
while(True):
|
||||
# Test Set Pixel
|
||||
sensor.set_pixformat(sensor.GRAYSCALE)
|
||||
for i in range(10):
|
||||
img = sensor.snapshot()
|
||||
for j in range(100):
|
||||
x = (pyb.rng() % (2*img.width())) - (img.width()//2)
|
||||
y = (pyb.rng() % (2*img.height())) - (img.height()//2)
|
||||
img.set_pixel(x, y, 255)
|
||||
sensor.set_pixformat(sensor.RGB565)
|
||||
for i in range(10):
|
||||
img = sensor.snapshot()
|
||||
for j in range(100):
|
||||
x = (pyb.rng() % (2*img.width())) - (img.width()//2)
|
||||
y = (pyb.rng() % (2*img.height())) - (img.height()//2)
|
||||
img.set_pixel(x, y, (255, 255, 255))
|
||||
# Test Draw Line
|
||||
sensor.set_pixformat(sensor.GRAYSCALE)
|
||||
for i in range(10):
|
||||
|
||||
@ -3,19 +3,18 @@ sensor.reset()
|
||||
sensor.set_framesize(sensor.QVGA)
|
||||
# All drawing functions use the same code to pass color.
|
||||
# So we just need to test one function.
|
||||
# TODO: Why does MP need int(c) when c is computed using "//"?
|
||||
while(True):
|
||||
# Test Draw Line (GRAYSCALE)
|
||||
sensor.set_pixformat(sensor.GRAYSCALE)
|
||||
for i in range(10):
|
||||
img = sensor.snapshot()
|
||||
for i in range(img.width()):
|
||||
c = ((i * 255) + (img.width()/2)) // img.width()
|
||||
c = ((i * 255) + (img.width()/2)) / img.width()
|
||||
img.draw_line([i, 0, i, img.height()-1], int(c))
|
||||
sensor.snapshot()
|
||||
time.sleep(1000)
|
||||
for i in range(img.width()):
|
||||
c = (((img.width() - i) * 255) + (img.width()/2)) // img.width()
|
||||
c = (((img.width() - i) * 255) + (img.width()/2)) / img.width()
|
||||
img.draw_line([i, 0, i, img.height()-1], color = int(c))
|
||||
sensor.snapshot()
|
||||
time.sleep(1000)
|
||||
@ -24,12 +23,12 @@ while(True):
|
||||
for i in range(10):
|
||||
img = sensor.snapshot()
|
||||
for i in range(img.width()):
|
||||
c = ((i * 255) + (img.width()/2)) // img.width()
|
||||
c = ((i * 255) + (img.width()/2)) / img.width()
|
||||
img.draw_line([i, 0, i, img.height()-1], [int(c), 0, 0])
|
||||
sensor.snapshot()
|
||||
time.sleep(1000)
|
||||
for i in range(img.width()):
|
||||
c = (((img.width() - i) * 255) + (img.width()/2)) // img.width()
|
||||
c = (((img.width() - i) * 255) + (img.width()/2)) / img.width()
|
||||
img.draw_line([i, 0, i, img.height()-1], color = [int(c), 0, 0])
|
||||
sensor.snapshot()
|
||||
time.sleep(1000)
|
||||
@ -38,12 +37,12 @@ while(True):
|
||||
for i in range(10):
|
||||
img = sensor.snapshot()
|
||||
for i in range(img.width()):
|
||||
c = ((i * 255) + (img.width()/2)) // img.width()
|
||||
c = ((i * 255) + (img.width()/2)) / img.width()
|
||||
img.draw_line([i, 0, i, img.height()-1], [0, int(c), 0])
|
||||
sensor.snapshot()
|
||||
time.sleep(1000)
|
||||
for i in range(img.width()):
|
||||
c = (((img.width() - i) * 255) + (img.width()/2)) // img.width()
|
||||
c = (((img.width() - i) * 255) + (img.width()/2)) / img.width()
|
||||
img.draw_line([i, 0, i, img.height()-1], color = [0, int(c), 0])
|
||||
sensor.snapshot()
|
||||
time.sleep(1000)
|
||||
@ -52,12 +51,12 @@ while(True):
|
||||
for i in range(10):
|
||||
img = sensor.snapshot()
|
||||
for i in range(img.width()):
|
||||
c = ((i * 255) + (img.width()/2)) // img.width()
|
||||
c = ((i * 255) + (img.width()/2)) / img.width()
|
||||
img.draw_line([i, 0, i, img.height()-1], [0, 0, int(c)])
|
||||
sensor.snapshot()
|
||||
time.sleep(1000)
|
||||
for i in range(img.width()):
|
||||
c = (((img.width() - i) * 255) + (img.width()/2)) // img.width()
|
||||
c = (((img.width() - i) * 255) + (img.width()/2)) / img.width()
|
||||
img.draw_line([i, 0, i, img.height()-1], color = [0, 0, int(c)])
|
||||
sensor.snapshot()
|
||||
time.sleep(1000)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user