Skip to content

Commit 614a185

Browse files
MaleicAcidMaleicAcid
authored andcommitted
add CV\filter2D
Signed-off-by: MaleicAcid <CS_MaleicAcid@163.com>
1 parent 5853544 commit 614a185

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
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, filter2D, ZEND_FN(opencv_filter2D), opencv_filter2D_arginfo)
225226
ZEND_NS_NAMED_FE(OPENCV_NS, getStructuringElement, ZEND_FN(opencv_get_structuring_element), opencv_get_structuring_element_arginfo)
226227
ZEND_NS_NAMED_FE(OPENCV_NS, threshold, ZEND_FN(opencv_threshold), opencv_threshold_arginfo)
227228
PHP_FE_END /* Must be the last line in opencv_functions[] */

source/opencv2/opencv_imgproc.cc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,54 @@ PHP_FUNCTION(opencv_threshold){
677677
RETURN_DOUBLE(threshold(*src_object->mat, *dst_object->mat, thresh, maxval, (int)type));
678678
}
679679

680+
/**
681+
* CV\filter2D
682+
* @param execute_data
683+
* @param return_value
684+
*/
685+
PHP_FUNCTION(opencv_filter2D){
686+
687+
zval *src_zval, *dst_zval, *kernel_zval, *anchor_zval = NULL;
688+
long ddepth;
689+
Point anchor = Point(-1,-1);
690+
double delta = 0.0;
691+
long border_type = BORDER_DEFAULT;
692+
opencv_mat_object *dst_object;
693+
694+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OzlO|Odl",
695+
&src_zval, opencv_mat_ce,
696+
&dst_zval,
697+
&ddepth,
698+
&kernel_zval, opencv_mat_ce,
699+
&anchor_zval, opencv_point_ce,
700+
&delta,
701+
&border_type) == FAILURE) {
702+
RETURN_NULL();
703+
}
704+
705+
opencv_mat_object *src_object = Z_PHP_MAT_OBJ_P(src_zval);
706+
opencv_mat_object *kernel_object = Z_PHP_MAT_OBJ_P(kernel_zval);
707+
if(anchor_zval != NULL){
708+
opencv_point_object *anchor_object = Z_PHP_POINT_OBJ_P(anchor_zval);
709+
anchor = *anchor_object->point;
710+
}
711+
712+
zval *dst_real_zval = Z_REFVAL_P(dst_zval);
713+
if(Z_TYPE_P(dst_real_zval) == IS_OBJECT && Z_OBJCE_P(dst_real_zval) == opencv_mat_ce){
714+
dst_object = Z_PHP_MAT_OBJ_P(dst_real_zval);
715+
} else{
716+
zval_ptr_dtor(dst_real_zval);
717+
zval instance;
718+
Mat dst;
719+
object_init_ex(&instance,opencv_mat_ce);
720+
ZVAL_COPY_VALUE(dst_real_zval, &instance);
721+
dst_object = Z_PHP_MAT_OBJ_P(dst_real_zval);
722+
dst_object->mat = new Mat(dst);
723+
}
724+
filter2D(*src_object->mat, *dst_object->mat, (int)ddepth, *kernel_object->mat, anchor, delta, (int)border_type);
725+
RETURN_NULL();
726+
}
727+
680728
/**
681729
* CV\getStructuringElement
682730
* @param execute_data

source/opencv2/opencv_imgproc.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ 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_filter2D_arginfo, 0, 0, 7)
115+
ZEND_ARG_INFO(0, src)
116+
ZEND_ARG_INFO(1, dst)
117+
ZEND_ARG_INFO(0, ddepth)
118+
ZEND_ARG_INFO(0, kernel)
119+
ZEND_ARG_INFO(0, anchor)
120+
ZEND_ARG_INFO(0, delta)
121+
ZEND_ARG_INFO(0, border_type)
122+
ZEND_END_ARG_INFO()
123+
PHP_FUNCTION(opencv_filter2D);
124+
114125
ZEND_BEGIN_ARG_INFO_EX(opencv_get_structuring_element_arginfo, 0, 0, 3)
115126
ZEND_ARG_INFO(0, shape)
116127
ZEND_ARG_INFO(0, ksize)

0 commit comments

Comments
 (0)