#define EDGE_COUNT_THRESHOLD 15 // 跳变个数阈值
static mp_obj_t py_image_in_place_detection(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
int result = 0;
image_t \*arg_img = py_image_cobj(args\[0\]);
printf("1111111");
mp_obj_list_t \*roi_list = MP_OBJ_TO_PTR(args\[1\]);
int x = mp_obj_get_int(roi_list->items\[0\]);
int y = mp_obj_get_int(roi_list->items\[1\]);
int w = mp_obj_get_int(roi_list->items\[2\]);
int h = mp_obj_get_int(roi_list->items\[3\]);
if (w <= 0 || h <= 0 || x < 0 || y < 0) {
printf("result: 0 (invalid roi)\\n");
return mp_obj_new_int(0);
}
int img_width = arg_img->w;
uint8_t \*base = (uint8_t \*)arg_img->pixels;
int edge_count = 0;
for (int yy = 0; yy < h; yy++) {
uint8_t \*row_ptr = base + (y + yy) \* img_width;
int last_pix = -1;
for (int xx = 0; xx < w; xx++) {
int pix = imlib_get_pixel_fast(arg_img, row_ptr, x + xx);
if (last_pix != -1 && pix != last_pix) {
edge_count++;
}
last_pix = pix;
}
}
// 纵向跳变
for (int xx = 0; xx < w; xx++) {
int last_pix = -1;
int px = x + xx;
for (int yy = 0; yy < h; yy++) {
uint8_t \*row_ptr = base + (y + yy) \* img_width;
int pix = imlib_get_pixel_fast(arg_img, row_ptr, px);
if (last_pix != -1 && pix != last_pix) {
edge_count++;
}
last_pix = pix;
}
}
result = (edge_count > EDGE_COUNT_THRESHOLD) ? 1 : 0;
return mp_obj_new_int(result);
}
static MP_DEFINE_CONST_FUN_OBJ_KW(py_image_in_place_detection_obj, 1, py_image_in_place_detection);
{MP_ROM_QSTR(MP_QSTR_in_place_detection), MP_ROM_PTR(&py_image_in_place_detection_obj)},
QDEF1(MP_QSTR_in_place_detection, 28662, 18, “in_place_detection”)
That means you corrupted memory or crashed the program, you kind of need to debug your own C code. We don’t provide help support for that.
See the tutorial on this for how to use a debugger: 10. Building, flashing, and debugging the firmware - OpenMV MicroPython 1.28 documentation