Skip to content

Commit 5853544

Browse files
MaleicAcidMaleicAcid
authored andcommitted
Merge remote-tracking branch 'origin/master'
2 parents 170cab5 + b2ac4bf commit 5853544

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

opencv.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ const zend_function_entry opencv_functions[] = {
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)
225225
ZEND_NS_NAMED_FE(OPENCV_NS, getStructuringElement, ZEND_FN(opencv_get_structuring_element), opencv_get_structuring_element_arginfo)
226+
ZEND_NS_NAMED_FE(OPENCV_NS, threshold, ZEND_FN(opencv_threshold), opencv_threshold_arginfo)
226227
PHP_FE_END /* Must be the last line in opencv_functions[] */
227228
};
228229
/* }}} */

source/opencv2/opencv_imgproc.cc

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

129-
long ncontours = 1, lineType = LINE_8, shift = 0;
129+
long 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;
@@ -139,6 +139,7 @@ PHP_FUNCTION(opencv_fill_poly){
139139
RETURN_NULL();
140140
}
141141

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

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

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

source/opencv2/opencv_imgproc.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,14 @@ ZEND_BEGIN_ARG_INFO_EX(opencv_get_structuring_element_arginfo, 0, 0, 3)
117117
ZEND_ARG_INFO(0, anchor)
118118
ZEND_END_ARG_INFO()
119119
PHP_FUNCTION(opencv_get_structuring_element);
120+
121+
ZEND_BEGIN_ARG_INFO_EX(opencv_threshold_arginfo, 0, 0, 5)
122+
ZEND_ARG_INFO(0, src)
123+
ZEND_ARG_INFO(1, dst)
124+
ZEND_ARG_INFO(0, thresh)
125+
ZEND_ARG_INFO(0, maxval)
126+
ZEND_ARG_INFO(0, type)
127+
ZEND_END_ARG_INFO()
128+
PHP_FUNCTION(opencv_threshold);
129+
120130
#endif //OPENCV_OPENCV_IMGPROC_H

0 commit comments

Comments
 (0)