mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Add mask functionality to clear.
This commit is contained in:
parent
1f72c3750d
commit
954431ef52
@ -6,51 +6,6 @@
|
|||||||
#include "imlib.h"
|
#include "imlib.h"
|
||||||
|
|
||||||
#ifdef IMLIB_ENABLE_BINARY_OPS
|
#ifdef IMLIB_ENABLE_BINARY_OPS
|
||||||
void imlib_zero(image_t *img, image_t *mask, bool invert)
|
|
||||||
{
|
|
||||||
switch(img->bpp) {
|
|
||||||
case IMAGE_BPP_BINARY: {
|
|
||||||
for (int y = 0, yy = img->h; y < yy; y++) {
|
|
||||||
uint32_t *row_ptr = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(img, y);
|
|
||||||
uint32_t *row_ptr_2 = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(mask, y);
|
|
||||||
for (int x = 0, xx = img->w; x < xx; x++) {
|
|
||||||
if (IMAGE_GET_BINARY_PIXEL_FAST(row_ptr_2, x) ^ invert) {
|
|
||||||
IMAGE_PUT_BINARY_PIXEL_FAST(row_ptr, x, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case IMAGE_BPP_GRAYSCALE: {
|
|
||||||
for (int y = 0, yy = img->h; y < yy; y++) {
|
|
||||||
uint8_t *row_ptr = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(img, y);
|
|
||||||
uint32_t *row_ptr_2 = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(mask, y);
|
|
||||||
for (int x = 0, xx = img->w; x < xx; x++) {
|
|
||||||
if (IMAGE_GET_BINARY_PIXEL_FAST(row_ptr_2, x) ^ invert) {
|
|
||||||
IMAGE_PUT_GRAYSCALE_PIXEL_FAST(row_ptr, x, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case IMAGE_BPP_RGB565: {
|
|
||||||
for (int y = 0, yy = img->h; y < yy; y++) {
|
|
||||||
uint16_t *row_ptr = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(img, y);
|
|
||||||
uint32_t *row_ptr_2 = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(mask, y);
|
|
||||||
for (int x = 0, xx = img->w; x < xx; x++) {
|
|
||||||
if (IMAGE_GET_BINARY_PIXEL_FAST(row_ptr_2, x) ^ invert) {
|
|
||||||
IMAGE_PUT_RGB565_PIXEL_FAST(row_ptr, x, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void imlib_binary(image_t *out, image_t *img, list_t *thresholds, bool invert, bool zero, image_t *mask)
|
void imlib_binary(image_t *out, image_t *img, list_t *thresholds, bool invert, bool zero, image_t *mask)
|
||||||
{
|
{
|
||||||
image_t bmp;
|
image_t bmp;
|
||||||
@ -62,7 +17,6 @@ void imlib_binary(image_t *out, image_t *img, list_t *thresholds, bool invert, b
|
|||||||
for (list_lnk_t *it = iterator_start_from_head(thresholds); it; it = iterator_next(it)) {
|
for (list_lnk_t *it = iterator_start_from_head(thresholds); it; it = iterator_next(it)) {
|
||||||
color_thresholds_list_lnk_data_t lnk_data;
|
color_thresholds_list_lnk_data_t lnk_data;
|
||||||
iterator_get(thresholds, it, &lnk_data);
|
iterator_get(thresholds, it, &lnk_data);
|
||||||
|
|
||||||
switch(img->bpp) {
|
switch(img->bpp) {
|
||||||
case IMAGE_BPP_BINARY: {
|
case IMAGE_BPP_BINARY: {
|
||||||
for (int y = 0, yy = img->h; y < yy; y++) {
|
for (int y = 0, yy = img->h; y < yy; y++) {
|
||||||
|
|||||||
@ -755,6 +755,48 @@ void imlib_save_image(image_t *img, const char *path, rectangle_t *roi, int qual
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void imlib_zero(image_t *img, image_t *mask, bool invert)
|
||||||
|
{
|
||||||
|
switch(img->bpp) {
|
||||||
|
case IMAGE_BPP_BINARY: {
|
||||||
|
for (int y = 0, yy = img->h; y < yy; y++) {
|
||||||
|
uint32_t *row_ptr = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(img, y);
|
||||||
|
for (int x = 0, xx = img->w; x < xx; x++) {
|
||||||
|
if (image_get_mask_pixel(mask, x, y) ^ invert) {
|
||||||
|
IMAGE_PUT_BINARY_PIXEL_FAST(row_ptr, x, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case IMAGE_BPP_GRAYSCALE: {
|
||||||
|
for (int y = 0, yy = img->h; y < yy; y++) {
|
||||||
|
uint8_t *row_ptr = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(img, y);
|
||||||
|
for (int x = 0, xx = img->w; x < xx; x++) {
|
||||||
|
if (image_get_mask_pixel(mask, x, y) ^ invert) {
|
||||||
|
IMAGE_PUT_GRAYSCALE_PIXEL_FAST(row_ptr, x, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case IMAGE_BPP_RGB565: {
|
||||||
|
for (int y = 0, yy = img->h; y < yy; y++) {
|
||||||
|
uint16_t *row_ptr = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(img, y);
|
||||||
|
for (int x = 0, xx = img->w; x < xx; x++) {
|
||||||
|
if (image_get_mask_pixel(mask, x, y) ^ invert) {
|
||||||
|
IMAGE_PUT_RGB565_PIXEL_FAST(row_ptr, x, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// A simple algorithm for correcting lens distortion.
|
// A simple algorithm for correcting lens distortion.
|
||||||
// See http://www.tannerhelland.com/4743/simple-algorithm-correcting-lens-distortion/
|
// See http://www.tannerhelland.com/4743/simple-algorithm-correcting-lens-distortion/
|
||||||
void imlib_lens_corr(image_t *img, float strength, float zoom)
|
void imlib_lens_corr(image_t *img, float strength, float zoom)
|
||||||
|
|||||||
@ -1251,6 +1251,7 @@ void imlib_edge_canny(image_t *src, rectangle_t *roi, int low_thresh, int high_t
|
|||||||
void imlib_find_hog(image_t *src, rectangle_t *roi, int cell_size);
|
void imlib_find_hog(image_t *src, rectangle_t *roi, int cell_size);
|
||||||
|
|
||||||
// Helper Functions
|
// Helper Functions
|
||||||
|
void imlib_zero(image_t *img, image_t *mask, bool invert);
|
||||||
void imlib_flood_fill_int(image_t *out, image_t *img, int x, int y,
|
void imlib_flood_fill_int(image_t *out, image_t *img, int x, int y,
|
||||||
int seed_threshold, int floating_threshold,
|
int seed_threshold, int floating_threshold,
|
||||||
flood_fill_call_back_t cb, void *data);
|
flood_fill_call_back_t cb, void *data);
|
||||||
@ -1267,7 +1268,6 @@ void imlib_flood_fill(image_t *img, int x, int y,
|
|||||||
float seed_threshold, float floating_threshold,
|
float seed_threshold, float floating_threshold,
|
||||||
int c, bool invert, bool clear_background, image_t *mask);
|
int c, bool invert, bool clear_background, image_t *mask);
|
||||||
// Binary Functions
|
// Binary Functions
|
||||||
void imlib_zero(image_t *img, image_t *mask, bool invert);
|
|
||||||
void imlib_binary(image_t *out, image_t *img, list_t *thresholds, bool invert, bool zero, image_t *mask);
|
void imlib_binary(image_t *out, image_t *img, list_t *thresholds, bool invert, bool zero, image_t *mask);
|
||||||
void imlib_invert(image_t *img);
|
void imlib_invert(image_t *img);
|
||||||
void imlib_b_and(image_t *img, const char *path, image_t *other, int scalar, image_t *mask);
|
void imlib_b_and(image_t *img, const char *path, image_t *other, int scalar, image_t *mask);
|
||||||
|
|||||||
@ -1578,13 +1578,20 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_save_obj, 2, py_image_save);
|
|||||||
// Drawing Methods
|
// Drawing Methods
|
||||||
//////////////////
|
//////////////////
|
||||||
|
|
||||||
STATIC mp_obj_t py_image_clear(mp_obj_t img_obj)
|
STATIC mp_obj_t py_image_clear(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||||
{
|
{
|
||||||
image_t *arg_img = py_helper_arg_to_image_mutable_bayer(img_obj);
|
image_t *arg_img = py_helper_arg_to_image_mutable_bayer(args[0]);
|
||||||
memset(arg_img->data, 0, image_size(arg_img));
|
image_t *arg_msk = py_helper_keyword_to_image_mutable_mask(n_args, args, 1, kw_args);
|
||||||
return img_obj;
|
|
||||||
|
if (!arg_msk) {
|
||||||
|
memset(arg_img->data, 0, image_size(arg_img));
|
||||||
|
} else {
|
||||||
|
imlib_zero(arg_img, arg_msk, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return args[0];
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_image_clear_obj, py_image_clear);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_clear_obj, 1, py_image_clear);
|
||||||
|
|
||||||
STATIC mp_obj_t py_image_draw_line(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
STATIC mp_obj_t py_image_draw_line(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -431,6 +431,7 @@ Q(save)
|
|||||||
|
|
||||||
// Clear
|
// Clear
|
||||||
Q(clear)
|
Q(clear)
|
||||||
|
Q(mask)
|
||||||
|
|
||||||
// Draw Line
|
// Draw Line
|
||||||
Q(draw_line)
|
Q(draw_line)
|
||||||
@ -488,7 +489,7 @@ Q(draw_image)
|
|||||||
// duplicate Q(x_scale)
|
// duplicate Q(x_scale)
|
||||||
// duplicate Q(y_scale)
|
// duplicate Q(y_scale)
|
||||||
Q(alpha)
|
Q(alpha)
|
||||||
Q(mask)
|
// duplicate Q(mask)
|
||||||
|
|
||||||
// Draw Keypoints
|
// Draw Keypoints
|
||||||
Q(draw_keypoints)
|
Q(draw_keypoints)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user