diff --git a/src/omv/imlib/apriltag.c b/src/omv/imlib/apriltag.c index 3cdeabca6..72667eae4 100644 --- a/src/omv/imlib/apriltag.c +++ b/src/omv/imlib/apriltag.c @@ -11977,47 +11977,18 @@ void imlib_find_apriltags(list_t *out, image_t *ptr, rectangle_t *roi, apriltag_ apriltag_detector_add_family(td, (apriltag_family_t *) &artoolkit); } - uint8_t *grayscale_image = fb_alloc(roi->w * roi->h, FB_ALLOC_NO_HINT); + image_t img; + img.w = roi->w; + img.h = roi->h; + img.pixfmt = PIXFORMAT_GRAYSCALE; + img.data = fb_alloc(image_size(&img), FB_ALLOC_NO_HINT); + imlib_draw_image(&img, ptr, 0, 0, 1.f, 1.f, roi, -1, 256, NULL, NULL, 0, NULL, NULL); image_u8_t im; im.width = roi->w; im.height = roi->h; im.stride = roi->w; - im.buf = grayscale_image; - - switch (ptr->pixfmt) { - case PIXFORMAT_BINARY: { - for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) { - uint32_t *row_ptr = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(ptr, y); - for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) { - *(grayscale_image++) = COLOR_BINARY_TO_GRAYSCALE(IMAGE_GET_BINARY_PIXEL_FAST(row_ptr, x)); - } - } - break; - } - case PIXFORMAT_GRAYSCALE: { - for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) { - uint8_t *row_ptr = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(ptr, y); - for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) { - *(grayscale_image++) = IMAGE_GET_GRAYSCALE_PIXEL_FAST(row_ptr, x); - } - } - break; - } - case PIXFORMAT_RGB565: { - for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) { - uint16_t *row_ptr = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(ptr, y); - for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) { - *(grayscale_image++) = COLOR_RGB565_TO_GRAYSCALE(IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, x)); - } - } - break; - } - default: { - memset(grayscale_image, 0, roi->w * roi->h); - break; - } - } + im.buf = img.data; zarray_t *detections = apriltag_detector_detect(td, &im); list_init(out, sizeof(find_apriltags_list_lnk_data_t)); @@ -12104,9 +12075,9 @@ void imlib_find_rects(list_t *out, image_t *ptr, rectangle_t *roi, uint32_t thre // Frame Buffer Memory Usage... // -> GRAYSCALE Input Image = w*h*1 // -> GRAYSCALE Threhsolded Image = w*h*1 - // -> UnionFind = w*h*4 (+w*h*2 for hash table) + // -> UnionFind = w*h*2 (+w*h*1 for hash table) size_t resolution = roi->w * roi->h; - size_t fb_alloc_need = resolution * (1 + 1 + 4 + 2); // read above... + size_t fb_alloc_need = resolution * (1 + 1 + 2 + 2); // read above... umm_init_x(((fb_avail() - fb_alloc_need) / resolution) * resolution); apriltag_detector_t *td = apriltag_detector_create(); diff --git a/src/omv/imlib/dmtx.c b/src/omv/imlib/dmtx.c index e1e6c851b..c5c38a579 100644 --- a/src/omv/imlib/dmtx.c +++ b/src/omv/imlib/dmtx.c @@ -2764,7 +2764,7 @@ void Matrix3VMultFast(DmtxVector2 *vIn, DmtxMatrix3 m) { float w; float x, y; - + w = vIn->X*m[0][2] + vIn->Y*m[1][2] + m[2][2]; if(fabsf(w) <= DmtxAlmostZero) { vIn->X = FLT_MAX; @@ -3058,7 +3058,7 @@ GetPointFlow(DmtxDecode *dec, int colorPlane, DmtxPixelLoc loc, int arrive) int xAdjust, yAdjust; int color, colorPattern[8]; DmtxPointFlow flow; - + // check boundary conditions outside of the loop if (loc.X <= 0 || loc.Y <= 0 || loc.X >= dec->image->width-1 || loc.Y >= dec->image->height-1) return dmtxBlankEdge; // one or more pixels are past an edge @@ -6322,32 +6322,13 @@ void imlib_find_datamatrices(list_t *out, image_t *ptr, rectangle_t *roi, int ef dmtxDecodeSetProp(decode, DmtxPropXmax, ((ptr->pixfmt == PIXFORMAT_GRAYSCALE) ? roi->x : 0) + (roi->w - 1)); dmtxDecodeSetProp(decode, DmtxPropYmax, ((ptr->pixfmt == PIXFORMAT_GRAYSCALE) ? roi->y : 0) + (roi->h - 1)); - switch (ptr->pixfmt) { - case PIXFORMAT_BINARY: { - for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) { - uint32_t *row_ptr = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(ptr, y); - for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) { - *(grayscale_image++) = COLOR_BINARY_TO_GRAYSCALE(IMAGE_GET_BINARY_PIXEL_FAST(row_ptr, x)); - } - } - break; - } - case PIXFORMAT_GRAYSCALE: { - break; - } - case PIXFORMAT_RGB565: { - for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) { - uint16_t *row_ptr = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(ptr, y); - for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) { - *(grayscale_image++) = COLOR_RGB565_TO_GRAYSCALE(IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, x)); - } - } - break; - } - default: { - memset(grayscale_image, 0, roi->w * roi->h); - break; - } + if (ptr->pixfmt != PIXFORMAT_GRAYSCALE) { + image_t img; + img.w = roi->w; + img.h = roi->h; + img.pixfmt = PIXFORMAT_GRAYSCALE; + img.data = grayscale_image; + imlib_draw_image(&img, ptr, 0, 0, 1.f, 1.f, roi, -1, 256, NULL, NULL, 0, NULL, NULL); } list_init(out, sizeof(find_datamatrices_list_lnk_data_t)); diff --git a/src/omv/imlib/qrcode.c b/src/omv/imlib/qrcode.c index ef849d321..854069b04 100644 --- a/src/omv/imlib/qrcode.c +++ b/src/omv/imlib/qrcode.c @@ -2971,41 +2971,12 @@ void imlib_find_qrcodes(list_t *out, image_t *ptr, rectangle_t *roi) quirc_resize(controller, roi->w, roi->h); uint8_t *grayscale_image = quirc_begin(controller, NULL, NULL); - switch (ptr->pixfmt) { - case PIXFORMAT_BINARY: { - for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) { - uint32_t *row_ptr = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(ptr, y); - for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) { - *(grayscale_image++) = COLOR_BINARY_TO_GRAYSCALE(IMAGE_GET_BINARY_PIXEL_FAST(row_ptr, x)); - } - } - break; - } - case PIXFORMAT_GRAYSCALE: { - for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) { - uint8_t *row_ptr = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(ptr, y); - memcpy(grayscale_image, &row_ptr[roi->x], roi->w); - grayscale_image += roi->w; -// for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) { -// *(grayscale_image++) = IMAGE_GET_GRAYSCALE_PIXEL_FAST(row_ptr, x); -// } - } - break; - } - case PIXFORMAT_RGB565: { - for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) { - uint16_t *row_ptr = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(ptr, y); - for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) { - *(grayscale_image++) = COLOR_RGB565_TO_Y(IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, x)); - } - } - break; - } - default: { - memset(grayscale_image, 0, roi->w * roi->h); - break; - } - } + image_t img; + img.w = roi->w; + img.h = roi->h; + img.pixfmt = PIXFORMAT_GRAYSCALE; + img.data = grayscale_image; + imlib_draw_image(&img, ptr, 0, 0, 1.f, 1.f, roi, -1, 256, NULL, NULL, 0, NULL, NULL); quirc_end(controller); list_init(out, sizeof(find_qrcodes_list_lnk_data_t)); diff --git a/src/omv/imlib/zbar.c b/src/omv/imlib/zbar.c index 2cd8790b6..27d71b7ff 100644 --- a/src/omv/imlib/zbar.c +++ b/src/omv/imlib/zbar.c @@ -8732,32 +8732,13 @@ void imlib_find_barcodes(list_t *out, image_t *ptr, rectangle_t *roi) image.seq = 0; image.syms = 0; - switch (ptr->pixfmt) { - case PIXFORMAT_BINARY: { - for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) { - uint32_t *row_ptr = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(ptr, y); - for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) { - *(grayscale_image++) = COLOR_BINARY_TO_GRAYSCALE(IMAGE_GET_BINARY_PIXEL_FAST(row_ptr, x)); - } - } - break; - } - case PIXFORMAT_GRAYSCALE: { - break; - } - case PIXFORMAT_RGB565: { - for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) { - uint16_t *row_ptr = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(ptr, y); - for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) { - *(grayscale_image++) = COLOR_RGB565_TO_GRAYSCALE(IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, x)); - } - } - break; - } - default: { - memset(grayscale_image, 0, roi->w * roi->h); - break; - } + if (ptr->pixfmt != PIXFORMAT_GRAYSCALE) { + image_t img; + img.w = roi->w; + img.h = roi->h; + img.pixfmt = PIXFORMAT_GRAYSCALE; + img.data = grayscale_image; + imlib_draw_image(&img, ptr, 0, 0, 1.f, 1.f, roi, -1, 256, NULL, NULL, 0, NULL, NULL); } list_init(out, sizeof(find_barcodes_list_lnk_data_t)); diff --git a/src/omv/modules/py_image.c b/src/omv/modules/py_image.c index b6333b5af..0a351e464 100644 --- a/src/omv/modules/py_image.c +++ b/src/omv/modules/py_image.c @@ -4925,7 +4925,7 @@ static const mp_obj_type_t py_rect_type = { static mp_obj_t py_image_find_rects(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { - image_t *arg_img = py_helper_arg_to_image_mutable(args[0]); + image_t *arg_img = py_image_cobj(args[0]); rectangle_t roi; py_helper_keyword_rectangle_roi(arg_img, n_args, args, 1, kw_args, &roi); @@ -5091,7 +5091,7 @@ static const mp_obj_type_t py_qrcode_type = { static mp_obj_t py_image_find_qrcodes(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { - image_t *arg_img = py_helper_arg_to_image_mutable(args[0]); + image_t *arg_img = py_image_cobj(args[0]); rectangle_t roi; py_helper_keyword_rectangle_roi(arg_img, n_args, args, 1, kw_args, &roi); @@ -5474,7 +5474,7 @@ static const mp_obj_type_t py_datamatrix_type = { static mp_obj_t py_image_find_datamatrices(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { - image_t *arg_img = py_helper_arg_to_image_mutable(args[0]); + image_t *arg_img = py_image_cobj(args[0]); rectangle_t roi; py_helper_keyword_rectangle_roi(arg_img, n_args, args, 1, kw_args, &roi); @@ -5624,7 +5624,7 @@ static const mp_obj_type_t py_barcode_type = { static mp_obj_t py_image_find_barcodes(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { - image_t *arg_img = py_helper_arg_to_image_mutable(args[0]); + image_t *arg_img = py_image_cobj(args[0]); rectangle_t roi; py_helper_keyword_rectangle_roi(arg_img, n_args, args, 1, kw_args, &roi);