Skip to content

Commit 6dd39dc

Browse files
committed
Fix CV\createTrackbar and CV\cvtColor bug
1 parent 2b49ef2 commit 6dd39dc

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

source/opencv2/opencv_highgui.cc

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ opencv_fcall_info_cb * opencv_fcall_info_cb_create(zend_fcall_info *fci_ptr, zen
128128
opencv_fcall_info_cb *cb = new opencv_fcall_info_cb;
129129
cb->fci = new zend_fcall_info;
130130
cb->fci_cache = new zend_fcall_info_cache;
131-
132131
memcpy(cb->fci, fci_ptr, sizeof(zend_fcall_info));
133132
memcpy(cb->fci_cache, fci_cache_ptr, sizeof(zend_fcall_info_cache));
134133
Z_TRY_ADDREF(cb->fci->function_name);//todo 滑动调或窗口销毁是释放内存
@@ -140,17 +139,19 @@ opencv_fcall_info_cb * opencv_fcall_info_cb_create(zend_fcall_info *fci_ptr, zen
140139
}
141140

142141
void opencv_create_trackbar_callback(int pos, void* userdata){
143-
opencv_fcall_info_cb *fci_s=(opencv_fcall_info_cb*)userdata;
144-
145-
zval retval;
146-
zval args[1];
147-
ZVAL_LONG(&args[0], (long)pos);//将滑动条滑动的值传入到闭包参数中
148-
fci_s->fci->param_count = 1;
149-
fci_s->fci->params = args;
150-
fci_s->fci->retval = &retval;
151-
152-
zend_call_function(fci_s->fci, fci_s->fci_cache);
153-
zval_ptr_dtor(&args[0]);
142+
if(userdata != 0){
143+
opencv_fcall_info_cb *fci_s=(opencv_fcall_info_cb*)userdata;
144+
145+
zval retval;
146+
zval args[1];
147+
ZVAL_LONG(&args[0], (long)pos);//将滑动条滑动的值传入到闭包参数中
148+
fci_s->fci->param_count = 1;
149+
fci_s->fci->params = args;
150+
fci_s->fci->retval = &retval;
151+
152+
zend_call_function(fci_s->fci, fci_s->fci_cache);
153+
zval_ptr_dtor(&args[0]);
154+
}
154155
}
155156

156157

@@ -168,15 +169,19 @@ PHP_FUNCTION(opencv_create_trackbar){
168169

169170
zend_fcall_info fci;
170171
zend_fcall_info_cache fci_cache;
171-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ssll|f",
172+
zend_bool is_null;
173+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ssll|f!",
172174
&trackbarname, &trackbarname_len,
173175
&winname,&winname_len,
174176
&value,&count,
175-
&fci, &fci_cache) == FAILURE) {
177+
&fci, &fci_cache,&is_null) == FAILURE) {
176178
return;
177179
}
180+
opencv_fcall_info_cb *cb = 0;
181+
if (fci.size > 0 && ZEND_NUM_ARGS() > 4) {
182+
cb = opencv_fcall_info_cb_create(&fci, &fci_cache);
183+
}
178184
int *trackbar_value_ptr = new int(value);
179-
opencv_fcall_info_cb *cb = opencv_fcall_info_cb_create(&fci, &fci_cache);
180185
createTrackbar(trackbarname, winname, trackbar_value_ptr, (int)count,opencv_create_trackbar_callback,cb);
181186
RETURN_NULL();
182187
}

source/opencv2/opencv_imgproc.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ void opencv_imgproc_init(int module_number)
3636
* @param return_value
3737
*/
3838
PHP_FUNCTION(opencv_cv_t_color){
39-
long code;
39+
long code, dstCn = 0;
4040
Mat dstImg;
4141
zval *mat_zval;
42-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &mat_zval,opencv_mat_ce, &code) == FAILURE) {
42+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol|l", &mat_zval,opencv_mat_ce, &code, &dstCn) == FAILURE) {
4343
RETURN_NULL();
4444
}
4545
//get src mat object from mat_zval
4646
opencv_mat_object *src_obj = Z_PHP_MAT_OBJ_P(mat_zval);
47-
cvtColor(*(src_obj->mat), dstImg, (int)code);
47+
cvtColor(*(src_obj->mat), dstImg, (int)code, (int)dstCn);
4848

4949
//new PHP Mat bing cv::cvtColor dstImg.
5050
zval instance;

0 commit comments

Comments
 (0)