Skip to content

Commit 5a2cb15

Browse files
committed
Add CV\threshold function
1 parent 2f19011 commit 5a2cb15

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
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: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,11 +638,43 @@ PHP_FUNCTION(opencv_erode){
638638
opencv_scalar_object *border_value_object = Z_PHP_SCALAR_OBJ_P(border_value_zval);
639639
border_value = *border_value_object->scalar;
640640
}
641-
642641
erode(*src_object->mat, *dst_object->mat, *kernel_object->mat, anchor, (int)iterations, (int)border_type, border_value);
643642
RETURN_NULL();
644643
}
645644

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