@@ -672,6 +672,10 @@ maix_image *maix_image::_draw_crop(int x, int y, int w, int h)
672
672
maix_image *tmp_img = new maix_image ();
673
673
return tmp_img;
674
674
}
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);
675
679
libmaix_image_t *tmp = libmaix_image_create (w, h, this ->_img ->mode , LIBMAIX_IMAGE_LAYOUT_HWC, NULL , true );
676
680
if (tmp)
677
681
{
@@ -1111,3 +1115,52 @@ py::dict maix_image::_imlib_find_template(maix_image &template_src, float arg_th
1111
1115
}
1112
1116
return return_val;
1113
1117
}
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
+ }
0 commit comments