Skip to content

Commit a140f26

Browse files
MaleicAcidMaleicAcid
authored andcommitted
Merge branch 'master' of https://github.com/hihozhou/php-opencv
2 parents a25bcae + e0a68fc commit a140f26

File tree

4 files changed

+130
-7
lines changed

4 files changed

+130
-7
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ result:
139139
- 19.Videostab
140140

141141

142-
142+
## Contributors
143+
144+
[@hihozhou](https://github.com/hihozhou)
145+
[@MaleicAcid](https://github.com/MaleicAcid)
143146

144147
## 感谢
145148

opencv.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ const zend_function_entry opencv_functions[] = {
220220
ZEND_NS_NAMED_FE(OPENCV_NS, GaussianBlur, ZEND_FN(opencv_gaussian_blur), opencv_gaussian_blur_arginfo)
221221
ZEND_NS_NAMED_FE(OPENCV_NS, medianBlur, ZEND_FN(opencv_median_blur), opencv_median_blur_arginfo)
222222
ZEND_NS_NAMED_FE(OPENCV_NS, bilateralFilter, ZEND_FN(opencv_bilateral_filter), opencv_bilateral_filter_arginfo)
223+
ZEND_NS_NAMED_FE(OPENCV_NS, dilate, ZEND_FN(opencv_dilate), opencv_dilate_arginfo)
224+
ZEND_NS_NAMED_FE(OPENCV_NS, erode, ZEND_FN(opencv_erode), opencv_erode_arginfo)
223225
PHP_FE_END /* Must be the last line in opencv_functions[] */
224226
};
225227
/* }}} */

source/opencv2/opencv_imgproc.cc

Lines changed: 102 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,28 +119,28 @@ PHP_FUNCTION(opencv_circle){
119119
}
120120

121121
/**
122+
* todo 传入二维数组
122123
* CV\fillPoly
123124
* @param execute_data
124125
* @param return_value
125126
*/
126127
PHP_FUNCTION(opencv_fill_poly){
127128

128-
//define parameters
129-
long ncontours, lineType = LINE_8, shift = 0;
129+
long ncontours = 1, lineType = LINE_8, shift = 0;
130130
zval *img_zval, *color_zval, *offset_point_zval = NULL;
131131
zval *points_zval;
132132
opencv_point_object *offset_object;
133-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OalO|llz",
133+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OaO|llz",
134134
&img_zval, opencv_mat_ce,
135-
&points_zval, &ncontours,
135+
&points_zval,
136136
&color_zval, opencv_scalar_ce,
137137
&lineType, &shift,
138138
&offset_point_zval) == FAILURE) {
139139
RETURN_NULL();
140140
}
141141

142142
unsigned long point_count = zend_hash_num_elements(Z_ARRVAL_P(points_zval));
143-
Point root_points[1][point_count];
143+
Point root_points[ncontours][point_count];
144144
opencv_point_object *point_object;
145145
zend_ulong _h;
146146
zval *array_val_zval;
@@ -158,7 +158,7 @@ PHP_FUNCTION(opencv_fill_poly){
158158
}
159159
}ZEND_HASH_FOREACH_END();
160160

161-
const Point* pts[1] = {root_points[0]};
161+
const Point* pts[ncontours] = {root_points[0]};
162162
int npts[] = {(int)point_count};
163163
Point offset;
164164
zval *offset_point_real_zval;
@@ -548,6 +548,102 @@ PHP_FUNCTION(opencv_bilateral_filter){
548548
}
549549

550550

