@@ -1086,7 +1086,11 @@ PHP_FUNCTION(opencv_flood_fill){
10861086 RETURN_LONG (result);
10871087}
10881088
1089- // todo
1089+ /* *
1090+ * CV\findContoursWithoutHierarchy()
1091+ * @param execute_data
1092+ * @param return_value
1093+ */
10901094PHP_FUNCTION (opencv_find_contours_without_hierarchy){
10911095 zval *image_zval, *contours_zval, *offset_zval = NULL ;
10921096 long mode, method;
@@ -1149,6 +1153,101 @@ PHP_FUNCTION(opencv_find_contours_without_hierarchy){
11491153 RETURN_NULL ();
11501154}
11511155
1156+ /* *
1157+ * //todo hierarchy param
1158+ * CV\drawContours()
1159+ * @param execute_data
1160+ * @param return_value
1161+ */
1162+ PHP_FUNCTION (opencv_draw_contours){
1163+ zval *image_zval, *contours_zval, *color_zval, *hierarchy_zval, *offset_zval = NULL ;
1164+ long contourIdx, thickness = 1 , lineType = LINE_8, maxLevel = INT_MAX;
1165+
1166+ if (zend_parse_parameters (ZEND_NUM_ARGS (), " OalO|llalz" ,
1167+ &image_zval, opencv_mat_ce,
1168+ &contours_zval,
1169+ &contourIdx,
1170+ &color_zval, opencv_scalar_ce,
1171+ &thickness, &lineType,
1172+ &hierarchy_zval,
1173+ &maxLevel, &offset_zval
1174+ ) == FAILURE) {
1175+ RETURN_NULL ();
1176+ }
1177+ std::vector<std::vector<cv::Point> >contours;
1178+ std::vector<cv::Point> contour;
1179+ opencv_point_object *point_object;
1180+ opencv_mat_object *image_object = Z_PHP_MAT_OBJ_P (image_zval);
1181+ opencv_scalar_object *color_object = Z_PHP_SCALAR_OBJ_P (color_zval);
1182+ zend_ulong _h;
1183+ zend_ulong _h2;
1184+ zval *array_val_zval;
1185+ zval *array_val_zval2;
1186+ ZEND_HASH_FOREACH_NUM_KEY_VAL (Z_ARRVAL_P (contours_zval),_h,array_val_zval){// get point arrays
1187+ again1:
1188+ if (Z_TYPE_P (array_val_zval) == IS_ARRAY){
1189+ contour.clear ();
1190+ ZEND_HASH_FOREACH_NUM_KEY_VAL (Z_ARRVAL_P (array_val_zval),_h2,array_val_zval2){// get points object
1191+ again2:
1192+ if (Z_TYPE_P (array_val_zval2) == IS_OBJECT && Z_OBJCE_P (array_val_zval2) == opencv_point_ce){
1193+ point_object = Z_PHP_POINT_OBJ_P (array_val_zval2);
1194+ contour.push_back (*point_object->point );
1195+ }else if (Z_TYPE_P (array_val_zval2) == IS_REFERENCE){
1196+ array_val_zval2 = Z_REFVAL_P (array_val_zval2);
1197+ goto again2;
1198+ } else {
1199+ opencv_throw_exception (" The 2D array element can only be Point object." );
1200+ RETURN_NULL ();
1201+ }
1202+ }ZEND_HASH_FOREACH_END ();
1203+ contours.push_back (contour);
1204+ }else if (Z_TYPE_P (array_val_zval) == IS_REFERENCE){
1205+ array_val_zval = Z_REFVAL_P (array_val_zval);
1206+ goto again1;
1207+ } else {
1208+ opencv_throw_exception (" The parameter contours can only be a Point object two bit array." );
1209+ RETURN_NULL ();
1210+ }
1211+ }ZEND_HASH_FOREACH_END ();
1212+ InputArray hierarchy = noArray ();
1213+ zval *offset_real_zval;
1214+
1215+ Point offset;
1216+ opencv_point_object *offset_object;
1217+ if (offset_zval != NULL ){
1218+ offset_real_zval = Z_REFVAL_P (offset_zval);
1219+ if (Z_TYPE_P (offset_real_zval) == IS_OBJECT && Z_OBJCE_P (offset_real_zval) == opencv_point_ce){
1220+ // is Point object
1221+ offset_object = Z_PHP_POINT_OBJ_P (offset_real_zval);
1222+ } else {
1223+ // isn't Point object
1224+ zval_ptr_dtor (offset_real_zval);
1225+ zval instance;
1226+ object_init_ex (&instance,opencv_point_ce);
1227+ ZVAL_COPY_VALUE (offset_real_zval, &instance);// Cover dst_real_zval by Point object
1228+ offset_object = Z_PHP_POINT_OBJ_P (offset_real_zval);
1229+ }
1230+ } else {
1231+ offset = Point ();
1232+ }
1233+ try {
1234+ drawContours (*image_object->mat , contours, (int )contourIdx, *color_object->scalar ,
1235+ (int )thickness, (int )lineType, hierarchy, (int )maxLevel, offset);
1236+ }catch (Exception e){
1237+ opencv_throw_exception (e.what ());
1238+ }
1239+
1240+
1241+ if (offset_zval != NULL ){
1242+ offset_object->point = new Point (offset);
1243+ opencv_point_update_property_by_c_point (offset_real_zval, offset_object->point );
1244+ }
1245+
1246+ RETURN_NULL ();
1247+
1248+
1249+ }
1250+
11521251/* *
11531252 * color conversion code in CV\cvtColor,opencv enum ColorConversionCodes
11541253 * @param module_number
0 commit comments