Skip to content

Commit 1d3053d

Browse files
committed
CV\setMouseCallback
1 parent 6dd39dc commit 1d3053d

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

opencv.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ const zend_function_entry opencv_functions[] = {
235235
ZEND_NS_NAMED_FE(OPENCV_NS, getTickCount, ZEND_FN(opencv_get_tick_count), NULL)
236236
ZEND_NS_NAMED_FE(OPENCV_NS, getTickFrequency, ZEND_FN(opencv_get_tick_frequency), NULL)
237237
ZEND_NS_NAMED_FE(OPENCV_NS, floodFill, ZEND_FN(opencv_flood_fill), opencv_flood_fill_arginfo)
238+
ZEND_NS_NAMED_FE(OPENCV_NS, setMouseCallback, ZEND_FN(opencv_set_mouse_callback), NULL)
238239
PHP_FE_END /* Must be the last line in opencv_functions[] */
239240
};
240241
/* }}} */

source/opencv2/opencv_highgui.cc

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,15 @@ PHP_FUNCTION(opencv_create_trackbar){
169169

170170
zend_fcall_info fci;
171171
zend_fcall_info_cache fci_cache;
172-
zend_bool is_null;
173172
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ssll|f!",
174173
&trackbarname, &trackbarname_len,
175174
&winname,&winname_len,
176175
&value,&count,
177-
&fci, &fci_cache,&is_null) == FAILURE) {
176+
&fci, &fci_cache) == FAILURE) {
178177
return;
179178
}
180179
opencv_fcall_info_cb *cb = 0;
181-
if (fci.size > 0 && ZEND_NUM_ARGS() > 4) {
180+
if (fci.size > 0 && ZEND_NUM_ARGS() > 4) {//check callback param is valid
182181
cb = opencv_fcall_info_cb_create(&fci, &fci_cache);
183182
}
184183
int *trackbar_value_ptr = new int(value);
@@ -214,6 +213,53 @@ PHP_FUNCTION(opencv_get_track_bar_pos){
214213
}
215214

216215

216+
void opencv_on_mouse_callback(int event, int x, int y, int flags, void* userdata){
217+
if(userdata != 0){
218+
opencv_fcall_info_cb *fci_s=(opencv_fcall_info_cb*)userdata;
219+
zval retval;
220+
zval args[4];
221+
ZVAL_LONG(&args[0], (long)event);
222+
ZVAL_LONG(&args[1], (long)x);
223+
ZVAL_LONG(&args[2], (long)y);
224+
ZVAL_LONG(&args[3], (long)flags);
225+
fci_s->fci->param_count = 4;
226+
fci_s->fci->params = args;
227+
fci_s->fci->retval = &retval;
228+
229+
zend_call_function(fci_s->fci, fci_s->fci_cache);
230+
zval_ptr_dtor(&args[0]);
231+
zval_ptr_dtor(&args[1]);
232+
zval_ptr_dtor(&args[2]);
233+
zval_ptr_dtor(&args[3]);
234+
}
235+
}
236+
237+
/**
238+
* CV\setMouseCallback
239+
* @param execute_data
240+
* @param return_value
241+
*/
242+
PHP_FUNCTION(opencv_set_mouse_callback){
243+
char *winname;
244+
long winname_len;
245+
246+
zend_fcall_info fci;
247+
zend_fcall_info_cache fci_cache;
248+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|f!",
249+
&winname,&winname_len,
250+
&fci, &fci_cache) == FAILURE) {
251+
return;
252+
}
253+
opencv_fcall_info_cb *cb = 0;
254+
if (fci.size > 0 && ZEND_NUM_ARGS() > 1) {//check callback param is valid
255+
cb = opencv_fcall_info_cb_create(&fci, &fci_cache);
256+
}
257+
setMouseCallback(winname, opencv_on_mouse_callback, cb);
258+
RETURN_NULL();
259+
}
260+
261+
262+
217263
void opencv_highgui_init(int module_number)
218264
{
219265
/**

source/opencv2/opencv_highgui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ ZEND_END_ARG_INFO()
3434
PHP_FUNCTION(opencv_create_trackbar);
3535
PHP_FUNCTION(opencv_destroy_window);
3636
PHP_FUNCTION(opencv_get_track_bar_pos);
37+
PHP_FUNCTION(opencv_set_mouse_callback);
3738

3839
#endif //OPENCV_OPENCV_HIGHGUI_H

0 commit comments

Comments
 (0)