551+
PHP_FUNCTION(opencv_dilate){
552+
zval *src_zval, *dst_zval, *kernel_zval, *anchor_zval = NULL, *border_value_zval = NULL;
553+
long iterations = 1, border_type = BORDER_CONSTANT;
554+
555+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OzO|OllO",
556+
&src_zval, opencv_mat_ce,
557+
&dst_zval,
558+
&kernel_zval, opencv_mat_ce,
559+
&anchor_zval, opencv_point_ce,
560+
&iterations, &border_type,
561+
&border_value_zval, opencv_scalar_ce) == FAILURE) {
562+
RETURN_NULL();
563+
}
564+
opencv_mat_object *src_object, *dst_object, *kernel_object;
565+
Point anchor = Point(-1,-1);
566+
Scalar border_value = morphologyDefaultBorderValue();
567+
568+
src_object = Z_PHP_MAT_OBJ_P(src_zval);
569+
kernel_object = Z_PHP_MAT_OBJ_P(kernel_zval);
570+
zval *dst_real_zval = Z_REFVAL_P(dst_zval);
571+
572+
if(Z_TYPE_P(dst_real_zval) == IS_OBJECT && Z_OBJCE_P(dst_real_zval) == opencv_mat_ce){
573+
dst_object = Z_PHP_MAT_OBJ_P(dst_real_zval);
574+
} else{
575+
zval_ptr_dtor(dst_real_zval);
576+
zval instance;
577+
Mat dst;
578+
object_init_ex(&instance,opencv_mat_ce);
579+
ZVAL_COPY_VALUE(dst_real_zval, &instance);
580+
dst_object = Z_PHP_MAT_OBJ_P(dst_real_zval);
581+
dst_object->mat = new Mat(dst);
582+
}
583+
584+
if(anchor_zval != NULL){
585+
opencv_point_object *anchor_object = Z_PHP_POINT_OBJ_P(anchor_zval);
586+
anchor = *anchor_object->point;
587+
}
588+
589+
if(border_value_zval != NULL){
590+
opencv_scalar_object *border_value_object = Z_PHP_SCALAR_OBJ_P(border_value_zval);
591+
border_value = *border_value_object->scalar;
592+
}
593+
594+
dilate(*src_object->mat, *dst_object->mat, *kernel_object->mat, anchor, (int)iterations, (int)border_type, border_value);
595+
RETURN_NULL();
596+
597+
}
598+
599+
PHP_FUNCTION(opencv_erode){
600+
601+
zval *src_zval, *dst_zval, *kernel_zval, *anchor_zval = NULL, *border_value_zval = NULL;
602+
long iterations = 1, border_type = BORDER_CONSTANT;
603+
604+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OzO|OllO",
605+
&src_zval, opencv_mat_ce,
606+
&dst_zval,
607+
&kernel_zval, opencv_mat_ce,
608+
&anchor_zval, opencv_point_ce,
609+
&iterations, &border_type,
610+
&border_value_zval, opencv_scalar_ce) == FAILURE) {
611+
RETURN_NULL();
612+
}
613+
opencv_mat_object *src_object, *dst_object, *kernel_object;
614+
Point anchor = Point(-1,-1);
615+
Scalar border_value = morphologyDefaultBorderValue();
616+
617+
src_object = Z_PHP_MAT_OBJ_P(src_zval);
618+
kernel_object = Z_PHP_MAT_OBJ_P(kernel_zval);
619+
zval *dst_real_zval = Z_REFVAL_P(dst_zval);
620+
621+
if(Z_TYPE_P(dst_real_zval) == IS_OBJECT && Z_OBJCE_P(dst_real_zval) == opencv_mat_ce){
622+
dst_object = Z_PHP_MAT_OBJ_P(dst_real_zval);
623+
} else{
624+
zval_ptr_dtor(dst_real_zval);
625+
zval instance;
626+
Mat dst;
627+
object_init_ex(&instance,opencv_mat_ce);
628+
ZVAL_COPY_VALUE(dst_real_zval, &instance);
629+
dst_object = Z_PHP_MAT_OBJ_P(dst_real_zval);
630+
dst_object->mat = new Mat(dst);
631+
}
632+
633+
if(anchor_zval != NULL){
634+
opencv_point_object *anchor_object = Z_PHP_POINT_OBJ_P(anchor_zval);
635+
anchor = *anchor_object->point;
636+
}
637+
638+
if(border_value_zval != NULL){
639+
opencv_scalar_object *border_value_object = Z_PHP_SCALAR_OBJ_P(border_value_zval);
640+
border_value = *border_value_object->scalar;
641+
}
642+
643+
erode(*src_object->mat, *dst_object->mat, *kernel_object->mat, anchor, (int)iterations, (int)border_type, border_value);
644+
RETURN_NULL();
645+
}
646+
551647
/**
552648
* color conversion code in CV\cvtColor,opencv enum ColorConversionCodes
553649
* @param module_number

source/opencv2/opencv_imgproc.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,26 @@ ZEND_BEGIN_ARG_INFO_EX(opencv_bilateral_filter_arginfo, 0, 0, 6)
8989
ZEND_END_ARG_INFO()
9090
PHP_FUNCTION(opencv_bilateral_filter);
9191

92+
ZEND_BEGIN_ARG_INFO_EX(opencv_dilate_arginfo, 0, 0, 7)
93+
ZEND_ARG_INFO(0, src)
94+
ZEND_ARG_INFO(1, dst)
95+
ZEND_ARG_INFO(0, kernel)
96+
ZEND_ARG_INFO(0, anchor)
97+
ZEND_ARG_INFO(0, iterations)
98+
ZEND_ARG_INFO(0, borderType)
99+
ZEND_ARG_INFO(0, borderValue)
100+
ZEND_END_ARG_INFO()
101+
PHP_FUNCTION(opencv_dilate);
102+
103+
ZEND_BEGIN_ARG_INFO_EX(opencv_erode_arginfo, 0, 0, 7)
104+
ZEND_ARG_INFO(0, src)
105+
ZEND_ARG_INFO(1, dst)
106+
ZEND_ARG_INFO(0, kernel)
107+
ZEND_ARG_INFO(0, anchor)
108+
ZEND_ARG_INFO(0, iterations)
109+
ZEND_ARG_INFO(0, borderType)
110+
ZEND_ARG_INFO(0, borderValue)
111+
ZEND_END_ARG_INFO()
112+
PHP_FUNCTION(opencv_erode);
113+
92114
#endif //OPENCV_OPENCV_IMGPROC_H

0 commit comments

Comments
 (0)