Skip to content

Commit c277e97

Browse files
committed
[fix] check the limit boundary length
1 parent a29c542 commit c277e97

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

ext_modules/_maix_image/_maix_image.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,10 @@ maix_image *maix_image::_draw_crop(int x, int y, int w, int h)
672672
maix_image *tmp_img = new maix_image();
673673
return tmp_img;
674674
}
675+
x = std::max(x,0);
676+
y = std::max(y,0);
677+
w = std::min(w, this->_img->width - x);
678+
h = std::min(h , this->_img->height - y);
675679
libmaix_image_t *tmp = libmaix_image_create(w, h, this->_img->mode, LIBMAIX_IMAGE_LAYOUT_HWC, NULL, true);
676680
if (tmp)
677681
{
@@ -1111,3 +1115,52 @@ py::dict maix_image::_imlib_find_template(maix_image &template_src, float arg_th
11111115
}
11121116
return return_val;
11131117
}
1118+
1119+
maix_image *maix_image::_draw_affine(int x , int y , int w , int h , std::vector<int> dst_size)
1120+
{
1121+
if (NULL == this->_img)
1122+
{
1123+
py::print("no img");
1124+
maix_image *tmp_img = new maix_image();
1125+
return tmp_img;
1126+
}
1127+
x = std::max(x,0);
1128+
y = std::max(y,0);
1129+
w = std::min(w, this->_img->width - x);
1130+
h = std::min(h , this->_img->height - y);
1131+
int reg_w = dst_size[0];
1132+
int reg_h = dst_size[1];
1133+
libmaix_image_t *tmp = libmaix_image_create(reg_w, reg_h, LIBMAIX_IMAGE_MODE_RGB888, LIBMAIX_IMAGE_LAYOUT_HWC, NULL, true);
1134+
if (tmp)
1135+
{
1136+
maix_image *tmp_img = new maix_image();
1137+
1138+
1139+
1140+
int affine_dst_pts[6] = {reg_w , reg_h , 0 , reg_h , 0,0};
1141+
1142+
int affine_src_pts [6];
1143+
affine_src_pts[0] = x + w;
1144+
affine_src_pts[1] = y + h ;
1145+
affine_src_pts[2] = x;
1146+
affine_src_pts[3] = y + h;
1147+
affine_src_pts[4] = x;
1148+
affine_src_pts[5] = y;
1149+
if (libmaix_cv_image_affine(this->_img, affine_src_pts , affine_dst_pts , reg_w, reg_h, &tmp) != 0)
1150+
{
1151+
return tmp_img;
1152+
}
1153+
tmp_img->local_load(tmp);
1154+
return tmp_img;
1155+
}
1156+
else
1157+
{
1158+
libmaix_image_destroy(&tmp);
1159+
}
1160+
maix_image *tmp_img = new maix_image();
1161+
return tmp_img;
1162+
1163+
1164+
1165+
1166+
}

ext_modules/_maix_nn_mud/src/py_maix_nn_Model.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static int Model_init(ModelObject *self, PyObject *args, PyObject *kwds)
131131
else if(PyObject_TypeCheck(o_model_path, &PyDict_Type))
132132
{
133133
// dict
134-
printf("Dict mode");
134+
// printf("Dict mode");
135135
if(!o_opt || !PyObject_TypeCheck(o_opt, &PyDict_Type))
136136
{
137137
PyErr_SetString(PyExc_ValueError, "arg opt is needed");
@@ -563,12 +563,10 @@ static int Model_init(ModelObject *self, PyObject *args, PyObject *kwds)
563563
else if(PyObject_TypeCheck(o_model_path, &PyUnicode_Type))
564564
{
565565
// mud
566-
printf("mud mode \n");
567566
self->use_mud = true;
568567
libmaix_camera_module_init();
569568
libmaix_nn_module_init();
570569
char * mud = (char*)PyUnicode_DATA(o_model_path);
571-
printf("%s\n",mud);
572570
self->mud = mud;
573571
self->info = libmaix_mud_load_mud(mud);
574572
libmaix_nn_model_path_t *model_path = (libmaix_nn_model_path_t * )malloc(sizeof(libmaix_nn_model_path_t));

0 commit comments

Comments
 (0)