@@ -1248,6 +1248,54 @@ PHP_FUNCTION(opencv_draw_contours){
12481248
12491249}
12501250
1251+ /* *
1252+ * todo param can Mat
1253+ * @param execute_data
1254+ * @param return_value
1255+ */
1256+ PHP_FUNCTION (opencv_bounding_rect){
1257+ zval *points_zval;
1258+
1259+ if (zend_parse_parameters (ZEND_NUM_ARGS (), " a" , &points_zval) == FAILURE) {
1260+ RETURN_NULL ();
1261+ }
1262+ std::vector<cv::Point> points;
1263+ opencv_point_object *point_object;
1264+ Rect return_rect;
1265+ unsigned long src_count = zend_hash_num_elements (Z_ARRVAL_P (points_zval));
1266+ points.reserve (src_count);// 指定长度
1267+ zend_ulong _h;
1268+ zval *array_val_zval;
1269+ ZEND_HASH_FOREACH_NUM_KEY_VAL (Z_ARRVAL_P (points_zval),_h,array_val_zval){// get point arrays
1270+ again1:
1271+ if (Z_TYPE_P (array_val_zval) == IS_OBJECT && Z_OBJCE_P (array_val_zval) == opencv_point_ce){
1272+ point_object = Z_PHP_POINT_OBJ_P (array_val_zval);
1273+ points.push_back (*point_object->point );
1274+ }else if (Z_TYPE_P (array_val_zval) == IS_REFERENCE){
1275+ array_val_zval = Z_REFVAL_P (array_val_zval);
1276+ goto again1;
1277+ } else {
1278+ opencv_throw_exception (" The parameter contours can only be a Point object two bit array." );
1279+ RETURN_NULL ();
1280+ }
1281+ }ZEND_HASH_FOREACH_END ();
1282+ try {
1283+ return_rect = boundingRect (points);
1284+ }catch (Exception e){
1285+ opencv_throw_exception (e.what ());
1286+ }
1287+
1288+ zval instance;
1289+ object_init_ex (&instance, opencv_rect_ce);
1290+ opencv_rect_object *rect_obj = Z_PHP_RECT_OBJ_P (&instance);
1291+
1292+ rect_obj->rect = new Rect (return_rect);
1293+
1294+ opencv_rect_update_property_by_c_rect (&instance,rect_obj->rect );
1295+
1296+ RETURN_ZVAL (&instance,0 ,0 ); // return php Rect object
1297+ }
1298+
12511299/* *
12521300 * color conversion code in CV\cvtColor,opencv enum ColorConversionCodes
12531301 * @param module_number
0 commit comments