Skip to content

Commit 2a62ccd

Browse files
committed
CV\VideoCapture Class
1 parent 2ab2848 commit 2a62ccd

File tree

4 files changed

+111
-1
lines changed

4 files changed

+111
-1
lines changed

config.m4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ if test "$PHP_OPENCV" != "no"; then
4444
source/opencv2/opencv_imgproc.cc \
4545
source/opencv2/core/opencv_base.cc \
4646
source/opencv2/core/opencv_persistence.cc \
47-
source/opencv2/opencv_objdetect.cc"
47+
source/opencv2/opencv_objdetect.cc \
48+
source/opencv2/opencv_videoio.cc"
4849

4950

5051
PHP_NEW_EXTENSION(opencv, $opencv_source_file, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)

opencv.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ extern "C" {
3838
#include "source/opencv2/core/opencv_base.h"
3939
#include "source/opencv2/core/opencv_persistence.h"
4040
#include "source/opencv2/opencv_objdetect.h"
41+
#include "source/opencv2/opencv_videoio.h"
4142

4243
/* If you declare any globals in php_opencv.h uncomment this:
4344
ZEND_DECLARE_MODULE_GLOBALS(opencv)
@@ -117,6 +118,7 @@ PHP_MINIT_FUNCTION(opencv)
117118
opencv_border_types_init(module_number);
118119
opencv_file_storage_init(module_number);
119120
opencv_objdetect_init(module_number);
121+
opencv_videoio_init(module_number);
120122

121123
return SUCCESS;
122124
}

source/opencv2/opencv_videoio.cc

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP-OpenCV |
4+
+----------------------------------------------------------------------+
5+
| This source file is subject to version 2.0 of the Apache license, |
6+
| that is bundled with this package in the file LICENSE, and is |
7+
| available through the world-wide-web at the following url: |
8+
| http://www.apache.org/licenses/LICENSE-2.0.html |
9+
| If you did not receive a copy of the Apache2.0 license and are unable|
10+
| to obtain it through the world-wide-web, please send a note to |
11+
| hihozhou@gmail.com so we can mail you a copy immediately. |
12+
+----------------------------------------------------------------------+
13+
| Author: HaiHao Zhou <hihozhou@gmail.com> |
14+
+----------------------------------------------------------------------+
15+
*/
16+
#include "../../php_opencv.h"
17+
#include "opencv_videoio.h"
18+
19+
zend_class_entry *opencv_video_capture_ce;
20+
21+
zend_object_handlers opencv_video_capture_object_handlers;
22+
23+
zend_object* opencv_video_capture_create_handler(zend_class_entry *type)
24+
{
25+
size_t size = sizeof(opencv_video_capture_object);
26+
opencv_video_capture_object *obj = (opencv_video_capture_object *)ecalloc(1,size);
27+
memset(obj, 0, sizeof(opencv_video_capture_object));
28+
zend_object_std_init(&obj->std, type);
29+
object_properties_init(&obj->std, type);
30+
obj->std.ce = type;
31+
obj->std.handlers = &opencv_video_capture_object_handlers;
32+
return &obj->std;
33+
}
34+
35+
PHP_METHOD(opencv_video_capture, __construct)
36+
{
37+
opencv_video_capture_object *obj = Z_PHP_VIDEO_CAPTURE_P(getThis());
38+
obj->videoCapture = new VideoCapture();
39+
}
40+
41+
/**
42+
* opencv_video_capture_methods[]
43+
*/
44+
const zend_function_entry opencv_video_capture_methods[] = {
45+
PHP_ME(opencv_video_capture, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
46+
PHP_FE_END
47+
};
48+
/* }}} */
49+
50+
void opencv_video_capture_free_obj(zend_object *object)
51+
{
52+
opencv_video_capture_object *obj;
53+
obj = get_video_capture_obj(object);
54+
delete obj->videoCapture;
55+
zend_object_std_dtor(object);
56+
}
57+
58+
void opencv_video_capture_init(int module_number){
59+
zend_class_entry ce;
60+
INIT_NS_CLASS_ENTRY(ce,OPENCV_NS, "VideoCapture", opencv_video_capture_methods);
61+
opencv_video_capture_ce = zend_register_internal_class(&ce);
62+
63+
opencv_video_capture_ce->create_object = opencv_video_capture_create_handler;
64+
memcpy(&opencv_video_capture_object_handlers,
65+
zend_get_std_object_handlers(), sizeof(zend_object_handlers));
66+
opencv_video_capture_object_handlers.clone_obj = NULL;
67+
opencv_video_capture_object_handlers.free_obj = opencv_video_capture_free_obj;
68+
}
69+
70+
void opencv_videoio_init(int module_number){
71+
opencv_video_capture_init(module_number);
72+
}

source/opencv2/opencv_videoio.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP-OpenCV |
4+
+----------------------------------------------------------------------+
5+
| This source file is subject to version 2.0 of the Apache license, |
6+
| that is bundled with this package in the file LICENSE, and is |
7+
| available through the world-wide-web at the following url: |
8+
| http://www.apache.org/licenses/LICENSE-2.0.html |
9+
| If you did not receive a copy of the Apache2.0 license and are unable|
10+
| to obtain it through the world-wide-web, please send a note to |
11+
| hihozhou@gmail.com so we can mail you a copy immediately. |
12+
+----------------------------------------------------------------------+
13+
| Author: HaiHao Zhou <hihozhou@gmail.com> |
14+
+----------------------------------------------------------------------+
15+
*/
16+
17+
#ifndef PHP_OPENCV_VIDEOIO_H
18+
#define PHP_OPENCV_VIDEOIO_H
19+
20+
extern zend_class_entry *opencv_video_capture_ce;
21+
22+
#define Z_PHP_VIDEO_CAPTURE_P(zv) get_video_capture_obj(Z_OBJ_P(zv))
23+
24+
typedef struct _opencv_video_capture_object{
25+
zend_object std;
26+
VideoCapture *videoCapture;
27+
}opencv_video_capture_object;
28+
29+
extern void opencv_videoio_init(int module_number);
30+
31+
static inline opencv_video_capture_object* get_video_capture_obj(zend_object *obj) {
32+
return (opencv_video_capture_object*)((char*)(obj) - XtOffsetOf(opencv_video_capture_object, std));
33+
}
34+
35+
#endif //PHP_OPENCV_VIDEOIO_H

0 commit comments

Comments
 (0)