Skip to content

Commit 37a2f4d

Browse files
MaleicAcidMaleicAcid
authored andcommitted
add Mat::ones (used in 《Making your own linear filters!》to create kernel)
update mat.phpt Signed-off-by: MaleicAcid <CS_MaleicAcid@163.com>
1 parent db7e3b9 commit 37a2f4d

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

source/opencv2/core/opencv_mat.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,24 @@ PHP_METHOD(opencv_mat, empty)
128128
RETURN_LONG(obj->mat->empty());
129129
}
130130

131+
PHP_METHOD(opencv_mat, ones)
132+
{
133+
long rows, cols, flags;
134+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll", &rows, &cols, &flags) == FAILURE) {
135+
RETURN_NULL();
136+
}
137+
zval instance;
138+
object_init_ex(&instance, opencv_mat_ce);
139+
opencv_mat_object *obj = Z_PHP_MAT_OBJ_P(&instance);
140+
141+
Mat im = Mat::ones((int)rows, (int)cols, (int)flags);
142+
143+
obj->mat=new Mat(im);
144+
//update php Mat object property
145+
opencv_mat_update_property_by_c_mat(&instance, obj->mat);
146+
147+
RETURN_ZVAL(&instance,0,0); //return php Mat object
148+
}
131149

132150
PHP_METHOD(opencv_mat, zeros)
133151
{
@@ -445,6 +463,7 @@ const zend_function_entry opencv_mat_methods[] = {
445463
PHP_ME(opencv_mat, print, NULL, ZEND_ACC_PUBLIC)
446464
PHP_ME(opencv_mat, size, NULL, ZEND_ACC_PUBLIC)
447465
PHP_ME(opencv_mat, clone, NULL, ZEND_ACC_PUBLIC)
466+
PHP_ME(opencv_mat, ones, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
448467
PHP_ME(opencv_mat, zeros, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
449468
PHP_MALIAS(opencv_mat, zerosBySize ,zeros_by_size, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
450469
PHP_MALIAS(opencv_mat, isContinuous ,is_continuous, NULL, ZEND_ACC_PUBLIC)

tests/mat.phpt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ $mat->print(Formatter::FMT_PYTHON);
1515
$zeros = Mat::zeros(10,10,CV_8UC1);
1616
var_dump($zeros);
1717
$zeros->print(Formatter::FMT_PYTHON);
18+
$ones = Mat::ones(10,10,CV_8UC1);
19+
var_dump($ones);
20+
$ones->print(Formatter::FMT_PYTHON);
1821
?>
1922
--EXPECT--
2023
object(CV\Mat)#2 (4) {
@@ -51,4 +54,24 @@ object(CV\Mat)#3 (4) {
5154
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
5255
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
5356
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
54-
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
57+
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
58+
object(CV\Mat)#4 (4) {
59+
["type":"CV\Mat":private]=>
60+
int(0)
61+
["rows"]=>
62+
int(10)
63+
["cols"]=>
64+
int(10)
65+
["dims"]=>
66+
int(2)
67+
}
68+
[[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
69+
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
70+
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
71+
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
72+
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
73+
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
74+
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
75+
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
76+
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
77+
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]

0 commit comments

Comments
 (0)