Skip to content

Commit 9ef5df2

Browse files
committed
Merge branch 'dev'
2 parents e0a68fc + a59dea7 commit 9ef5df2

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

opencv.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ const zend_function_entry opencv_functions[] = {
222222
ZEND_NS_NAMED_FE(OPENCV_NS, bilateralFilter, ZEND_FN(opencv_bilateral_filter), opencv_bilateral_filter_arginfo)
223223
ZEND_NS_NAMED_FE(OPENCV_NS, dilate, ZEND_FN(opencv_dilate), opencv_dilate_arginfo)
224224
ZEND_NS_NAMED_FE(OPENCV_NS, erode, ZEND_FN(opencv_erode), opencv_erode_arginfo)
225+
ZEND_NS_NAMED_FE(OPENCV_NS, threshold, ZEND_FN(opencv_threshold), opencv_threshold_arginfo)
225226
PHP_FE_END /* Must be the last line in opencv_functions[] */
226227
};
227228
/* }}} */

source/opencv2/opencv_imgproc.cc

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ PHP_FUNCTION(opencv_circle){
125125
*/
126126
PHP_FUNCTION(opencv_fill_poly){
127127

128-
long ncontours = 1, lineType = LINE_8, shift = 0;
128+
long lineType = LINE_8, shift = 0;
129129
zval *img_zval, *color_zval, *offset_point_zval = NULL;
130130
zval *points_zval;
131131
opencv_point_object *offset_object;
@@ -138,6 +138,7 @@ PHP_FUNCTION(opencv_fill_poly){
138138
RETURN_NULL();
139139
}
140140

141+
long ncontours = 1;
141142
unsigned long point_count = zend_hash_num_elements(Z_ARRVAL_P(points_zval));
142143
Point root_points[ncontours][point_count];
143144
opencv_point_object *point_object;
@@ -157,7 +158,8 @@ PHP_FUNCTION(opencv_fill_poly){
157158
}
158159
}ZEND_HASH_FOREACH_END();
159160

160-
const Point* pts[ncontours] = {root_points[0]};
161+
const Point* pts[ncontours];
162+
pts[0] = root_points[0];
161163
int npts[] = {(int)point_count};
162164
Point offset;
163165
zval *offset_point_real_zval;
@@ -638,11 +640,42 @@ PHP_FUNCTION(opencv_erode){
638640
opencv_scalar_object *border_value_object = Z_PHP_SCALAR_OBJ_P(border_value_zval);
639641
border_value = *border_value_object->scalar;
640642
}
641-
642643
erode(*src_object->mat, *dst_object->mat, *kernel_object->mat, anchor, (int)iterations, (int)border_type, border_value);
643644
RETURN_NULL();
644645
}
645646

647+
648+
PHP_FUNCTION(opencv_threshold){
649+
650+
zval *src_zval, *dst_zval;
651+
double thresh, maxval;
652+
long type;
653+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ozddl",
654+
&src_zval, opencv_mat_ce,
655+
&dst_zval,
656+
&thresh, &maxval,
657+
&type) == FAILURE) {
658+
RETURN_NULL();
659+
}
660+
661+
opencv_mat_object *src_object, *dst_object;
662+
663+
src_object = Z_PHP_MAT_OBJ_P(src_zval);
664+
zval *dst_real_zval = Z_REFVAL_P(dst_zval);
665+
if(Z_TYPE_P(dst_real_zval) == IS_OBJECT && Z_OBJCE_P(dst_real_zval) == opencv_mat_ce){
666+
dst_object = Z_PHP_MAT_OBJ_P(dst_real_zval);
667+
} else{
668+
zval_ptr_dtor(dst_real_zval);
669+
zval instance;
670+
Mat dst;
671+
object_init_ex(&instance,opencv_mat_ce);
672+
ZVAL_COPY_VALUE(dst_real_zval, &instance);
673+
dst_object = Z_PHP_MAT_OBJ_P(dst_real_zval);
674+
dst_object->mat = new Mat(dst);
675+
}
676+
RETURN_DOUBLE(threshold(*src_object->mat, *dst_object->mat, thresh, maxval, (int)type));
677+
}
678+
646679
/**
647680
* color conversion code in CV\cvtColor,opencv enum ColorConversionCodes
648681
* @param module_number

source/opencv2/opencv_imgproc.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,13 @@ ZEND_BEGIN_ARG_INFO_EX(opencv_erode_arginfo, 0, 0, 7)
111111
ZEND_END_ARG_INFO()
112112
PHP_FUNCTION(opencv_erode);
113113

114+
ZEND_BEGIN_ARG_INFO_EX(opencv_threshold_arginfo, 0, 0, 5)
115+
ZEND_ARG_INFO(0, src)
116+
ZEND_ARG_INFO(1, dst)
117+
ZEND_ARG_INFO(0, thresh)
118+
ZEND_ARG_INFO(0, maxval)
119+
ZEND_ARG_INFO(0, type)
120+
ZEND_END_ARG_INFO()
121+
PHP_FUNCTION(opencv_threshold);
122+
114123
#endif //OPENCV_OPENCV_IMGPROC_H

0 commit comments

Comments
 (0)