From cee081a2fbb87b9d8df71d9b6398d180ec2664ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=9D=A5=E9=85=B8?= Date: Sun, 30 Jul 2017 21:33:39 +0800 Subject: [PATCH 1/2] add cv/Mat->dims --- source/opencv2/core/opencv_mat.cc | 1 + tests/absdiff.phpt | 8 ++++++-- tests/cv.phpt | 4 +++- tests/mat.phpt | 8 ++++++-- tests/roi.phpt | 4 +++- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/source/opencv2/core/opencv_mat.cc b/source/opencv2/core/opencv_mat.cc index ee57228..aef8280 100644 --- a/source/opencv2/core/opencv_mat.cc +++ b/source/opencv2/core/opencv_mat.cc @@ -55,6 +55,7 @@ void opencv_mat_free_obj(zend_object *object) void opencv_mat_update_property_by_c_mat(zval *z,Mat *mat){ zend_update_property_long(opencv_mat_ce, z, "rows", sizeof("rows")-1, mat->rows); zend_update_property_long(opencv_mat_ce, z, "cols", sizeof("cols")-1, mat->cols); + zend_update_property_long(opencv_mat_ce, z, "dims", sizeof("dims")-1, mat->dims); zend_update_property_long(opencv_mat_ce, z, "type", sizeof("type")-1, mat->type()); } diff --git a/tests/absdiff.phpt b/tests/absdiff.phpt index 8552413..5a27464 100644 --- a/tests/absdiff.phpt +++ b/tests/absdiff.phpt @@ -22,13 +22,15 @@ var_dump($dst); $dst->print(); --EXPECT-- -object(CV\Mat)#3 (3) { +object(CV\Mat)#3 (4) { ["type":"CV\Mat":private]=> int(0) ["rows"]=> int(3) ["cols"]=> int(3) + ["dims"]=> + int(2) } [ 10, 10, 10; 10, 10, 10; @@ -47,13 +49,15 @@ object(CV\Scalar)#3 (1) { } } [0, 0, 0, 0] -object(CV\Mat)#3 (3) { +object(CV\Mat)#3 (4) { ["type":"CV\Mat":private]=> int(16) ["rows"]=> int(3) ["cols"]=> int(3) + ["dims"]=> + int(2) } [ 0, 0, 0, 0, 0, 0, 0, 0, 0; 0, 0, 0, 0, 0, 0, 0, 0, 0; diff --git a/tests/cv.phpt b/tests/cv.phpt index 245cec9..be46e32 100644 --- a/tests/cv.phpt +++ b/tests/cv.phpt @@ -13,11 +13,13 @@ var_dump($im); //CV::imwrite('2222.png',$im); ?> --EXPECT-- -object(CV\Mat)#1 (3) { +object(CV\Mat)#1 (4) { ["type":"CV\Mat":private]=> int(16) ["rows"]=> int(50) ["cols"]=> int(50) + ["dims"]=> + int(2) } \ No newline at end of file diff --git a/tests/mat.phpt b/tests/mat.phpt index ddb3c96..393ae5b 100644 --- a/tests/mat.phpt +++ b/tests/mat.phpt @@ -17,26 +17,30 @@ var_dump($zeros); $zeros->print(Formatter::FMT_PYTHON); ?> --EXPECT-- -object(CV\Mat)#2 (3) { +object(CV\Mat)#2 (4) { ["type":"CV\Mat":private]=> int(16) ["rows"]=> int(5) ["cols"]=> int(5) + ["dims"]=> + int(2) } [[[255, 100, 100], [255, 100, 100], [255, 100, 100], [255, 100, 100], [255, 100, 100]], [[255, 100, 100], [255, 100, 100], [255, 100, 100], [255, 100, 100], [255, 100, 100]], [[255, 100, 100], [255, 100, 100], [255, 100, 100], [255, 100, 100], [255, 100, 100]], [[255, 100, 100], [255, 100, 100], [255, 100, 100], [255, 100, 100], [255, 100, 100]], [[255, 100, 100], [255, 100, 100], [255, 100, 100], [255, 100, 100], [255, 100, 100]]] -object(CV\Mat)#3 (3) { +object(CV\Mat)#3 (4) { ["type":"CV\Mat":private]=> int(0) ["rows"]=> int(10) ["cols"]=> int(10) + ["dims"]=> + int(2) } [[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], diff --git a/tests/roi.phpt b/tests/roi.phpt index 1b253cc..082e827 100644 --- a/tests/roi.phpt +++ b/tests/roi.phpt @@ -20,13 +20,15 @@ $roi->print(Formatter::FMT_PYTHON); ?> --EXPECT-- -object(CV\Mat)#3 (3) { +object(CV\Mat)#3 (4) { ["type":"CV\Mat":private]=> int(0) ["rows"]=> int(5) ["cols"]=> int(5) + ["dims"]=> + int(2) } [[ 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0], From 35aeb659f7d0428e084bed4dd425e06119504b69 Mon Sep 17 00:00:00 2001 From: MaleicAcid Date: Sun, 30 Jul 2017 23:30:15 +0800 Subject: [PATCH 2/2] Add cv/Mat->empty() Add cv/Mat->isSubmatrix() Signed-off-by: MaleicAcid --- source/opencv2/core/opencv_mat.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source/opencv2/core/opencv_mat.cc b/source/opencv2/core/opencv_mat.cc index aef8280..2472be7 100644 --- a/source/opencv2/core/opencv_mat.cc +++ b/source/opencv2/core/opencv_mat.cc @@ -122,6 +122,12 @@ PHP_METHOD(opencv_mat, channels) RETURN_LONG(obj->mat->channels()); } +PHP_METHOD(opencv_mat, empty) +{ + opencv_mat_object *obj = Z_PHP_MAT_OBJ_P(getThis()); + RETURN_LONG(obj->mat->empty()); +} + PHP_METHOD(opencv_mat, zeros) { @@ -175,6 +181,18 @@ PHP_METHOD(opencv_mat, is_continuous) RETURN_BOOL(isContinuous); } +/** + * Mat->isSubmatrix + * @param execute_data + * @param return_value + */ +PHP_METHOD(opencv_mat, is_submatrix) +{ + opencv_mat_object *obj = Z_PHP_MAT_OBJ_P(getThis()); + bool isSubmatrix = obj->mat->isSubmatrix(); + RETURN_BOOL(isSubmatrix); +} + /** * Mat->row(y) * @param execute_data @@ -382,9 +400,11 @@ const zend_function_entry opencv_mat_methods[] = { PHP_ME(opencv_mat, type, NULL, ZEND_ACC_PUBLIC) PHP_ME(opencv_mat, depth, NULL, ZEND_ACC_PUBLIC) PHP_ME(opencv_mat, channels, NULL, ZEND_ACC_PUBLIC) + PHP_ME(opencv_mat, empty, NULL, ZEND_ACC_PUBLIC) PHP_ME(opencv_mat, print, NULL, ZEND_ACC_PUBLIC) PHP_ME(opencv_mat, zeros, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_MALIAS(opencv_mat, isContinuous ,is_continuous, NULL, ZEND_ACC_PUBLIC) + PHP_MALIAS(opencv_mat, isSubmatrix ,is_submatrix, NULL, ZEND_ACC_PUBLIC) PHP_ME(opencv_mat, row, NULL, ZEND_ACC_PUBLIC) PHP_ME(opencv_mat, col, NULL, ZEND_ACC_PUBLIC) PHP_ME(opencv_mat, at, NULL, ZEND_ACC_PUBLIC)