Many thanks. If it is useful, here is the process from end to end using a clone of image.difference to image.sean_contour (please excuse the name which doesn’t really make sense…
- create a record in /src/micropython/stmhal/qstrdefsport.h which looks like this:
Q(sean_contours)
- create a prototype in /src/omv/img/imlib.h which looks like this:
void imlib_sean_contours(image_t *img, const char *file, image_t *other);
- create a function in /src/omv/img/imlib.c which looks like this (which is actually just difference() cloned:
void imlib_sean_contours(image_t *img, const char *file, image_t *other)
{
if (IM_IS_GS(img)) {
uint8_t *pixels = img->pixels;
if (file) {
} else {
uint8_t *other_pixels = other->pixels;
for (int i=0, j=img->w*img->h; i<j; i++) {
pixels[i] = abs(pixels[i] - other_pixels[i]);
}
}
} else {
uint16_t *pixels = (uint16_t *) img->pixels;
if (file) {
} else {
uint16_t *other_pixels = (uint16_t *) img->pixels;
for (int i=0, j=img->w*img->h; i<j; i++) {
const int pixel = pixels[i], other_pixel = other_pixels[i];
const int r = abs(IM_R565(pixel) - IM_R565(other_pixel));
const int g = abs(IM_G565(pixel) - IM_G565(other_pixel));
const int b = abs(IM_B565(pixel) - IM_B565(other_pixel));
pixels[i] = IM_RGB565(r, g, b);
}
}
}
}
- in /src/omv/py/py_image.c
Around line 400, add a line which looks like this (a clone of the python wrapper for difference()):
static mp_obj_t py_image_sean_contours(mp_obj_t img_obj, mp_obj_t other_obj)
{
image_t *arg_img = py_image_cobj(img_obj);
PY_ASSERT_FALSE_MSG(IM_IS_JPEG(arg_img),
"Operation not supported on JPEG");
if (MP_OBJ_IS_STR(other_obj)) {
imlib_sean_contours(arg_img, mp_obj_str_get_str(other_obj), NULL);
} else {
image_t *arg_other = py_image_cobj(other_obj);
PY_ASSERT_TRUE_MSG(IM_EQUAL(arg_img, arg_other),
"Invalid Argument: img_0_geometry != img_1_geometry");
imlib_sean_contours(arg_img, NULL, arg_other);
}
return mp_const_none;
}
- in py_image.c around line 1226 add a line which looks like this:
STATIC MP_DEFINE_CONST_FUN_OBJ_2(py_image_sean_contours_obj, py_image_sean_contours);
- in py_image.c in the dictionary map set starting with
static const mp_map_elem_t locals_dict_table[] = { ....
add a line like this:
{MP_OBJ_NEW_QSTR(MP_QSTR_sean_contours), (mp_obj_t)&py_image_sean_contours_obj},
-
rebuild - this generates an entry for sean_contour in
/src/build/micropython/genhdr/qstrdefs.generated.h and
… /qstrdefs.preprocessed.h
then assuming a successful build…
-
now upload using IDE
firmware updated, I can use image.sean_contour()