mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Add circle drawing
This commit is contained in:
parent
df5808b27d
commit
f1b524b520
@ -22,6 +22,11 @@
|
||||
__typeof__ (y) _y = (y); \
|
||||
src->data[_y*src->w+_x]; })
|
||||
|
||||
#define SET_PIXEL(src, x, y, c) \
|
||||
({ __typeof__ (x) _x = (x); \
|
||||
__typeof__ (y) _y = (y); \
|
||||
src->data[_y*src->w+_x]=c; })
|
||||
|
||||
#define MAX_GRAY_LEVEL (255)
|
||||
|
||||
/* RGB565->LAB lookup */
|
||||
@ -351,6 +356,35 @@ void imlib_draw_rectangle(struct image *image, struct rectangle *r)
|
||||
|
||||
}
|
||||
|
||||
void imlib_draw_circle(struct image *image, int cx, int cy, int r)
|
||||
{
|
||||
int x = r, y = 0;
|
||||
uint8_t c = 0xff;
|
||||
int radiusError = 1-x;
|
||||
if (cx+r >= image->w || cx-r < 0 ||
|
||||
cy+r >= image->h || cy-r < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
while(x >= y) {
|
||||
SET_PIXEL(image, x + cx, y + cy, c);
|
||||
SET_PIXEL(image, y + cx, x + cy, c);
|
||||
SET_PIXEL(image, -x + cx, y + cy, c);
|
||||
SET_PIXEL(image, -y + cx, x + cy, c);
|
||||
SET_PIXEL(image, -x + cx, -y + cy, c);
|
||||
SET_PIXEL(image, -y + cx, -x + cy, c);
|
||||
SET_PIXEL(image, x + cx, -y + cy, c);
|
||||
SET_PIXEL(image, y + cx, -x + cy, c);
|
||||
y++;
|
||||
if (radiusError<0) {
|
||||
radiusError += 2 * y + 1;
|
||||
} else {
|
||||
x--;
|
||||
radiusError+= 2 * (y - x + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void imlib_histeq(struct image *src)
|
||||
{
|
||||
int i, sum;
|
||||
|
||||
@ -207,6 +207,7 @@ void surf_dump_ipts(array_t *ipts);
|
||||
|
||||
void imlib_scale_image(struct image *src, struct image *dst);
|
||||
void imlib_draw_rectangle(struct image *image, struct rectangle *r);
|
||||
void imlib_draw_circle(struct image *image, int cx, int cy, int r);
|
||||
int imlib_image_mean(struct image *src);
|
||||
void imlib_subimage(struct image *src_img, struct image *dst_img, int x_off, int y_off);
|
||||
void imlib_blit(struct image *dst_img, struct image *src_img, int x_off, int y_off);
|
||||
|
||||
@ -103,6 +103,25 @@ mp_obj_t py_imlib_draw_rectangle(mp_obj_t image_obj, mp_obj_t rectangle_obj)
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t py_imlib_draw_circle(mp_obj_t image_obj, mp_obj_t c_obj, mp_obj_t r_obj)
|
||||
{
|
||||
int cx, cy, r;
|
||||
mp_obj_t *array;
|
||||
struct image *image;
|
||||
|
||||
/* get image pointer */
|
||||
image = py_image_cobj(image_obj);
|
||||
|
||||
/* center */
|
||||
array = mp_obj_get_array_fixed_n(c_obj, 2);
|
||||
cx = mp_obj_get_int(array[0]);
|
||||
cy = mp_obj_get_int(array[1]);
|
||||
|
||||
/* radius */
|
||||
r = mp_obj_get_int(r_obj);
|
||||
imlib_draw_circle(image, cx, cy, r);
|
||||
return mp_const_none;
|
||||
}
|
||||
mp_obj_t py_imlib_threshold(mp_obj_t image_obj, mp_obj_t color_obj, mp_obj_t threshold)
|
||||
{
|
||||
/* C stuff */
|
||||
@ -332,7 +351,7 @@ mp_obj_t py_imlib_surf_detector(mp_obj_t image_obj, mp_obj_t upright, mp_obj_t t
|
||||
|
||||
surf_t surf = {
|
||||
.upright=mp_obj_get_int(upright),
|
||||
.octaves=1,
|
||||
.octaves=5,
|
||||
.init_sample=2,
|
||||
.thresh=mp_obj_get_float(thresh),
|
||||
};
|
||||
@ -416,13 +435,13 @@ mp_obj_t py_imlib_init()
|
||||
rt_store_attr(m, qstr_from_str("histeq"), rt_make_function_n(1, py_imlib_histeq));
|
||||
rt_store_attr(m, qstr_from_str("median"), rt_make_function_n(2, py_imlib_median));
|
||||
rt_store_attr(m, qstr_from_str("draw_rectangle"), rt_make_function_n(2, py_imlib_draw_rectangle));
|
||||
rt_store_attr(m, qstr_from_str("draw_circle"), rt_make_function_n(3, py_imlib_draw_circle));
|
||||
rt_store_attr(m, qstr_from_str("threshold"), rt_make_function_n(3, py_imlib_threshold));
|
||||
rt_store_attr(m, qstr_from_str("count_blobs"), rt_make_function_n(1, py_imlib_count_blobs));
|
||||
rt_store_attr(m, qstr_from_str("detect_objects"), rt_make_function_n(2, py_imlib_detect_objects));
|
||||
rt_store_attr(m, qstr_from_str("surf_detector"), rt_make_function_n(3, py_imlib_surf_detector));
|
||||
rt_store_attr(m, qstr_from_str("surf_match"), rt_make_function_n(3, py_imlib_surf_match));
|
||||
rt_store_attr(m, qstr_from_str("surf_draw_ipts"), rt_make_function_n(2, py_imlib_surf_draw_ipts));
|
||||
rt_store_attr(m, qstr_from_str("surf_dump_ipts"), rt_make_function_n(1, py_imlib_surf_dump_ipts));
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user