5 Commits

Autor SHA1 Mensagem Data
hihozhou 955aca44e0 Merge branch 'master' into dev 2018-01-20 11:12:36 +08:00
hihozhou f8e514c033 modify .travis.yml 2018-01-20 11:10:40 +08:00
hihozhou 5ad4d2e24e debug 2018-01-20 11:10:17 +08:00
hihozhou 4adfd2c1a1 Add CV\RotatedRect->points() and CV\getRectSubPix function 2017-11-10 14:10:11 +08:00
hihozhou d0610a981e Add CV\warpAffine function 2017-11-09 16:27:17 +08:00
42 arquivos alterados com 774 adições e 1870 exclusões
-17
Ver Arquivo
@@ -1,17 +0,0 @@
<!--
1. For using of php-opencv-examples you need: PHP 7.0 / 7.1 / 7.2 / 7.3 / 7.4 / 8.0, OpenCV 4.0.0+ and php-opencv
Please read full information about Installation in 3 steps: https://github.com/php-opencv/php-opencv/wiki/Installation:
- install opencv 4.0.0+
- install php-opencv for your php version
- install php-opencv-examples
2. If you have problems - try to resolve it by yourself with using info on pages:
- https://github.com/php-opencv/php-opencv/wiki/Installation.-troubleshooting
- https://github.com/php-opencv/php-opencv/issues?q=is%3Aissue
- https://github.com/php-opencv/php-opencv-examples/issues?q=is%3Aissue
3. If you have problems with installation please provide full information (logs of commands in console and results)
4. If you have problems with using php-opencv-examples please provide full information (logs of commands in console and results)
5. If you have problems with your own code please provide full information (your full code, logs of commands in console and results)
-->
+80 -9
Ver Arquivo
@@ -1,15 +1,86 @@
language: php
sudo: required
services:
- docker
compiler:
- gcc
- clang
os:
- linux
# - osx
php:
- 7.0
- 7.1
- 7.2
notifications:
email: hihozhou@gmail.com
before_install:
- docker pull ubuntu:20.10
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
- sudo apt-get -qq update
- sudo apt-get install gcc-4.8 -y -qq
- sudo apt-get install g++-4.8 -y -qq
- sudo apt-get install python3-numpy
install:
# OpenCV dependencies - Details available at: http://docs.opencv.org/trunk/doc/tutorials/introduction/linux_install/linux_install.html
- sudo apt-get install -y build-essential
# Install Cmake
- wget https://cmake.org/files/v3.8/cmake-3.8.2.tar.gz
- tar -zxf cmake-3.8.2.tar.gz
- cd cmake-3.8.2
- ./configure
- make
- sudo make install
- cd ..
- sudo apt-get install -y git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev -qq
- sudo apt-get install -y python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev -qq
# Download OpenCV-contrib v3.3.0-rc
#- git clone https://github.com/opencv/opencv_contrib.git
#- cd opencv_contrib
#- git checkout 3.3.0-rc
#- cd ..
# Download OpenCV v3.3.0-rc
- git clone https://github.com/opencv/opencv.git
- cd opencv
- git checkout 3.3.0-rc
# Create a new 'build' folder.
- mkdir build
- cd build
# Set build instructions for Ubuntu distro.
#- cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ..
- cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
# Run 'make' with four threads.
- make -j6
# Install to OS.
- sudo make install
# Add configuration to OpenCV to tell it where the library files are located on the file system (/usr/local/lib)
- sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
- sudo ldconfig
- echo "OpenCV installed."
# We need to return to the repo "root" folder, so we can then 'cd' into the C++ project folder.
- cd ../../
#addons:
# apt:
# sources:
# - george-edison55-precise-backports
# packages:
# - cmake-data
# - cmake
#Compile
before_script:
- ./travis/compile.sh
script:
- docker build .
branches:
only:
- master
- exit 0
-16
Ver Arquivo
@@ -1,16 +0,0 @@
FROM morozovsk/php-opencv:travis
#FROM ubuntu:20.10
#RUN apt update && export DEBIAN_FRONTEND=noninteractive && apt install -y wget cmake git php-common pkg-config
#RUN apt install -y software-properties-common
#RUN add-apt-repository ppa:ondrej/php
#RUN apt update
#RUN export DEBIAN_FRONTEND=noninteractive && apt install -y php8.0 php8.0-dev
#RUN wget https://raw.githubusercontent.com/php-opencv/php-opencv-packages/master/opencv_4.5.0_amd64.deb && dpkg -i opencv_4.5.0_amd64.deb && rm opencv_4.5.0_amd64.deb
RUN git clone https://github.com/php-opencv/php-opencv.git
RUN cd php-opencv && phpize && ./configure --with-php-config=/usr/bin/php-config && make && make install && make test
+144 -31
Ver Arquivo
@@ -1,39 +1,152 @@
## PHP-OPENCV - PHP extension for OpenCV
# PHP-OPENCV - PHP extension for Opencv
[![Build Status](https://travis-ci.org/php-opencv/php-opencv.svg?branch=master)](https://travis-ci.org/php-opencv/php-opencv) [![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.0-8892BF.svg)](https://php.net/)
[![Build Status](https://travis-ci.org/hihozhou/php-opencv.svg?branch=master)](https://travis-ci.org/hihozhou/php-opencv) [![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.0-8892BF.svg)](https://php.net/)
#### Installation (2 steps)
- [install opencv 4.0.0+](https://github.com/php-opencv/php-opencv/wiki/Installation.-opencv)
- [install php-opencv for your php version](https://github.com/php-opencv/php-opencv/wiki/Installation.-php-opencv)
- [install php-opencv-examples](https://github.com/php-opencv/php-opencv/wiki/Installation.-php-opencv-examples) (if you need it)
- [resolve problems](https://github.com/php-opencv/php-opencv/wiki/Installation.-troubleshooting) (if you need it)
#### Examples
- [dnn](https://github.com/php-opencv/php-opencv-examples)
- [core](https://github.com/hihozhou/php-opencv)
## Document
- [PHP OpenCV Doc](http://phpopencv.org/zh-cn/docs/)
- [PHP OpenCV Api](http://phpopencv.org/zh-cn/api/)
#### Documentation
- [PHP OpenCV Doc](https://phpopencv.org/docs/index.html)
- [PHP OpenCV Api](https://phpopencv.org/api/index.html)
#### Requirements
- OpenCV 4.0.0+
- PHP 7.0 / 7.1 / 7.2 / 7.3 / 7.4 / 8.0
## Requirements
#### Features
- [core](https://phpopencv.org/docs/mat.html)
- [imgproc](https://phpopencv.org/docs/gausian_median_blur_bilateral_filter.html)
- highgui
- objdetect
- video
- ml
- dnn
- OpenCV 3.3.0+
- PHP7.0+
#### Helper for autocomplete and highlighting in your IDE
- [phpdoc file](https://github.com/php-opencv/php-opencv-examples/blob/master/phpdoc.php)
- [php-opencv-ide-helper](https://github.com/hihozhou/php-opencv-ide-helper)
#### Contributors
- [@morozovsk](https://github.com/morozovsk)
- [@hihozhou](https://github.com/hihozhou)
- [@MaleicAcid](https://github.com/MaleicAcid)
## Installation
```bash
git clone https://github.com/hihozhou/php-opencv.git
cd php-opencv
phpize
./configure --with-php-config=your php-config path
make
make install
```
## Configure
php.ini
```
extension="your opencv.so path"
```
## Example
### LBPH face recognition
```php
use CV\Face\LBPHFaceRecognizer;
//use ...;
$src = imread('facePic.jpg');
$gray = cvtColor($src, COLOR_BGR2GRAY);
equalizeHist($gray, $gray);
$faceRecognizer = LBPHFaceRecognizer::create();
/* ... */ //get $images and $labels for train
$faceRecognizer->train($images, $labels);//How to get $image and $labels, see the document
/* ... */ //Face detection using CascadeClassifier
$faceLabel = $faceRecognizer->predict($gray);
/* ... */ //draw face and name
```
result:
![predict](tests/face_recognizer.jpg)
### Image Processing
```php
//Obama.php
use function CV\{ imread, imshow, waitkey, namedWindow};
$im = imread('Obama.png');//load image
namedWindow('This is Obama id card',WINDOW_FULLSCREEN);//create window
imshow('This is Obama id card',$im);//show image on window
waitkey(0);
```
result:
![Obama](tests/Obama.png)
Load image by gray
```php
$gray = imread('Obama.png',IMREAD_GRAYSCALE);
//or
use function CV\{ cvtColor};
$gray = cvtColor($im, COLOR_BGR2GRAY);
```
![Obama_gray](tests/Obama_gray.png)
You can draw something.
e.g:
```php
use CV\{Mat,Scalar, Point, Size};
use function CV\{ellipse, imwrite, waitKey};
use const CV\{CV_8UC3};
$windowWidth = 600;
$thickness = 2;
$lineType = 8;
$matScalar = new Scalar(0,0,0);
$mat = new Mat($windowWidth, $windowWidth, CV_8UC3, $matScalar);
$point=new Point($windowWidth/2, $windowWidth/2);
$size=new Size($windowWidth/4, $windowWidth/16);
$scalar=new Scalar(255, 129, 0);
for($i = 0; $i <= 360; $i += 45){
ellipse($mat,$point,$size,$i,0,360,$scalar,$thickness,$lineType);
}
imwrite('./tests/ellipse.png',$mat);
```
result:
![ellipse](tests/ellipse.png)
## Features
- [x] 1.[core](http://phpopencv.org/zh-cn/docs/mat.html)
- [x] 2.[imgproc](http://phpopencv.org/zh-cn/docs/gausian_median_blur_bilateral_filter.html)
- [x] 3.highgui
- [ ] 4.contrib
- [ ] 5.features2d
- [ ] 6.flann
- [ ] 7.gpu
- [ ] 8.calib3d
- [ ] 9.legacy
- [x] 10.ml
- [ ] 11.nonfree
- [x] 12.objdetect
- [ ] 13.ocl
- [ ] 14.photo
- [ ] 15.stitching
- [ ] 16.superres
- [ ] 17.ts
- [x] 18.video
- [ ] 19.Videostab
## Contributors
[@hihozhou](https://github.com/hihozhou)
[@MaleicAcid](https://github.com/MaleicAcid)
## 感谢
感谢[韩天峰](https://github.com/matyhtf)老大的指导,
感谢[盘古大叔](https://github.com/pangudashu)的[php7-internal](https://github.com/pangudashu/php7-internal)项目以及平常的指导,
感谢`木桶技术升级交流群``黑夜路人技术群`、以及`PHP内核交流`的群友对技术的帮助。
+7 -9
Ver Arquivo
@@ -49,9 +49,7 @@ if test "$PHP_OPENCV" != "no"; then
source/opencv2/opencv_videoio.cc \
source/opencv2/opencv_face.cc \
source/opencv2/face/opencv_facerec.cc \
source/opencv2/face/opencv_facemarkLBF.cc \
source/opencv2/core/opencv_cvdef.cc \
source/opencv2/dnn/opencv_dnn.cc \
source/opencv2/opencv_ml.cc"
@@ -66,19 +64,19 @@ if test "$PHP_OPENCV" != "no"; then
if test -f "$PKG_CONFIG"; then
AC_MSG_RESULT(found)
AC_MSG_CHECKING(for opencv)
if $PKG_CONFIG --exists opencv4; then
if $PKG_CONFIG --atleast-version=4.0.0 opencv4; then
opencv_version=`$PKG_CONFIG --modversion opencv4`
if $PKG_CONFIG --exists opencv; then
if $PKG_CONFIG --atleast-version=3.3.0 opencv; then
opencv_version=`$PKG_CONFIG --modversion opencv`
AC_MSG_RESULT([found $opencv_version])
dnl Add c++ opencv libs and includes by pkg-config
OPENCV_LIBS=`$PKG_CONFIG --libs opencv4`
OPENCV_INCS=`$PKG_CONFIG --cflags opencv4`
OPENCV_LIBS=`$PKG_CONFIG --libs opencv`
OPENCV_INCS=`$PKG_CONFIG --cflags opencv`
PHP_EVAL_INCLINE($OPENCV_INCS)
PHP_EVAL_LIBLINE($OPENCV_LIBS, OPENCV_SHARED_LIBADD)
AC_DEFINE(HAVE_OPENCV, 1, [whether opencv exists in the system])
else
AC_MSG_RESULT(too old)
AC_MSG_ERROR(Ooops ! You need at least opencv 4.0.0)
AC_MSG_ERROR(Ooops ! You need at least opencv 3.3.0)
fi
else
AC_MSG_RESULT(not found)
@@ -90,4 +88,4 @@ if test "$PHP_OPENCV" != "no"; then
fi
fi
fi
+34 -45
Ver Arquivo
@@ -43,7 +43,6 @@ extern "C" {
#include "source/opencv2/core/opencv_utility.h"
#include "source/opencv2/opencv_ml.h"
#include "source/opencv2/core/opencv_cvdef.h"
#include "source/opencv2/dnn/opencv_dnn.h"
/* If you declare any globals in php_opencv.h uncomment this:
ZEND_DECLARE_MODULE_GLOBALS(opencv)
@@ -125,7 +124,6 @@ PHP_MINIT_FUNCTION(opencv)
opencv_objdetect_init(module_number);
opencv_videoio_init(module_number);
opencv_face_init(module_number);
opencv_dnn_init(module_number);
opencv_ml_init(module_number);
opencv_cvdef_init(module_number);
@@ -183,39 +181,35 @@ PHP_MINFO_FUNCTION(opencv)
*
* Every user visible function must have an entry in opencv_functions[].
*/
ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0)
ZEND_END_ARG_INFO()
const zend_function_entry opencv_functions[] = {
PHP_FE(confirm_opencv_compiled, arginfo_void) /* For testing, remove later. */
ZEND_NS_NAMED_FE(OPENCV_NS, CV_8UC, ZEND_FN(opencv_cv_8uc), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, CV_8SC, ZEND_FN(opencv_cv_8sc), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, CV_16UC, ZEND_FN(opencv_cv_16uc), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, CV_16SC, ZEND_FN(opencv_cv_16sc), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, CV_32SC, ZEND_FN(opencv_cv_32sc), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, CV_32FC, ZEND_FN(opencv_cv_32fc), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, CV_64FC, ZEND_FN(opencv_cv_64fc), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, imread, ZEND_FN(opencv_imread), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, imwrite, ZEND_FN(opencv_imwrite), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, imshow, ZEND_FN(opencv_imshow), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, waitKey, ZEND_FN(opencv_wait_key), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, moveWindow, ZEND_FN(opencv_move_window), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, namedWindow, ZEND_FN(opencv_named_window), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, cvtColor, ZEND_FN(opencv_cv_t_color), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, ellipse, ZEND_FN(opencv_ellipse), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, circle, ZEND_FN(opencv_circle), arginfo_void)
PHP_FE(confirm_opencv_compiled, NULL) /* For testing, remove later. */
ZEND_NS_NAMED_FE(OPENCV_NS, CV_8UC, ZEND_FN(opencv_cv_8uc), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, CV_8SC, ZEND_FN(opencv_cv_8sc), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, CV_16UC, ZEND_FN(opencv_cv_16uc), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, CV_16SC, ZEND_FN(opencv_cv_16sc), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, CV_32SC, ZEND_FN(opencv_cv_32sc), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, CV_32FC, ZEND_FN(opencv_cv_32fc), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, CV_64FC, ZEND_FN(opencv_cv_64fc), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, imread, ZEND_FN(opencv_imread), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, imwrite, ZEND_FN(opencv_imwrite), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, imshow, ZEND_FN(opencv_imshow), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, waitKey, ZEND_FN(opencv_wait_key), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, moveWindow, ZEND_FN(opencv_move_window), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, namedWindow, ZEND_FN(opencv_named_window), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, cvtColor, ZEND_FN(opencv_cv_t_color), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, ellipse, ZEND_FN(opencv_ellipse), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, circle, ZEND_FN(opencv_circle), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, fillPoly, ZEND_FN(opencv_fill_poly), opencv_fill_poly_arginfo)
ZEND_NS_NAMED_FE(OPENCV_NS, line, ZEND_FN(opencv_line), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, rectangle, ZEND_FN(opencv_rectangle), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, rectangleByPoint, ZEND_FN(opencv_rectangle_by_point), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, rectangleByRect, ZEND_FN(opencv_rectangle_by_rect), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, line, ZEND_FN(opencv_line), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, rectangle, ZEND_FN(opencv_rectangle), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, rectangleByPoint, ZEND_FN(opencv_rectangle_by_point), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, rectangleByRect, ZEND_FN(opencv_rectangle_by_rect), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, addWeighted, ZEND_FN(opencv_add_weighted), opencv_add_weighted_arginfo)
ZEND_NS_NAMED_FE(OPENCV_NS, split, ZEND_FN(opencv_split), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, split, ZEND_FN(opencv_split), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, merge, ZEND_FN(opencv_merge), opencv_merge_arginfo)
ZEND_NS_NAMED_FE(OPENCV_NS, createTrackbar, ZEND_FN(opencv_create_trackbar), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, destroyWindow, ZEND_FN(opencv_destroy_window), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, getOptimalDFTSize, ZEND_FN(opencv_get_optimal_dft_size), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, createTrackbar, ZEND_FN(opencv_create_trackbar), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, destroyWindow, ZEND_FN(opencv_destroy_window), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, getOptimalDFTSize, ZEND_FN(opencv_get_optimal_dft_size), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, copyMakeBorder, ZEND_FN(opencv_copy_make_border), opencv_copy_make_border_arginfo)
ZEND_NS_NAMED_FE(OPENCV_NS, dft, ZEND_FN(opencv_dft), opencv_dft_arginfo)
ZEND_NS_NAMED_FE(OPENCV_NS, magnitude, ZEND_FN(opencv_magnitude), opencv_magnitude_arginfo)
@@ -224,9 +218,9 @@ const zend_function_entry opencv_functions[] = {
ZEND_NS_NAMED_FE(OPENCV_NS, normalize, ZEND_FN(opencv_normalize), opencv_normalize_arginfo)
ZEND_NS_NAMED_FE(OPENCV_NS, equalizeHist, ZEND_FN(opencv_equalize_hist), opencv_equalize_hist_arginfo)
ZEND_NS_NAMED_FE(OPENCV_NS, resize, ZEND_FN(opencv_resize), opencv_resize_arginfo)
ZEND_NS_NAMED_FE(OPENCV_NS, putText, ZEND_FN(opencv_put_text), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, putText, ZEND_FN(opencv_put_text), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, absdiff, ZEND_FN(opencv_absdiff), opencv_absdiff_arginfo)
ZEND_NS_NAMED_FE(OPENCV_NS, getTrackBarPos, ZEND_FN(opencv_get_track_bar_pos), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, getTrackBarPos, ZEND_FN(opencv_get_track_bar_pos), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, blur, ZEND_FN(opencv_blur), opencv_blur_arginfo)
ZEND_NS_NAMED_FE(OPENCV_NS, GaussianBlur, ZEND_FN(opencv_gaussian_blur), opencv_gaussian_blur_arginfo)
ZEND_NS_NAMED_FE(OPENCV_NS, medianBlur, ZEND_FN(opencv_median_blur), opencv_median_blur_arginfo)
@@ -242,22 +236,17 @@ const zend_function_entry opencv_functions[] = {
ZEND_NS_NAMED_FE(OPENCV_NS, threshold, ZEND_FN(opencv_threshold), opencv_threshold_arginfo)
ZEND_NS_NAMED_FE(OPENCV_NS, morphologyEx, ZEND_FN(opencv_morphology_ex), opencv_morphology_ex_arginfo)
ZEND_NS_NAMED_FE(OPENCV_NS, LUT, ZEND_FN(opencv_lut), opencv_lut_arginfo)
ZEND_NS_NAMED_FE(OPENCV_NS, getTickCount, ZEND_FN(opencv_get_tick_count), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, getTickFrequency, ZEND_FN(opencv_get_tick_frequency), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, getTickCount, ZEND_FN(opencv_get_tick_count), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, getTickFrequency, ZEND_FN(opencv_get_tick_frequency), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, floodFill, ZEND_FN(opencv_flood_fill), opencv_flood_fill_arginfo)
ZEND_NS_NAMED_FE(OPENCV_NS, setMouseCallback, ZEND_FN(opencv_set_mouse_callback), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, setMouseCallback, ZEND_FN(opencv_set_mouse_callback), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, adaptiveThreshold, ZEND_FN(opencv_adaptive_threshold), opencv_adaptive_threshold_arginfo)
ZEND_NS_NAMED_FE(OPENCV_NS, findContoursWithoutHierarchy, ZEND_FN(opencv_find_contours_without_hierarchy), opencv_find_contours_without_hierarchy_arginfo)
ZEND_NS_NAMED_FE(OPENCV_NS, drawContours, ZEND_FN(opencv_draw_contours), opencv_draw_contours_arginfo)
ZEND_NS_NAMED_FE(OPENCV_NS, boundingRect, ZEND_FN(opencv_bounding_rect), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_DNN_NS, blobFromImage, ZEND_FN(opencv_dnn_blob_from_image), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_DNN_NS, readNetFromCaffe, ZEND_FN(opencv_dnn_read_net_from_caffe), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_DNN_NS, readNetFromTorch, ZEND_FN(opencv_dnn_read_net_from_torch), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_DNN_NS, readNetFromTensorflow, ZEND_FN(opencv_dnn_read_net_from_tensorflow), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_DNN_NS, readNetFromONNX, ZEND_FN(opencv_dnn_read_net_from_onnx), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_DNN_NS, readNetFromModelOptimizer, ZEND_FN(opencv_dnn_read_net_from_model_optimizer), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_DNN_NS, readNetFromDarknet, ZEND_FN(opencv_dnn_read_net_from_darknet), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, imdecode, ZEND_FN(opencv_imdecode), arginfo_void)
ZEND_NS_NAMED_FE(OPENCV_NS, boundingRect, ZEND_FN(opencv_bounding_rect), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, getRotationMatrix2D, ZEND_FN(opencv_get_rotation_matrix2D), NULL)
ZEND_NS_NAMED_FE(OPENCV_NS, warpAffine, ZEND_FN(opencv_warp_affine), opencv_warp_affine_arginfo)
ZEND_NS_NAMED_FE(OPENCV_NS, getRectSubPix, ZEND_FN(opencv_get_rect_sub_pix), opencv_get_rect_sub_pix_arginfo)
PHP_FE_END /* Must be the last line in opencv_functions[] */
};
/* }}} */
-1
Ver Arquivo
@@ -49,7 +49,6 @@ using namespace cv;
#define OPENCV_NS "CV"
#define OPENCV_FACE_NS ZEND_NS_NAME(OPENCV_NS,"Face")
#define OPENCV_ML_NS ZEND_NS_NAME(OPENCV_NS,"ML")
#define OPENCV_DNN_NS ZEND_NS_NAME(OPENCV_NS,"DNN")
#define OPENCV_CONNECT(text1,text2) text1##text2
+1 -2
Ver Arquivo
@@ -27,8 +27,7 @@ void opencv_interface_init(int module_number)
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "CV_32S", CV_32S, CONST_CS | CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "CV_32F", CV_32F, CONST_CS | CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "CV_64F", CV_64F, CONST_CS | CONST_PERSISTENT);
char *cv_usrtype1 = (char*)malloc(strlen("CV_USRTYPE1 support has been dropped in OpenCV 4.0") + 1);
REGISTER_NS_STRING_CONSTANT(OPENCV_NS, "CV_USRTYPE1", cv_usrtype1, CONST_CS | CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "CV_USRTYPE1", CV_USRTYPE1, CONST_CS | CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "CV_8UC1", CV_8UC1, CONST_CS | CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "CV_8UC2", CV_8UC2, CONST_CS | CONST_PERSISTENT);
+103 -323
Ver Arquivo
@@ -30,9 +30,9 @@ zend_class_entry *opencv_mat_ce;
*/
zend_object* opencv_mat_create_handler(zend_class_entry *type)
{
int size = sizeof(opencv_mat_object)+zend_object_properties_size(type);
int size = sizeof(opencv_mat_object);
opencv_mat_object *obj = (opencv_mat_object *)ecalloc(1,size);
memset(obj, 0, size);
memset(obj, 0, sizeof(opencv_mat_object));
zend_object_std_init(&obj->std, type);
object_properties_init(&obj->std, type);
obj->std.ce = type;
@@ -50,111 +50,10 @@ 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_OBJ_P(z), "rows", sizeof("rows")-1, mat->rows);
zend_update_property_long(opencv_mat_ce, Z_OBJ_P(z), "cols", sizeof("cols")-1, mat->cols);
zend_update_property_long(opencv_mat_ce, Z_OBJ_P(z), "dims", sizeof("dims")-1, mat->dims);
zend_update_property_long(opencv_mat_ce, Z_OBJ_P(z), "type", sizeof("type")-1, mat->type());
//zend_update_property_long(opencv_mat_ce, Z_OBJ_P(z), "depth", sizeof("depth")-1, mat->depth());
if (mat->dims > 2) {
zval shape_zval;
array_init(&shape_zval);
for(int i = 0; i < mat->dims; i++)
{
add_next_index_long(&shape_zval, mat->size.p[i]);
}
zend_update_property(opencv_mat_ce, Z_OBJ_P(z), "shape", sizeof("shape")-1, &shape_zval);
}
}
void opencv_mat_at(Mat *mat, int *idx, long channel, zval *value_zval, long *return_long_val, double *return_double_val) {
uchar *return_uchar_val;
schar *return_schar_val;
ushort *return_ushort_val;
short *return_short_val;
int *return_int_val;
float *return_float_val;
switch(mat->type()) {
//CV_8U
case CV_8UC1: return_uchar_val = &mat->at<uchar>(idx); break;
case CV_8UC2: return_uchar_val = &mat->at<Vec2b>(idx)[channel]; break;
case CV_8UC3: return_uchar_val = &mat->at<Vec3b>(idx)[channel]; break;
case CV_8UC4: return_uchar_val = &mat->at<Vec4b>(idx)[channel]; break;
//CV_8S
case CV_8SC1: return_schar_val = &mat->at<schar>(idx); break;
case CV_8SC2: return_schar_val = &mat->at<Vec<schar, 2>>(idx)[channel]; break;
case CV_8SC3: return_schar_val = &mat->at<Vec<schar, 3>>(idx)[channel]; break;
case CV_8SC4: return_schar_val = &mat->at<Vec<schar, 4>>(idx)[channel]; break;
//CV_16U
case CV_16UC1: return_ushort_val = &mat->at<ushort>(idx); break;
case CV_16UC2: return_ushort_val = &mat->at<Vec2w>(idx)[channel]; break;
case CV_16UC3: return_ushort_val = &mat->at<Vec3w>(idx)[channel]; break;
case CV_16UC4: return_ushort_val = &mat->at<Vec4w>(idx)[channel]; break;
//CV_16S
case CV_16SC1: return_short_val = &mat->at<short>(idx); break;
case CV_16SC2: return_short_val = &mat->at<Vec2s>(idx)[channel]; break;
case CV_16SC3: return_short_val = &mat->at<Vec3s>(idx)[channel]; break;
case CV_16SC4: return_short_val = &mat->at<Vec4s>(idx)[channel]; break;
//CV_32S
case CV_32SC1: return_int_val = &mat->at<int>(idx); break;
case CV_32SC2: return_int_val = &mat->at<Vec2i>(idx)[channel]; break;
case CV_32SC3: return_int_val = &mat->at<Vec3i>(idx)[channel]; break;
case CV_32SC4: return_int_val = &mat->at<Vec4i>(idx)[channel]; break;
//CV_32F
case CV_32FC1: return_float_val = &mat->at<float>(idx); break;
case CV_32FC2: return_float_val = &mat->at<Vec2f>(idx)[channel]; break;
case CV_32FC3: return_float_val = &mat->at<Vec3f>(idx)[channel]; break;
case CV_32FC4: return_float_val = &mat->at<Vec4f>(idx)[channel]; break;
//CV_64F
case CV_64FC1: return_double_val = &mat->at<double>(idx); break;
case CV_64FC2: return_double_val = &mat->at<Vec2d>(idx)[channel]; break;
case CV_64FC3: return_double_val = &mat->at<Vec3d>(idx)[channel]; break;
case CV_64FC4: return_double_val = &mat->at<Vec4d>(idx)[channel]; break;
default: opencv_throw_exception("Wrong Mat type"); break;
}
//get px value
switch(mat->depth()){
case CV_8U: *return_long_val = *return_uchar_val; break;
case CV_8S: *return_long_val = *return_schar_val; break;
case CV_16U: *return_long_val = *return_ushort_val; break;
case CV_16S: *return_long_val = *return_short_val; break;
case CV_32S: *return_long_val = *return_int_val; break;
case CV_32F: *return_double_val = *return_float_val; break;
case CV_64F: break;
default: opencv_throw_exception("Wrong Mat type"); break;
}
//set px value
if (value_zval != NULL) {
switch(mat->depth()){
case CV_32F:
case CV_64F: convert_to_double(value_zval); break;
default: convert_to_long(value_zval); break;
}
zend_long value = Z_LVAL_P(value_zval);
switch(mat->depth()){
case CV_8U: *return_uchar_val = saturate_cast<uchar>(Z_LVAL_P(value_zval)); break;
case CV_8S: *return_schar_val = saturate_cast<schar>(Z_LVAL_P(value_zval)); break;
case CV_16U: *return_ushort_val = saturate_cast<ushort>(Z_LVAL_P(value_zval)); break;
case CV_16S: *return_short_val = saturate_cast<short>(Z_LVAL_P(value_zval)); break;
case CV_32S: *return_int_val = saturate_cast<int>(Z_LVAL_P(value_zval)); break;
case CV_32F: *return_float_val = saturate_cast<float>(Z_DVAL_P(value_zval)); break;
case CV_64F: *return_double_val = saturate_cast<double>(Z_DVAL_P(value_zval)); break;
default: opencv_throw_exception("Wrong Mat type"); break;
}
}
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());
}
/**
@@ -196,77 +95,11 @@ PHP_METHOD(opencv_mat, print)
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &type) == FAILURE) {
RETURN_NULL();
}
opencv_mat_object *obj = Z_PHP_MAT_OBJ_P(getThis());
//long转cv::Formatter::FormatType类型
cv::Formatter::FormatType formatType = static_cast<cv::Formatter::FormatType>((int)type);
std::cout << format(*(obj->mat), formatType) << std::endl;
std::cout << format(*(obj->mat),int(type)) << std::endl;
RETURN_NULL();
}
/**
* toString Mat data
* @param execute_data
* @param return_value
*/
PHP_METHOD(opencv_mat, toString)
{
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) {
RETURN_NULL();
}
opencv_mat_object *obj = Z_PHP_MAT_OBJ_P(getThis());
//long转cv::Formatter::FormatType类型
cv::Formatter::FormatType formatType = static_cast<cv::Formatter::FormatType>(0);
std::ostringstream stream;
stream << format(*(obj->mat), formatType);
std::string str = stream.str();
const char* chr = str.c_str();
RETURN_STRING(chr);
}
/**
* toArray Mat data
* @param execute_data
* @param return_value
*/
PHP_METHOD(opencv_mat, data)
{
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) {
RETURN_NULL();
}
opencv_mat_object *obj = Z_PHP_MAT_OBJ_P(getThis());
zval shape_zval;
array_init(&shape_zval);
if (obj->mat->isContinuous()) {
for(int channel = 0; channel < obj->mat->channels(); channel++)
{
for(int i = 0; i < obj->mat->total(); i++)
{
switch(obj->mat->depth()){
case CV_8U: add_next_index_long(&shape_zval, obj->mat->at<uchar>(i + channel * obj->mat->total())); break;
case CV_8S: add_next_index_long(&shape_zval, obj->mat->at<schar>(i + channel * obj->mat->total())); break;
case CV_16U: add_next_index_long(&shape_zval, obj->mat->at<ushort>(i + channel * obj->mat->total())); break;
case CV_16S: add_next_index_long(&shape_zval, obj->mat->at<short>(i + channel * obj->mat->total())); break;
case CV_32S: add_next_index_long(&shape_zval, obj->mat->at<int>(i + channel * obj->mat->total())); break;
case CV_32F: add_next_index_double(&shape_zval, obj->mat->at<float>(i + channel * obj->mat->total())); break;
case CV_64F: add_next_index_double(&shape_zval, obj->mat->at<double>(i + channel * obj->mat->total()));break;
default: opencv_throw_exception("Wrong Mat type"); break;
}
}
}
}
RETURN_ZVAL(&shape_zval,0,0);
}
PHP_METHOD(opencv_mat, type)
{
@@ -286,12 +119,6 @@ PHP_METHOD(opencv_mat, channels)
RETURN_LONG(obj->mat->channels());
}
PHP_METHOD(opencv_mat, total)
{
opencv_mat_object *obj = Z_PHP_MAT_OBJ_P(getThis());
RETURN_LONG(obj->mat->total());
}
PHP_METHOD(opencv_mat, empty)
{
opencv_mat_object *obj = Z_PHP_MAT_OBJ_P(getThis());
@@ -536,6 +363,7 @@ PHP_METHOD(opencv_mat, copy_to)
}
/**
* //todo int,fload,double
* CV\Mat->at
* @param execute_data
* @param return_value
@@ -545,92 +373,81 @@ PHP_METHOD(opencv_mat, at)
long row, col, channel;
zval *value_zval = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|lz", &row, &col, &channel, &value_zval) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll|z", &row, &col, &channel, &value_zval) == FAILURE) {
RETURN_NULL();
}
opencv_mat_object *this_object = Z_PHP_MAT_OBJ_P(getThis());
zval *idx_zval;
int *idx;
long return_long_val;
double return_double_val;
if(value_zval == NULL){
//get px value
switch (this_object->mat->channels()){
case 1:
this_object->mat->at<uchar>((int)row,(int)col);
break;
case 2:
RETURN_LONG(this_object->mat->at<Vec2b>((int)row,(int)col)[channel]);
break;
case 3:
RETURN_LONG(this_object->mat->at<Vec3b>((int)row,(int)col)[channel]);
break;
case 4:
RETURN_LONG(this_object->mat->at<Vec4b>((int)row,(int)col)[channel]);
break;
default:
opencv_throw_exception("Get Mat px only channel in 1,2,3,4.");
break;
}
idx = new int(2);
idx[0] = row;
idx[1] = col;
opencv_mat_at(this_object->mat, idx, channel, value_zval, &return_long_val, &return_double_val);
switch (this_object->mat->depth()){
case CV_32F:
case CV_64F:
RETURN_DOUBLE(return_double_val);
default:
RETURN_LONG(return_long_val);
}
}
/**
* CV\Mat->atIdx
* @param execute_data
* @param return_value
*/
PHP_METHOD(opencv_mat, atIdx) // multi dimensions support
{
long channel = 1;
zval *value_zval = NULL;
zval *idx_zval;
int *idx = nullptr;
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "a|lz", &idx_zval, &channel, &value_zval) == FAILURE) {
RETURN_NULL();
}
opencv_mat_object *this_object = Z_PHP_MAT_OBJ_P(getThis());
unsigned long idx_count = zend_hash_num_elements(Z_ARRVAL_P(idx_zval));
if (idx_count == 0) {
opencv_throw_exception("array lenght must be >=1");
RETURN_NULL();
} else if (idx_count != this_object->mat->dims) {
opencv_throw_exception("array lenght must be = dims");
RETURN_NULL();
}
idx = new int(idx_count);
zval *array_val_zval;
zend_ulong _h;
ZEND_HASH_FOREACH_NUM_KEY_VAL(Z_ARRVAL_P(idx_zval),_h,array_val_zval){
again:
if(Z_TYPE_P(array_val_zval) == IS_LONG){
//idx.push_back((int)zval_get_long(array_val_zval));
idx[_h] = (int)zval_get_long(array_val_zval);
}else if(Z_TYPE_P(array_val_zval) == IS_REFERENCE){
array_val_zval = Z_REFVAL_P(array_val_zval);
goto again;
} else {
opencv_throw_exception("array value just number.");
RETURN_NULL();
}else{
//set px value
convert_to_long(value_zval);
zend_long value = Z_LVAL_P(value_zval);
switch(this_object->mat->depth()){
case CV_8U:
switch (this_object->mat->channels()){
case 1:
this_object->mat->at<uchar>((int)row,(int)col) = saturate_cast<uchar>(value);
break;
case 2:
this_object->mat->at<Vec2b>((int)row,(int)col)[channel]=saturate_cast<uchar>(value);
break;
case 3:
this_object->mat->at<Vec3b>((int)row,(int)col)[channel]=saturate_cast<uchar>(value);
break;
case 4:
this_object->mat->at<Vec4b>((int)row,(int)col)[channel]=saturate_cast<uchar>(value);
break;
default:
opencv_throw_exception("Get Mat px only channel in 1,2,3,4.");
break;
}
}ZEND_HASH_FOREACH_END();
break;
default:
switch (this_object->mat->channels()){
case 1:
this_object->mat->at<uchar>((int)row,(int)col) = saturate_cast<char>(value);
break;
case 2:
this_object->mat->at<Vec2b>((int)row,(int)col)[channel]=saturate_cast<char>(value);
break;
case 3:
this_object->mat->at<Vec3b>((int)row,(int)col)[channel]=saturate_cast<char>(value);
break;
case 4:
this_object->mat->at<Vec4b>((int)row,(int)col)[channel]=saturate_cast<char>(value);
break;
default:
opencv_throw_exception("Get Mat px only channel in 1,2,3,4.");
break;
}
break;
}
long return_long_val;
double return_double_val;
opencv_mat_at(this_object->mat, idx, channel, value_zval, &return_long_val, &return_double_val);
switch (this_object->mat->depth()){
case CV_32F:
case CV_64F:
RETURN_DOUBLE(return_double_val);
default:
RETURN_LONG(return_long_val);
}
RETURN_NULL();
}
ZEND_BEGIN_ARG_INFO_EX(opencv_mat_convert_to_arginfo, 0, 0, 4)
ZEND_ARG_INFO(1, dst)
ZEND_ARG_INFO(0, rtype)
@@ -737,33 +554,6 @@ PHP_METHOD(opencv_mat, divide)
RETURN_ZVAL(&instance,0,0); //return php Mat object
}
/**
* Mat->reshape()
* @param execute_data
* @param return_value
*/
PHP_METHOD(opencv_mat, reshape)
{
zval instance;
long cn;
long rows = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", &cn, &rows) == FAILURE) {
RETURN_NULL();
}
object_init_ex(&instance, opencv_mat_ce);
opencv_mat_object *new_obj = Z_PHP_MAT_OBJ_P(&instance);
opencv_mat_object *obj = Z_PHP_MAT_OBJ_P(getThis());
Mat im = obj->mat->reshape(cn, rows);
new_obj->mat=new Mat(im);
opencv_mat_update_property_by_c_mat(&instance, new_obj->mat);
RETURN_ZVAL(&instance,0,0); //return php Mat object
}
/**
@@ -845,41 +635,35 @@ PHP_METHOD(opencv_mat, subtract)
RETURN_ZVAL(&instance,0,0); //return php Mat object
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0)
ZEND_END_ARG_INFO()
/**
* opencv_mat_methods[]
*/
const zend_function_entry opencv_mat_methods[] = {
PHP_ME(opencv_mat, __construct, arginfo_void, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(opencv_mat, type, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, depth, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, channels, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, empty, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, print, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, toString, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, data, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, size, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, clone, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, ones, arginfo_void, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(opencv_mat, zeros, arginfo_void, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_MALIAS(opencv_mat, zerosBySize ,zeros_by_size, arginfo_void, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_MALIAS(opencv_mat, isContinuous ,is_continuous, arginfo_void, ZEND_ACC_PUBLIC)
PHP_MALIAS(opencv_mat, isSubmatrix ,is_submatrix, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, row, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, col, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, at, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, atIdx, arginfo_void, ZEND_ACC_PUBLIC)
PHP_MALIAS(opencv_mat, getImageROI ,get_image_roi, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
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, size, NULL, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, clone, NULL, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, ones, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(opencv_mat, zeros, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_MALIAS(opencv_mat, zerosBySize ,zeros_by_size, 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)
PHP_MALIAS(opencv_mat, getImageROI ,get_image_roi, NULL, ZEND_ACC_PUBLIC)
PHP_MALIAS(opencv_mat, copyTo ,copy_to, opencv_mat_copy_to_arginfo, ZEND_ACC_PUBLIC)
PHP_MALIAS(opencv_mat, convertTo ,convert_to, opencv_mat_convert_to_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, plus, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, divide, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, reshape, arginfo_void, ZEND_ACC_PUBLIC)
PHP_MALIAS(opencv_mat, setTo ,set_to, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, add , arginfo_void, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(opencv_mat, subtract , arginfo_void, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(opencv_mat, plus, NULL, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, divide, NULL, ZEND_ACC_PUBLIC)
PHP_MALIAS(opencv_mat, setTo ,set_to, NULL, ZEND_ACC_PUBLIC)
PHP_ME(opencv_mat, add , NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(opencv_mat, subtract , NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_FE_END
};
/* }}} */
@@ -893,17 +677,20 @@ const zend_function_entry opencv_mat_methods[] = {
* @param value
* @param cache_slot
*/
zval *opencv_mat_write_property(zend_object *object, zend_string *member, zval *value, void **cache_slot){
char *memberName=ZSTR_VAL(member);
opencv_mat_object *obj = get_mat_obj(object);
void opencv_mat_write_property(zval *object, zval *member, zval *value, void **cache_slot){
zend_string *str = zval_get_string(member);
char *memberName=ZSTR_VAL(str);
opencv_mat_object *obj = Z_PHP_MAT_OBJ_P(object);
if(strcmp(memberName, "cols") == 0 && obj->mat->cols!=(int)zval_get_long(value)){
obj->mat->cols=(int)zval_get_long(value);
}else if(strcmp(memberName, "rows") == 0 && obj->mat->rows!=(int)zval_get_long(value)){
obj->mat->rows=(int)zval_get_long(value);
}
//zend_string_release(str);//free zend_string not memberName(zend_string->val)
zend_string_release(str);//free zend_string not memberName(zend_string->val)
std_object_handlers.write_property(object,member,value,cache_slot);
return value;
}
/**
@@ -921,14 +708,7 @@ void opencv_mat_init(void){
opencv_mat_object_handlers.write_property = opencv_mat_write_property;
zend_declare_property_null(opencv_mat_ce,"type",sizeof("type") - 1,ZEND_ACC_PRIVATE);//private Mat->type
zend_declare_property_null(opencv_mat_ce,"rows",sizeof("rows") - 1,ZEND_ACC_PUBLIC);
zend_declare_property_null(opencv_mat_ce,"cols",sizeof("cols") - 1,ZEND_ACC_PUBLIC);
zend_declare_property_null(opencv_mat_ce,"dims",sizeof("dims") - 1,ZEND_ACC_PUBLIC);
zend_declare_property_null(opencv_mat_ce,"shape",sizeof("shape") - 1,ZEND_ACC_PUBLIC);
//zval *cd = (zval*)malloc(sizeof(zval)); /* empty zval */
//zend_declare_property(opencv_mat_ce,"shape",sizeof("shape") - 1,cd,ZEND_ACC_PUBLIC);
opencv_mat_object_handlers.free_obj = opencv_mat_free_obj;
opencv_mat_object_handlers.offset = XtOffsetOf(opencv_mat_object, std);
}
+1 -1
Ver Arquivo
@@ -28,8 +28,8 @@ extern zend_class_entry *opencv_mat_ce;
#define Z_PHP_MAT_OBJ_P(zv) get_mat_obj(Z_OBJ_P(zv))
typedef struct _opencv_mat_object{
Mat *mat;
zend_object std;
Mat *mat;
}opencv_mat_object;
+9 -13
Ver Arquivo
@@ -24,9 +24,9 @@ zend_class_entry *opencv_file_storage_ce;
zend_object_handlers opencv_file_storage_object_handlers;
zend_object* opencv_file_storage_create_handler(zend_class_entry *type){
size_t size = sizeof(opencv_file_storage_object)+zend_object_properties_size(type);
size_t size = sizeof(opencv_file_storage_object);
opencv_file_storage_object *obj = (opencv_file_storage_object *)ecalloc(1,size);
memset(obj, 0, size);
memset(obj, 0, sizeof(opencv_file_storage_object));
zend_object_std_init(&obj->std, type);
object_properties_init(&obj->std, type);
obj->std.ce = type;
@@ -224,24 +224,21 @@ PHP_METHOD(opencv_file_storage, is_opened){
RETURN_BOOL(obj->fileStorage->isOpened());
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0)
ZEND_END_ARG_INFO()
/**
* opencv_file_storage_methods[]
*/
const zend_function_entry opencv_file_storage_methods[] = {
PHP_ME(opencv_file_storage, __construct, arginfo_void, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(opencv_file_storage, open, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_file_storage, write, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_file_storage, read, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_file_storage, release, arginfo_void, ZEND_ACC_PUBLIC)
PHP_MALIAS(opencv_file_storage, isOpened ,is_opened, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_file_storage, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(opencv_file_storage, open, NULL, ZEND_ACC_PUBLIC)
PHP_ME(opencv_file_storage, write, NULL, ZEND_ACC_PUBLIC)
PHP_ME(opencv_file_storage, read, NULL, ZEND_ACC_PUBLIC)
PHP_ME(opencv_file_storage, release, NULL, ZEND_ACC_PUBLIC)
PHP_MALIAS(opencv_file_storage, isOpened ,is_opened, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
/* }}} */
zval *opencv_file_storage_read_property(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv){
zval *opencv_file_storage_read_property(zval *object, zval *member, int type, void **cache_slot, zval *rv){
// std::cout<<"opencv_file_storage_read_property"<<std::endl;
return std_object_handlers.read_property(object, member, type, cache_slot, rv);
@@ -281,6 +278,5 @@ void opencv_file_storage_init(int module_number){
// zend_declare_property_null(opencv_mat_ce,"type",sizeof("type") - 1,ZEND_ACC_PRIVATE);//private Mat->type
// opencv_mat_object_handlers.free_obj = opencv_mat_free_obj;
opencv_file_storage_object_handlers.offset = XtOffsetOf(opencv_file_storage_object, std);
opencv_file_storage_consts_init(module_number);
}
+1 -1
Ver Arquivo
@@ -22,8 +22,8 @@
extern zend_class_entry *opencv_file_storage_ce;
typedef struct _opencv_file_storage_object{
FileStorage *fileStorage;
zend_object std;
FileStorage *fileStorage;
}opencv_file_storage_object;
#define Z_PHP_FILE_STORAGE_OBJ_P(zv) get_file_storage_obj(Z_OBJ_P(zv))
+66 -78
Ver Arquivo
@@ -18,6 +18,8 @@
#include "../../../php_opencv.h"
#include "../../../opencv_exception.h"
#include "opencv_type.h"
#include <algorithm>
#include <iostream>
zend_class_entry *opencv_point_ce;
zend_class_entry *opencv_scalar_ce;
@@ -52,8 +54,8 @@ PHP_METHOD(opencv_point, __construct)
}
void opencv_point_update_property_by_c_point(zval *z, Point *point){
zend_update_property_long(opencv_point_ce, Z_OBJ_P(z), "x", sizeof("x")-1, point->x);
zend_update_property_long(opencv_point_ce, Z_OBJ_P(z), "y", sizeof("y")-1, point->y);
zend_update_property_long(opencv_point_ce, z, "x", sizeof("x")-1, point->x);
zend_update_property_long(opencv_point_ce, z, "y", sizeof("y")-1, point->y);
}
@@ -69,24 +71,23 @@ PHP_METHOD(opencv_point, print)
RETURN_NULL();
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0)
ZEND_END_ARG_INFO()
/**
* opencv_point_methods[]
*/
const zend_function_entry opencv_point_methods[] = {
PHP_ME(opencv_point, __construct, arginfo_void, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(opencv_point, print, arginfo_void, ZEND_ACC_PUBLIC) //todo why Point print method can effect Mat print method
PHP_ME(opencv_point, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(opencv_point, print, NULL, ZEND_ACC_PUBLIC) //todo why Point print method can effect Mat print method
PHP_FE_END
};
/* }}} */
zend_object* opencv_point_create_handler(zend_class_entry *type)
{
size_t size = sizeof(opencv_point_object)+zend_object_properties_size(type);
size_t size = sizeof(opencv_point_object);
opencv_point_object *obj = (opencv_point_object *)ecalloc(1,size);
memset(obj, 0, size);
memset(obj, 0, sizeof(opencv_point_object));
zend_object_std_init(&obj->std, type);
object_properties_init(&obj->std, type);
obj->std.ce = type;
@@ -109,18 +110,20 @@ void opencv_point_free_obj(zend_object *object)
* @param value
* @param cache_slot
*/
zval *opencv_point_write_property(zend_object *object, zend_string *member, zval *value, void **cache_slot){
char *memberName=ZSTR_VAL(member);
opencv_point_object *obj = get_point_obj(object);
void opencv_point_write_property(zval *object, zval *member, zval *value, void **cache_slot){
zend_string *str = zval_get_string(member);
char *memberName=ZSTR_VAL(str);
opencv_point_object *obj = Z_PHP_POINT_OBJ_P(object);
if(strcmp(memberName, "x") == 0 && obj->point->x!=(int)zval_get_long(value)){
obj->point->x=(int)zval_get_long(value);
}else if(strcmp(memberName, "y") == 0 && obj->point->y!=(int)zval_get_long(value)){
obj->point->y=(int)zval_get_long(value);
}
//zend_string_release(str);//free zend_string not memberName(zend_string->val)
zend_string_release(str);//free zend_string not memberName(zend_string->val)
std_object_handlers.write_property(object,member,value,cache_slot);
return value;
}
/**
@@ -137,10 +140,6 @@ void opencv_point_init(int module_number){
opencv_point_object_handlers.clone_obj = NULL;
opencv_point_object_handlers.write_property = opencv_point_write_property;
opencv_point_object_handlers.free_obj = opencv_point_free_obj;
opencv_point_object_handlers.offset = XtOffsetOf(opencv_point_object, std);
zend_declare_property_null(opencv_point_ce,"x",sizeof("x") - 1,ZEND_ACC_PUBLIC);
zend_declare_property_null(opencv_point_ce,"y",sizeof("y") - 1,ZEND_ACC_PUBLIC);
}
@@ -157,9 +156,9 @@ zend_object_handlers opencv_scalar_object_handlers;
zend_object* opencv_scalar_create_handler(zend_class_entry *type)
{
size_t size = sizeof(opencv_scalar_object)+zend_object_properties_size(type);
size_t size = sizeof(opencv_scalar_object);
opencv_scalar_object *obj = (opencv_scalar_object *)ecalloc(1,size);
memset(obj, 0, size);
memset(obj, 0, sizeof(opencv_scalar_object));
zend_object_std_init(&obj->std, type);
object_properties_init(&obj->std, type);
obj->std.ce = type;
@@ -183,9 +182,7 @@ void opencv_scalar_update_property_by_c_scalar(zval *z,Scalar *scalar){
add_next_index_double(&val,scalar->val[1]);
add_next_index_double(&val,scalar->val[2]);
add_next_index_double(&val,scalar->val[3]);
zend_update_property(opencv_scalar_ce, Z_OBJ_P(z), "val", sizeof("val")-1, &val);
zend_update_property(opencv_scalar_ce, z, "val", sizeof("val")-1, &val);
/**
* 数组val在array_init()后refcount=1
* 插入成员属性zend_update_property()会自动加一次,变为2
@@ -230,8 +227,8 @@ PHP_METHOD(opencv_scalar, print)
* opencv_scalar_methods[]
*/
const zend_function_entry opencv_scalar_methods[] = {
PHP_ME(opencv_scalar, __construct, arginfo_void, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(opencv_scalar, print, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_scalar, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(opencv_scalar, print, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
/* }}} */
@@ -250,10 +247,6 @@ void opencv_scalar_init(int module_number){
zend_get_std_object_handlers(), sizeof(zend_object_handlers));
opencv_scalar_object_handlers.clone_obj = NULL;
opencv_scalar_object_handlers.free_obj = opencv_scalar_free_obj;
opencv_scalar_object_handlers.offset = XtOffsetOf(opencv_scalar_object, std);
zval *val = (zval*)malloc(sizeof(zval)); /* empty zval */
zend_declare_property(opencv_scalar_ce,"val",sizeof("val") - 1, val, ZEND_ACC_PUBLIC);
}
@@ -267,9 +260,9 @@ zend_object_handlers opencv_size_object_handlers;
zend_object* opencv_size_create_handler(zend_class_entry *type)
{
size_t size = sizeof(opencv_size_object)+zend_object_properties_size(type);
size_t size = sizeof(opencv_size_object);
opencv_size_object *obj = (opencv_size_object *)ecalloc(1,size);
memset(obj, 0, size);
memset(obj, 0, sizeof(opencv_size_object));
zend_object_std_init(&obj->std, type);
object_properties_init(&obj->std, type);
obj->std.ce = type;
@@ -286,8 +279,8 @@ void opencv_size_free_obj(zend_object *object)
}
void opencv_size_update_property_by_c_size(zval *z, Size *size){
zend_update_property_long(opencv_size_ce, Z_OBJ_P(z), "width", sizeof("width")-1, size->width);
zend_update_property_long(opencv_size_ce, Z_OBJ_P(z), "height", sizeof("height")-1, size->height);
zend_update_property_long(opencv_size_ce, z, "width", sizeof("width")-1, size->width);
zend_update_property_long(opencv_size_ce, z, "height", sizeof("height")-1, size->height);
}
@@ -326,8 +319,8 @@ PHP_METHOD(opencv_size, print)
* opencv_size_methods[]
*/
const zend_function_entry opencv_size_methods[] = {
PHP_ME(opencv_size, __construct, arginfo_void, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(opencv_size, print, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_size, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(opencv_size, print, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
/* }}} */
@@ -340,19 +333,20 @@ const zend_function_entry opencv_size_methods[] = {
* @param value
* @param cache_slot
*/
zval *opencv_size_write_property(zend_object *object, zend_string *member, zval *value, void **cache_slot){
char *memberName=ZSTR_VAL(member);
opencv_size_object *obj = get_size_obj(object);
void opencv_size_write_property(zval *object, zval *member, zval *value, void **cache_slot){
zend_string *str = zval_get_string(member);
char *memberName=ZSTR_VAL(str);
opencv_size_object *obj = Z_PHP_SIZE_OBJ_P(object);
if(strcmp(memberName, "width") == 0 && obj->size->width!=(int)zval_get_long(value)){
obj->size->width=(int)zval_get_long(value);
}else if(strcmp(memberName, "height") == 0 && obj->size->height!=(int)zval_get_long(value)){
obj->size->height=(int)zval_get_long(value);
}
//zend_string_release(str);//free zend_string not memberName(zend_string->val)
zend_string_release(str);//free zend_string not memberName(zend_string->val)
std_object_handlers.write_property(object,member,value,cache_slot);
return value;
}
@@ -370,9 +364,6 @@ void opencv_size_init(int module_number){
opencv_size_object_handlers.clone_obj = NULL;
opencv_size_object_handlers.write_property = opencv_size_write_property;
opencv_size_object_handlers.free_obj = opencv_size_free_obj;
opencv_size_object_handlers.offset = XtOffsetOf(opencv_size_object, std);
zend_declare_property_null(opencv_size_ce,"width",sizeof("width") - 1,ZEND_ACC_PUBLIC);
zend_declare_property_null(opencv_size_ce,"height",sizeof("height") - 1,ZEND_ACC_PUBLIC);
}
@@ -386,9 +377,9 @@ zend_object_handlers opencv_rect_object_handlers;
zend_object* opencv_rect_create_handler(zend_class_entry *type)
{
size_t size = sizeof(opencv_rect_object)+zend_object_properties_size(type);
size_t size = sizeof(opencv_rect_object);
opencv_rect_object *obj = (opencv_rect_object *)ecalloc(1,size);
memset(obj, 0, size);
memset(obj, 0, sizeof(opencv_rect_object));
zend_object_std_init(&obj->std, type);
object_properties_init(&obj->std, type);
obj->std.ce = type;
@@ -405,10 +396,10 @@ void opencv_rect_free_obj(zend_object *object)
}
void opencv_rect_update_property_by_c_rect(zval *z, Rect *rect){
zend_update_property_long(opencv_rect_ce, Z_OBJ_P(z), "x", sizeof("x")-1, rect->x);
zend_update_property_long(opencv_rect_ce, Z_OBJ_P(z), "y", sizeof("y")-1, rect->y);
zend_update_property_long(opencv_rect_ce, Z_OBJ_P(z), "width", sizeof("width")-1, rect->width);
zend_update_property_long(opencv_rect_ce, Z_OBJ_P(z), "height", sizeof("height")-1, rect->height);
zend_update_property_long(opencv_rect_ce, z, "x", sizeof("x")-1, rect->x);
zend_update_property_long(opencv_rect_ce, z, "y", sizeof("y")-1, rect->y);
zend_update_property_long(opencv_rect_ce, z, "width", sizeof("width")-1, rect->width);
zend_update_property_long(opencv_rect_ce, z, "height", sizeof("height")-1, rect->height);
}
/**
@@ -515,12 +506,12 @@ PHP_METHOD(opencv_rect, area)
* opencv_rect_methods[]
*/
const zend_function_entry opencv_rect_methods[] = {
PHP_ME(opencv_rect, __construct, arginfo_void, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(opencv_rect, print, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_rect, tl, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_rect, br, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_rect, size, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_rect, area, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_rect, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(opencv_rect, print, NULL, ZEND_ACC_PUBLIC)
PHP_ME(opencv_rect, tl, NULL, ZEND_ACC_PUBLIC)
PHP_ME(opencv_rect, br, NULL, ZEND_ACC_PUBLIC)
PHP_ME(opencv_rect, size, NULL, ZEND_ACC_PUBLIC)
PHP_ME(opencv_rect, area, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
/* }}} */
@@ -533,9 +524,11 @@ const zend_function_entry opencv_rect_methods[] = {
* @param value
* @param cache_slot
*/
zval * opencv_rect_write_property(zend_object *object, zend_string *member, zval *value, void **cache_slot){
char *memberName=ZSTR_VAL(member);
opencv_rect_object *obj = get_rect_obj(object);
void opencv_rect_write_property(zval *object, zval *member, zval *value, void **cache_slot){
zend_string *str = zval_get_string(member);
char *memberName=ZSTR_VAL(str);
opencv_rect_object *obj = Z_PHP_RECT_OBJ_P(object);
if(strcmp(memberName, "x") == 0 && obj->rect->x!=(int)zval_get_long(value)){
obj->rect->x=(int)zval_get_long(value);
@@ -546,9 +539,9 @@ zval * opencv_rect_write_property(zend_object *object, zend_string *member, zval
}else if(strcmp(memberName, "height") == 0 && obj->rect->height!=(int)zval_get_long(value)){
obj->rect->height=(int)zval_get_long(value);
}
//zend_string_release(str);//free zend_string not memberName(zend_string->val)
zend_string_release(str);//free zend_string not memberName(zend_string->val)
std_object_handlers.write_property(object,member,value,cache_slot);
return value;
}
@@ -566,12 +559,6 @@ void opencv_rect_init(int module_number){
opencv_rect_object_handlers.clone_obj = NULL;
opencv_rect_object_handlers.write_property = opencv_rect_write_property;
opencv_rect_object_handlers.free_obj = opencv_rect_free_obj;
opencv_rect_object_handlers.offset = XtOffsetOf(opencv_rect_object, std);
zend_declare_property_null(opencv_rect_ce,"x",sizeof("x") - 1,ZEND_ACC_PUBLIC);
zend_declare_property_null(opencv_rect_ce,"y",sizeof("y") - 1,ZEND_ACC_PUBLIC);
zend_declare_property_null(opencv_rect_ce,"width",sizeof("width") - 1,ZEND_ACC_PUBLIC);
zend_declare_property_null(opencv_rect_ce,"height",sizeof("height") - 1,ZEND_ACC_PUBLIC);
}
//-----------------------------------【CV\RotatedRect】--------------------------------
@@ -582,9 +569,9 @@ zend_object_handlers opencv_rotated_rect_object_handlers;
zend_object* opencv_rotated_rect_create_handler(zend_class_entry *type)
{
size_t size = sizeof(opencv_rotated_rect_object)+zend_object_properties_size(type);
size_t size = sizeof(opencv_rotated_rect_object);
opencv_rotated_rect_object *obj = (opencv_rotated_rect_object *)ecalloc(1,size);
memset(obj, 0, size);
memset(obj, 0, sizeof(opencv_rotated_rect_object));
zend_object_std_init(&obj->std, type);
object_properties_init(&obj->std, type);
obj->std.ce = type;
@@ -601,9 +588,11 @@ zend_object* opencv_rotated_rect_create_handler(zend_class_entry *type)
* @param value
* @param cache_slot
*/
zval *opencv_rotated_rect_write_property(zend_object *object, zend_string *member, zval *value, void **cache_slot){
char *memberName = ZSTR_VAL(member);
opencv_rotated_rect_object *obj = get_rotated_rect_obj(object);
void opencv_rotated_rect_write_property(zval *object, zval *member, zval *value, void **cache_slot){
zend_string *str = zval_get_string(member);
char *memberName = ZSTR_VAL(str);
opencv_rotated_rect_object *obj = Z_PHP_ROTATED_RECT_OBJ_P(object);
if(strcmp(memberName, "angle") == 0 && obj->rotatedRect->angle != (int)zval_get_long(value)){
obj->rotatedRect->angle = (float)zval_get_long(value);
}else if(strcmp(memberName, "center") == 0 ){
@@ -625,9 +614,9 @@ zval *opencv_rotated_rect_write_property(zend_object *object, zend_string *membe
opencv_throw_exception("set property size only expect param is Size object.");
}
}
//zend_string_release(str);//free zend_string not memberName(zend_string->val)
zend_string_release(str);//free zend_string not memberName(zend_string->val)
std_object_handlers.write_property(object,member,value,cache_slot);
return value;
}
@@ -641,21 +630,21 @@ void opencv_rotated_rect_free_obj(zend_object *object)
void opencv_rotated_rect_update_property_by_c_rotated_rect(zval *z, RotatedRect *rotatedRect){
//RotatedRect->angle
zend_update_property_double(opencv_rotated_rect_ce, Z_OBJ_P(z), "angle", sizeof("angle")-1, rotatedRect->angle);
zend_update_property_double(opencv_rotated_rect_ce, z, "angle", sizeof("angle")-1, rotatedRect->angle);
//RotatedRect->center
zval center_zval;
object_init_ex(&center_zval, opencv_point_ce);
opencv_point_object *center_object = Z_PHP_POINT_OBJ_P(&center_zval);
center_object->point = new Point(rotatedRect->center.x,rotatedRect->center.y);
opencv_point_update_property_by_c_point(&center_zval, center_object->point);
zend_update_property(opencv_rotated_rect_ce, Z_OBJ_P(z), "center", sizeof("center")-1, &center_zval);
zend_update_property(opencv_rotated_rect_ce, z, "center", sizeof("center")-1, &center_zval);
//RotatedRect->size
zval size_zval;
object_init_ex(&size_zval, opencv_size_ce);
opencv_size_object *size_object = Z_PHP_SIZE_OBJ_P(&size_zval);
size_object->size = new Size(rotatedRect->size);
opencv_size_update_property_by_c_size(&size_zval, size_object->size);
zend_update_property(opencv_rotated_rect_ce, Z_OBJ_P(z), "size", sizeof("size")-1, &size_zval);
zend_update_property(opencv_rotated_rect_ce, z, "size", sizeof("size")-1, &size_zval);
/**
* 数组center_zval在object_init_ex()后refcount=1
* 插入成员属性zend_update_property()会自动加一次,变为2
@@ -724,8 +713,8 @@ PHP_METHOD(opencv_rotated_rect, points)
* opencv_rect_methods[]
*/
const zend_function_entry opencv_rotated_rect_methods[] = {
PHP_ME(opencv_rotated_rect, __construct, arginfo_void, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(opencv_rotated_rect, points, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_rotated_rect, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(opencv_rotated_rect, points, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
/* }}} */
@@ -741,7 +730,6 @@ void opencv_rotated_rect_init(int module_number){
opencv_rotated_rect_object_handlers.clone_obj = NULL;
opencv_rotated_rect_object_handlers.write_property = opencv_rotated_rect_write_property;
opencv_rotated_rect_object_handlers.free_obj = opencv_rotated_rect_free_obj;
opencv_rotated_rect_object_handlers.offset = XtOffsetOf(opencv_rotated_rect_object, std);
}
+5 -5
Ver Arquivo
@@ -34,29 +34,29 @@ extern zend_class_entry *opencv_rotated_rect_ce;
typedef struct _opencv_point_object{
Point *point;
zend_object std;
Point *point;
}opencv_point_object;
typedef struct _opencv_scalar_object{
Scalar *scalar;
zend_object std;
Scalar *scalar;
}opencv_scalar_object;
typedef struct _opencv_size_object{
Size *size;
zend_object std;
Size *size;
}opencv_size_object;
typedef struct _opencv_rect_object{
Rect *rect;
zend_object std;
Rect *rect;
}opencv_rect_object;
typedef struct _opencv_rotated_rect_object{
RotatedRect *rotatedRect;
zend_object std;
RotatedRect *rotatedRect;
}opencv_rotated_rect_object;
/**
-346
Ver Arquivo
@@ -1,346 +0,0 @@
/*
+----------------------------------------------------------------------+
| PHP-OpenCV |
+----------------------------------------------------------------------+
| This source file is subject to version 2.0 of the Apache license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.apache.org/licenses/LICENSE-2.0.html |
| If you did not receive a copy of the Apache2.0 license and are unable|
| to obtain it through the world-wide-web, please send a note to |
| hihozhou@gmail.com so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: HaiHao Zhou <hihozhou@gmail.com> |
+----------------------------------------------------------------------+
*/
#include "../../../php_opencv.h"
#include "opencv_dnn.h"
#ifdef HAVE_OPENCV_DNN
#include "../core/opencv_type.h"
#include "../core/opencv_mat.h"
#include "../../../opencv_exception.h"
using namespace dnn;
using namespace std;
#define Z_PHP_DNN_NET_OBJ_P(zv) get_dnn_net_obj(Z_OBJ_P(zv))
typedef struct _opencv_dnn_net_object{
Net DNNNet;
zend_object std;
}opencv_dnn_net_object;
/**
* @param obj
* @return
*/
static inline opencv_dnn_net_object* get_dnn_net_obj(zend_object *obj) {
return (opencv_dnn_net_object*)((char*)(obj) - XtOffsetOf(opencv_dnn_net_object, std));
}
zend_object_handlers opencv_dnn_net_object_handlers;
zend_class_entry *opencv_dnn_net_ce;
zend_class_entry *opencv_base_dnn_net_ce;
PHP_FUNCTION(opencv_dnn_blob_from_image)
{
zval *image_zval, *size_zval, *mean_zval;
double scalefactor = 1.;
bool swapRB = true, crop = true;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OdOO|bb",
&image_zval, opencv_mat_ce,
&scalefactor,
&size_zval, opencv_size_ce,
&mean_zval, opencv_scalar_ce,
&swapRB,
&crop
) == FAILURE) {
RETURN_NULL();
}
opencv_mat_object *image_object = Z_PHP_MAT_OBJ_P(image_zval);
opencv_size_object *size_object = Z_PHP_SIZE_OBJ_P(size_zval);
opencv_scalar_object *mean_object = Z_PHP_SCALAR_OBJ_P(mean_zval);
Mat im = blobFromImage(*image_object->mat, scalefactor, *size_object->size, *mean_object->scalar, swapRB, crop);
zval instance;
object_init_ex(&instance, opencv_mat_ce);
opencv_mat_object *new_obj = Z_PHP_MAT_OBJ_P(&instance);
new_obj->mat=new Mat(im);
opencv_mat_update_property_by_c_mat(&instance, new_obj->mat);
RETURN_ZVAL(&instance,0,0); //return php Mat object
}
PHP_FUNCTION(opencv_dnn_read_net_from_torch)
{
char *filename;
size_t filename_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &filename_len) == FAILURE) {
RETURN_NULL();
}
zval instance;
object_init_ex(&instance, opencv_dnn_net_ce);
opencv_dnn_net_object *obj = Z_PHP_DNN_NET_OBJ_P(&instance);
obj->DNNNet = readNetFromTorch(filename, true);
RETURN_ZVAL(&instance,0,0);
}
PHP_FUNCTION(opencv_dnn_read_net_from_caffe)
{
char *prototxt, *caffeModel;
size_t prototxt_len, caffeModel_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &prototxt, &prototxt_len, &caffeModel, &caffeModel_len) == FAILURE) {
RETURN_NULL();
}
ifstream protoFile;
protoFile.open(prototxt);//open the input file
stringstream protoStream;
protoStream << protoFile.rdbuf();//read the file
string protoData = protoStream.str();
ifstream modelFile;
modelFile.open(caffeModel, ios::binary);//open the input file
stringstream modelStream;
modelStream << modelFile.rdbuf();//read the file
string modelData = modelStream.str();
zval instance;
object_init_ex(&instance, opencv_dnn_net_ce);
opencv_dnn_net_object *obj = Z_PHP_DNN_NET_OBJ_P(&instance);
//obj->DNNNet = readNetFromCaffe(protoData.c_str(), protoData.size());
obj->DNNNet = readNetFromCaffe(protoData.c_str(), protoData.size(), modelData.c_str(), modelData.size());
RETURN_ZVAL(&instance,0,0);
}
PHP_FUNCTION(opencv_dnn_read_net_from_tensorflow)
{
char *model, *config;
size_t model_len, config_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &model, &model_len, &config, &config_len) == FAILURE) {
RETURN_NULL();
}
ifstream modelFile;
modelFile.open(model);//open the input file
stringstream modelStream;
modelStream << modelFile.rdbuf();//read the file
string modelData = modelStream.str();
ifstream configFile;
configFile.open(config, ios::binary);//open the input file
stringstream configStream;
configStream << configFile.rdbuf();//read the file
string configData = configStream.str();
zval instance;
object_init_ex(&instance, opencv_dnn_net_ce);
opencv_dnn_net_object *obj = Z_PHP_DNN_NET_OBJ_P(&instance);
//obj->DNNNet = readNetFromTensorflow(modelData.c_str(), modelData.size());
obj->DNNNet = readNetFromTensorflow(modelData.c_str(), modelData.size(), configData.c_str(), configData.size());
RETURN_ZVAL(&instance,0,0);
}
PHP_FUNCTION(opencv_dnn_read_net_from_onnx)
{
char *filename;
size_t filename_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &filename_len) == FAILURE) {
RETURN_NULL();
}
zval instance;
object_init_ex(&instance, opencv_dnn_net_ce);
opencv_dnn_net_object *obj = Z_PHP_DNN_NET_OBJ_P(&instance);
obj->DNNNet = readNetFromONNX(filename);
RETURN_ZVAL(&instance,0,0);
}
PHP_FUNCTION(opencv_dnn_read_net_from_model_optimizer)
{
char *xml, *bin;
size_t xml_len, bin_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &xml, &xml_len, &bin, &bin_len) == FAILURE) {
RETURN_NULL();
}
ifstream xmlFile;
xmlFile.open(xml);//open the input file
stringstream xmlStream;
xmlStream << xmlFile.rdbuf();//read the file
string xmlData = xmlStream.str();
ifstream binFile;
binFile.open(bin, ios::binary);//open the input file
stringstream binStream;
binStream << binFile.rdbuf();//read the file
string binData = binStream.str();
zval instance;
object_init_ex(&instance, opencv_dnn_net_ce);
opencv_dnn_net_object *obj = Z_PHP_DNN_NET_OBJ_P(&instance);
obj->DNNNet = readNetFromModelOptimizer(xmlData, binData);
RETURN_ZVAL(&instance,0,0);
}
PHP_FUNCTION(opencv_dnn_read_net_from_darknet)
{
char *cfg, *bin;
size_t cfg_len, bin_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &cfg, &cfg_len, &bin, &bin_len) == FAILURE) {
RETURN_NULL();
}
ifstream cfgFile;
cfgFile.open(cfg);//open the input file
stringstream cfgStream;
cfgStream << cfgFile.rdbuf();//read the file
string cfgData = cfgStream.str();
ifstream binFile;
binFile.open(bin, ios::binary);//open the input file
stringstream binStream;
binStream << binFile.rdbuf();//read the file
string binData = binStream.str();
zval instance;
object_init_ex(&instance, opencv_dnn_net_ce);
opencv_dnn_net_object *obj = Z_PHP_DNN_NET_OBJ_P(&instance);
//obj->DNNNet = readNetFromDarknet(cfgData.c_str(), cfgData.size());
obj->DNNNet = readNetFromDarknet(cfgData.c_str(), cfgData.size(), binData.c_str(), binData.size());
RETURN_ZVAL(&instance,0,0);
}
PHP_METHOD(opencv_dnn_net, setInput)
{
zval *image_zval;
char *name = (char*) "";
size_t name_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|s", &image_zval, opencv_mat_ce, &name, &name_len) == FAILURE) {
RETURN_NULL();
}
opencv_mat_object *image_object = Z_PHP_MAT_OBJ_P(image_zval);
opencv_dnn_net_object *obj = Z_PHP_DNN_NET_OBJ_P(getThis());
obj->DNNNet.setInput(*(image_object->mat), name);
RETURN_NULL();
}
PHP_METHOD(opencv_dnn_net, forward)
{
zval *image_zval;
char *name;
opencv_dnn_net_object *obj = Z_PHP_DNN_NET_OBJ_P(getThis());
Mat image = obj->DNNNet.forward();
zval instance;
object_init_ex(&instance, opencv_mat_ce);
opencv_mat_object *new_obj = Z_PHP_MAT_OBJ_P(&instance);
new_obj->mat=new Mat(image);
opencv_mat_update_property_by_c_mat(&instance, new_obj->mat);
RETURN_ZVAL(&instance,0,0); //return php Mat object
}
PHP_METHOD(opencv_dnn_net, getLayerNames)
{
std::vector<String> layers;
zval arr_zval;
opencv_dnn_net_object *obj = Z_PHP_DNN_NET_OBJ_P(getThis());
layers = obj->DNNNet.getLayerNames();
array_init_size(&arr_zval, layers.size());
for(std::vector<int>::size_type i = 0; i != layers.size(); i++) {
add_index_string(&arr_zval, i, layers[i].c_str());
}
RETURN_ZVAL(&arr_zval,0,0);
}
PHP_METHOD(opencv_dnn_net, getLayersCount)
{
char *type;
size_t type_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &type, &type_len) == FAILURE) {
RETURN_NULL();
}
opencv_dnn_net_object *obj = Z_PHP_DNN_NET_OBJ_P(getThis());
long count = obj->DNNNet.getLayersCount(type);
RETURN_LONG(count);
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0)
ZEND_END_ARG_INFO()
/**
* opencv_dnn_net_methods[]
*/
const zend_function_entry opencv_dnn_net_methods[] = {
PHP_ME(opencv_dnn_net, setInput, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_dnn_net, forward, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_dnn_net, getLayerNames, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_dnn_net, getLayersCount, arginfo_void, ZEND_ACC_PUBLIC)
PHP_FE_END
};
/* }}} */
/**
* @param type
* @return
*/
zend_object* opencv_dnn_net_handler(zend_class_entry *type)
{
size_t size = sizeof(opencv_dnn_net_object)+zend_object_properties_size(type);
opencv_dnn_net_object *obj = (opencv_dnn_net_object *)ecalloc(1,size);
memset(obj, 0, size);
zend_object_std_init(&obj->std, type);
object_properties_init(&obj->std, type);
obj->std.ce = type;
obj->std.handlers = &opencv_dnn_net_object_handlers;
return &obj->std;
}
void opencv_dnn_init(int module_number){
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce,OPENCV_DNN_NS, "Net", opencv_dnn_net_methods);
opencv_dnn_net_ce = zend_register_internal_class_ex(&ce, opencv_dnn_net_ce);
opencv_dnn_net_ce->create_object = opencv_dnn_net_handler;
memcpy(&opencv_dnn_net_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
opencv_dnn_net_object_handlers.offset = XtOffsetOf(opencv_dnn_net_object, std);
}
#else
void opencv_dnn_init(int module_number){
}
#endif
-36
Ver Arquivo
@@ -1,36 +0,0 @@
/*
+----------------------------------------------------------------------+
| PHP-OpenCV |
+----------------------------------------------------------------------+
| This source file is subject to version 2.0 of the Apache license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.apache.org/licenses/LICENSE-2.0.html |
| If you did not receive a copy of the Apache2.0 license and are unable|
| to obtain it through the world-wide-web, please send a note to |
| hihozhou@gmail.com so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: HaiHao Zhou <hihozhou@gmail.com> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_OPENCV_DNN_NET_H
#define PHP_OPENCV_DNN_NET_H
#include <opencv2/dnn.hpp>
#include <string>
#include <fstream>
#include <streambuf>
extern void opencv_dnn_init(int module_number);
#endif
PHP_FUNCTION(opencv_dnn_blob_from_image);
PHP_FUNCTION(opencv_dnn_read_net_from_torch);
PHP_FUNCTION(opencv_dnn_read_net_from_caffe);
PHP_FUNCTION(opencv_dnn_read_net_from_tensorflow);
PHP_FUNCTION(opencv_dnn_read_net_from_onnx);
PHP_FUNCTION(opencv_dnn_read_net_from_model_optimizer);
PHP_FUNCTION(opencv_dnn_read_net_from_darknet);
-251
Ver Arquivo
@@ -1,251 +0,0 @@
/*
+----------------------------------------------------------------------+
| PHP-OpenCV |
+----------------------------------------------------------------------+
| This source file is subject to version 2.0 of the Apache license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.apache.org/licenses/LICENSE-2.0.html |
| If you did not receive a copy of the Apache2.0 license and are unable|
| to obtain it through the world-wide-web, please send a note to |
| hihozhou@gmail.com so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: HaiHao Zhou <hihozhou@gmail.com> |
+----------------------------------------------------------------------+
*/
#include "../../../php_opencv.h"
#include "opencv_facemarkLBF.h"
#ifdef HAVE_OPENCV_FACE
#include "../opencv_face.h"
#include "../core/opencv_type.h"
#include "../core/opencv_mat.h"
#include "../../../opencv_exception.h"
#include <opencv2/face.hpp>
using namespace cv::face;
#define Z_PHP_FACEMARK_LBF_OBJ_P(zv) get_facemark_lbf_obj(Z_OBJ_P(zv))
typedef struct _opencv_facemark_lbf_object{
Ptr<FacemarkLBF> Facemark;
zend_object std;
}opencv_facemark_lbf_object;
/**
* @param obj
* @return
*/
static inline opencv_facemark_lbf_object* get_facemark_lbf_obj(zend_object *obj) {
return (opencv_facemark_lbf_object*)((char*)(obj) - XtOffsetOf(opencv_facemark_lbf_object, std));
}
zend_object_handlers opencv_facemark_lbf_object_handlers;
zend_class_entry *opencv_facemark_lbf_ce;
zend_class_entry *opencv_base_facemark_ce;
PHP_METHOD(opencv_facemark_lbf, create)
{
zval instance;
object_init_ex(&instance, opencv_facemark_lbf_ce);
opencv_facemark_lbf_object *obj = Z_PHP_FACEMARK_LBF_OBJ_P(&instance);
obj->Facemark = FacemarkLBF::create();
RETURN_ZVAL(&instance,0,0);
}
PHP_METHOD(opencv_facemark_lbf, loadModel)
{
char *filename;
size_t filename_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &filename_len) == FAILURE) {
RETURN_NULL();
}
opencv_facemark_lbf_object *obj = Z_PHP_FACEMARK_LBF_OBJ_P(getThis());
obj->Facemark->loadModel(filename);
RETURN_NULL();
}
PHP_METHOD(opencv_facemark_lbf, getFaces)
{
zval *image_zval, *objects_zval;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oz", &image_zval, opencv_mat_ce, &objects_zval) == FAILURE) {
RETURN_NULL();
}
std::vector<Rect> objects;
opencv_mat_object *image_object = Z_PHP_MAT_OBJ_P(image_zval);
opencv_facemark_lbf_object *obj = Z_PHP_FACEMARK_LBF_OBJ_P(getThis());
obj->Facemark->getFaces(*(image_object->mat), objects);
zval *objects_real_zval = Z_REFVAL_P(objects_zval);
zval_dtor(objects_real_zval);//if real_zval value not eq null ,free real_zval to avoid memory leaks detected
array_init(objects_real_zval);
for(unsigned long i=0; i < objects.size(); i++){
zval OPENCV_CONNECT(zval,i);
Rect OPENCV_CONNECT(rect,i);
opencv_rect_object *OPENCV_CONNECT(rect_object,i);
object_init_ex(&OPENCV_CONNECT(zval,i), opencv_rect_ce);
OPENCV_CONNECT(rect_object,i) = Z_PHP_RECT_OBJ_P(&OPENCV_CONNECT(zval,i));
OPENCV_CONNECT(rect,i) = objects.at(i);
OPENCV_CONNECT(rect_object,i)->rect = new Rect(OPENCV_CONNECT(rect,i));
opencv_rect_update_property_by_c_rect(&OPENCV_CONNECT(zval,i), OPENCV_CONNECT(rect_object,i)->rect);
add_next_index_zval(objects_real_zval,&OPENCV_CONNECT(zval,i));
}
RETURN_NULL();
}
ZEND_BEGIN_ARG_INFO_EX(opencv_facemark_lbf_fit_arginfo, 0, 0, 3)
ZEND_ARG_INFO(0, image)
ZEND_ARG_INFO(0, faces)
ZEND_ARG_INFO(1, landmarks)
ZEND_END_ARG_INFO()
PHP_METHOD(opencv_facemark_lbf, fit)
{
zval *image_zval, *faces_array, *landmarks_zval, *array_val_zval;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oaz", &image_zval, opencv_mat_ce, &faces_array, &landmarks_zval) == FAILURE) {
RETURN_NULL();
}
std::vector<Rect> faces;
zend_ulong _h;
ZEND_HASH_FOREACH_NUM_KEY_VAL(Z_ARRVAL_P(faces_array),_h,array_val_zval){
//check array_val_zval is Mat object
if(Z_TYPE_P(array_val_zval) == IS_OBJECT && Z_OBJCE_P(array_val_zval)==opencv_rect_ce){
opencv_rect_object *rect_object = Z_PHP_RECT_OBJ_P(array_val_zval);
faces.push_back(*rect_object->rect);
}else {
opencv_throw_exception("array value just Rect object.");
RETURN_NULL();
}
}ZEND_HASH_FOREACH_END();
std::vector<std::vector<Point2f> > landmarks;
opencv_mat_object *image_object = Z_PHP_MAT_OBJ_P(image_zval);
opencv_facemark_lbf_object *obj = Z_PHP_FACEMARK_LBF_OBJ_P(getThis());
obj->Facemark->fit(*(image_object->mat), faces, landmarks);
zval *landmarks_real_zval = Z_REFVAL_P(landmarks_zval);
zval_dtor(landmarks_real_zval);//if real_zval value not eq null ,free real_zval to avoid memory leaks detected
array_init(landmarks_real_zval);
int point_count = 0;
for(unsigned long i=0; i < landmarks.size(); i++){
zval OPENCV_CONNECT(zval_arr,i);
array_init(&OPENCV_CONNECT(zval_arr,i));
for(unsigned long j=0; j < landmarks.at(i).size(); j++){
zval OPENCV_CONNECT(zval_point,point_count);
object_init_ex(&OPENCV_CONNECT(zval_point,point_count), opencv_point_ce);
//printf("* Debug %i %i\n", i, j, landmarks.at(i).at(j));
Z_PHP_POINT_OBJ_P(&OPENCV_CONNECT(zval_point,point_count))->point=new Point(landmarks.at(i).at(j));
opencv_point_update_property_by_c_point(&OPENCV_CONNECT(zval_point,point_count), Z_PHP_POINT_OBJ_P(&OPENCV_CONNECT(zval_point,point_count))->point);
add_next_index_zval(&OPENCV_CONNECT(zval_arr,i),&OPENCV_CONNECT(zval_point,point_count));
point_count++;
}
add_next_index_zval(landmarks_real_zval,&OPENCV_CONNECT(zval_arr,i));
}
RETURN_NULL();//RETURN_ZVAL(landmarks_real_zval,0,0);
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0)
ZEND_END_ARG_INFO()
/**
* opencv_facemark_lbf_methods[]
*/
const zend_function_entry opencv_facemark_lbf_methods[] = {
PHP_ME(opencv_facemark_lbf, create, arginfo_void, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(opencv_facemark_lbf, loadModel, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_facemark_lbf, getFaces, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_facemark_lbf, fit, opencv_facemark_lbf_fit_arginfo, ZEND_ACC_PUBLIC)
PHP_FE_END
};
/* }}} */
/**
* @param type
* @return
*/
zend_object* opencv_facemark_lbf_handler(zend_class_entry *type)
{
size_t size = sizeof(opencv_facemark_lbf_object)+zend_object_properties_size(type);
opencv_facemark_lbf_object *obj = (opencv_facemark_lbf_object *)ecalloc(1,size);
memset(obj, 0, size);
zend_object_std_init(&obj->std, type);
object_properties_init(&obj->std, type);
obj->std.ce = type;
obj->std.handlers = &opencv_facemark_lbf_object_handlers;
return &obj->std;
}
void opencv_facemark_lbf_free_obj(zend_object *object)
{
opencv_facemark_lbf_object *obj;
obj = get_facemark_lbf_obj(object);
delete obj->Facemark;
zend_object_std_dtor(object);
}
void opencv_facemark_lbf_init(int module_number){
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce,OPENCV_FACE_NS, "FacemarkLBF", opencv_facemark_lbf_methods);
opencv_facemark_lbf_ce = zend_register_internal_class_ex(&ce, opencv_facemark_lbf_ce);
opencv_facemark_lbf_ce->create_object = opencv_facemark_lbf_handler;
memcpy(&opencv_facemark_lbf_object_handlers,
zend_get_std_object_handlers(), sizeof(zend_object_handlers));
opencv_facemark_lbf_object_handlers.clone_obj = NULL;
opencv_facemark_lbf_object_handlers.free_obj = opencv_facemark_lbf_free_obj;
opencv_facemark_lbf_object_handlers.offset = XtOffsetOf(opencv_facemark_lbf_object, std);
}
/**
* -----------------------------------【CV\BaseFaceRecognizer】--------------------------------------
*
* -------------------------------------------------------------------------------------
*/
/**
* opencv_facemark_lbf_methods[]
*/
const zend_function_entry opencv_base_facemark_methods[] = {
PHP_FE_END
};
/* }}} */
void opencv_base_facemark_init(int module_number){
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce,OPENCV_FACE_NS, "BaseFacemarkLBF", opencv_base_facemark_methods);
opencv_base_facemark_ce = zend_register_internal_class_ex(&ce, opencv_facemark_lbf_ce);
}
#else
void opencv_facemark_lbf_init(int module_number){
}
void opencv_base_facemark_init(int module_number){
}
#endif
-39
Ver Arquivo
@@ -1,39 +0,0 @@
/*
+----------------------------------------------------------------------+
| PHP-OpenCV |
+----------------------------------------------------------------------+
| This source file is subject to version 2.0 of the Apache license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.apache.org/licenses/LICENSE-2.0.html |
| If you did not receive a copy of the Apache2.0 license and are unable|
| to obtain it through the world-wide-web, please send a note to |
| hihozhou@gmail.com so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: HaiHao Zhou <hihozhou@gmail.com> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_OPENCV_FACEMARK_LBF_H
#define PHP_OPENCV_FACEMARK_LBF_H
/**
* -----------------------------------【CV\LBPHFaceRecognizer】-------------------------
*
* -------------------------------------------------------------------------------------
*/
extern void opencv_facemark_lbf_init(int module_number);
/**
* -----------------------------------【CV\BaseFaceRecognizer】-------------------------
*
* -------------------------------------------------------------------------------------
*/
extern void opencv_base_facemark_init(int module_number);
#endif //PHP_OPENCV_FACEMARK_LBF_H
+30 -38
Ver Arquivo
@@ -27,8 +27,8 @@ using namespace cv::face;
#define Z_PHP_LBPH_FACE_RECOGNIZER_OBJ_P(zv) get_lbph_face_recognizer_obj(Z_OBJ_P(zv))
typedef struct _opencv_lbph_face_recognizer_object{
Ptr<LBPHFaceRecognizer> faceRecognizer;
zend_object std;
Ptr<LBPHFaceRecognizer> faceRecognizer;
}opencv_lbph_face_recognizer_object;
@@ -102,41 +102,36 @@ PHP_METHOD(opencv_lbph_face_recognizer, train)
}
ZEND_BEGIN_ARG_INFO_EX(opencv_lbph_face_recognizer_predict_arginfo, 0, 0, 2)
ZEND_ARG_INFO(0, src)
ZEND_ARG_INFO(1, confidence)
ZEND_END_ARG_INFO()
PHP_METHOD(opencv_lbph_face_recognizer, predict)
{
zval *src_zval, *confidence_zval = NULL;
int label;
double confidence = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|z", &src_zval, opencv_mat_ce, &confidence_zval) == FAILURE) {
zval *src_zval;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &src_zval, opencv_mat_ce) == FAILURE) {
RETURN_NULL();
}
opencv_lbph_face_recognizer_object *obj = Z_PHP_LBPH_FACE_RECOGNIZER_OBJ_P(getThis());
opencv_mat_object *src_object = Z_PHP_MAT_OBJ_P(src_zval);
int predict_label = obj->faceRecognizer->predict(*src_object->mat);
RETURN_LONG(predict_label);
}
PHP_METHOD(opencv_lbph_face_recognizer, predictConfidence)
{
zval *src_zval;
int label = 0;
double confidence = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &src_zval, opencv_mat_ce) == FAILURE) {
RETURN_NULL();
}
opencv_lbph_face_recognizer_object *obj = Z_PHP_LBPH_FACE_RECOGNIZER_OBJ_P(getThis());
opencv_mat_object *src_object = Z_PHP_MAT_OBJ_P(src_zval);
obj->faceRecognizer->predict(*src_object->mat, label, confidence);
zval *confidence_real_zval;
if (confidence_zval != NULL) {
confidence_real_zval = Z_REFVAL_P(confidence_zval);
zval_ptr_dtor(confidence_real_zval);
ZVAL_DOUBLE(confidence_real_zval, confidence);
}
RETURN_LONG(label);
RETURN_DOUBLE(confidence);
}
PHP_METHOD(opencv_lbph_face_recognizer, read)
{
char *filename;
size_t filename_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &filename_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename) == FAILURE) {
RETURN_NULL();
}
@@ -148,8 +143,7 @@ PHP_METHOD(opencv_lbph_face_recognizer, read)
PHP_METHOD(opencv_lbph_face_recognizer, write)
{
char *filename;
size_t filename_len;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &filename_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename) == FAILURE) {
RETURN_NULL();
}
@@ -204,19 +198,18 @@ PHP_METHOD(opencv_lbph_face_recognizer, update)
RETURN_NULL();
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0)
ZEND_END_ARG_INFO()
/**
* opencv_lbph_face_recognizer_methods[]
*/
const zend_function_entry opencv_lbph_face_recognizer_methods[] = {
PHP_ME(opencv_lbph_face_recognizer, create, arginfo_void, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(opencv_lbph_face_recognizer, train, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_lbph_face_recognizer, predict, opencv_lbph_face_recognizer_predict_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(opencv_lbph_face_recognizer, read, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_lbph_face_recognizer, write, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_lbph_face_recognizer, update, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_lbph_face_recognizer, create, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(opencv_lbph_face_recognizer, train, NULL, ZEND_ACC_PUBLIC)
PHP_ME(opencv_lbph_face_recognizer, predict, NULL, ZEND_ACC_PUBLIC)
// todo
PHP_ME(opencv_lbph_face_recognizer, predictConfidence, NULL, ZEND_ACC_PUBLIC)
PHP_ME(opencv_lbph_face_recognizer, read, NULL, ZEND_ACC_PUBLIC)
PHP_ME(opencv_lbph_face_recognizer, write, NULL, ZEND_ACC_PUBLIC)
PHP_ME(opencv_lbph_face_recognizer, update, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
/* }}} */
@@ -227,9 +220,9 @@ const zend_function_entry opencv_lbph_face_recognizer_methods[] = {
*/
zend_object* opencv_lbph_face_recognizer_handler(zend_class_entry *type)
{
size_t size = sizeof(opencv_lbph_face_recognizer_object)+zend_object_properties_size(type);
size_t size = sizeof(opencv_lbph_face_recognizer_object);
opencv_lbph_face_recognizer_object *obj = (opencv_lbph_face_recognizer_object *)ecalloc(1,size);
memset(obj, 0, size);
memset(obj, 0, sizeof(opencv_lbph_face_recognizer_object));
zend_object_std_init(&obj->std, type);
object_properties_init(&obj->std, type);
obj->std.ce = type;
@@ -242,7 +235,7 @@ void opencv_lbph_face_recognizer_free_obj(zend_object *object)
{
opencv_lbph_face_recognizer_object *obj;
obj = get_lbph_face_recognizer_obj(object);
//delete obj->faceRecognizer; //todo: it's hotfix for: double free or corruption (out) Aborted (core dumped)
delete obj->faceRecognizer;
zend_object_std_dtor(object);
}
@@ -256,7 +249,6 @@ void opencv_lbph_face_recognizer_init(int module_number){
zend_get_std_object_handlers(), sizeof(zend_object_handlers));
opencv_lbph_face_recognizer_object_handlers.clone_obj = NULL;
opencv_lbph_face_recognizer_object_handlers.free_obj = opencv_lbph_face_recognizer_free_obj;
opencv_lbph_face_recognizer_object_handlers.offset = XtOffsetOf(opencv_lbph_face_recognizer_object, std);
}
+12 -13
Ver Arquivo
@@ -60,20 +60,19 @@ void opencv_norm_types_const_init(int module_number){
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "NORM_MINMAX", NORM_MINMAX, CONST_CS | CONST_PERSISTENT);
}
//todo
//void opencv_hershey_fonts_const_init(int module_number){
void opencv_hershey_fonts_const_init(int module_number){
//cv::HersheyFonts
// REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "FONT_HERSHEY_SIMPLEX", FONT_HERSHEY_SIMPLEX, CONST_CS | CONST_PERSISTENT);
// REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "FONT_HERSHEY_PLAIN", FONT_HERSHEY_PLAIN, CONST_CS | CONST_PERSISTENT);
// REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "FONT_HERSHEY_DUPLEX", FONT_HERSHEY_DUPLEX, CONST_CS | CONST_PERSISTENT);
// REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "FONT_HERSHEY_COMPLEX", FONT_HERSHEY_COMPLEX, CONST_CS | CONST_PERSISTENT);
// REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "FONT_HERSHEY_TRIPLEX", FONT_HERSHEY_TRIPLEX, CONST_CS | CONST_PERSISTENT);
// REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "FONT_HERSHEY_COMPLEX_SMALL", FONT_HERSHEY_COMPLEX_SMALL, CONST_CS | CONST_PERSISTENT);
// REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "FONT_HERSHEY_SCRIPT_SIMPLEX", FONT_HERSHEY_SCRIPT_SIMPLEX, CONST_CS | CONST_PERSISTENT);
// REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "FONT_HERSHEY_SCRIPT_COMPLEX", FONT_HERSHEY_SCRIPT_COMPLEX, CONST_CS | CONST_PERSISTENT);
// REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "FONT_ITALIC", FONT_ITALIC, CONST_CS | CONST_PERSISTENT);
//}
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "FONT_HERSHEY_SIMPLEX", FONT_HERSHEY_SIMPLEX, CONST_CS | CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "FONT_HERSHEY_PLAIN", FONT_HERSHEY_PLAIN, CONST_CS | CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "FONT_HERSHEY_DUPLEX", FONT_HERSHEY_DUPLEX, CONST_CS | CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "FONT_HERSHEY_COMPLEX", FONT_HERSHEY_COMPLEX, CONST_CS | CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "FONT_HERSHEY_TRIPLEX", FONT_HERSHEY_TRIPLEX, CONST_CS | CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "FONT_HERSHEY_COMPLEX_SMALL", FONT_HERSHEY_COMPLEX_SMALL, CONST_CS | CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "FONT_HERSHEY_SCRIPT_SIMPLEX", FONT_HERSHEY_SCRIPT_SIMPLEX, CONST_CS | CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "FONT_HERSHEY_SCRIPT_COMPLEX", FONT_HERSHEY_SCRIPT_COMPLEX, CONST_CS | CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "FONT_ITALIC", FONT_ITALIC, CONST_CS | CONST_PERSISTENT);
}
void opencv_core_init(int module_number)
@@ -81,7 +80,7 @@ void opencv_core_init(int module_number)
opencv_formatter_init();
opencv_formatter_const_init(module_number);
opencv_norm_types_const_init(module_number);
// opencv_hershey_fonts_const_init(module_number);
opencv_hershey_fonts_const_init(module_number);
}
-3
Ver Arquivo
@@ -24,7 +24,6 @@ zend_class_entry *opencv_face_recognizer_ce;
using namespace face;
#include "face/opencv_facerec.h"
#include "face/opencv_facemarkLBF.h"
/**
@@ -46,8 +45,6 @@ void opencv_face_init(int module_number){
opencv_face_recognizer_init(module_number);
opencv_lbph_face_recognizer_init(module_number);
opencv_base_face_recognizer_init(module_number);
opencv_facemark_lbf_init(module_number);
opencv_base_facemark_init(module_number);
}
#else
+2 -2
Ver Arquivo
@@ -132,7 +132,7 @@ opencv_fcall_info_cb * opencv_fcall_info_cb_create(zend_fcall_info *fci_ptr, zen
memcpy(cb->fci_cache, fci_cache_ptr, sizeof(zend_fcall_info_cache));
Z_TRY_ADDREF(cb->fci->function_name);//todo 滑动调或窗口销毁是释放内存
cb->fci->param_count = 0;
//cb->fci->no_separation = 1;
cb->fci->no_separation = 1;
cb->fci->retval = NULL;
return cb;
@@ -209,7 +209,7 @@ PHP_FUNCTION(opencv_get_track_bar_pos){
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &trackbarname, &trackbarname_len, &winname, &winname_len) == FAILURE) {
return;
}
RETURN_LONG(getTrackbarPos(trackbarname, winname));
RETURN_LONG(getTrackbarPos(trackbarname, winname))
}
-34
Ver Arquivo
@@ -80,40 +80,6 @@ PHP_FUNCTION(opencv_imwrite){
RETURN_TRUE;
}
/**
* CV\imdecode
* @param execute_data
* @param return_value
*/
PHP_FUNCTION(opencv_imdecode)
{
long flags;
char *buf;
long buf_len;
flags = IMREAD_COLOR;//flags default value
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &buf,&buf_len, &flags) == FAILURE) {
RETURN_NULL();
}
zval instance;
object_init_ex(&instance,opencv_mat_ce);
opencv_mat_object *obj = Z_PHP_MAT_OBJ_P(&instance);
Mat im = imdecode(Mat(1, buf_len, CV_8UC1, buf), (int)flags);
if(im.empty() || !im.data){
char *error_message = (char*)malloc(strlen("Can not load image") + 1);
strcpy(error_message,"Can not load image");
opencv_throw_exception(error_message);//throw exception
free(error_message);
}
obj->mat = new Mat(im);
//update php Mat object property
opencv_mat_update_property_by_c_mat(&instance, obj->mat);
RETURN_ZVAL(&instance,0,0); //return php Mat object
}
void opencv_imgcodecs_init(int module_number)
{
-1
Ver Arquivo
@@ -20,6 +20,5 @@
extern void opencv_imgcodecs_init(int module_number);
PHP_FUNCTION(opencv_imread);
PHP_FUNCTION(opencv_imwrite);
PHP_FUNCTION(opencv_imdecode);
#endif //OPENCV_OPENCV_IMCODECS_H
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
-19
Ver Arquivo
@@ -268,23 +268,4 @@ ZEND_END_ARG_INFO()
PHP_FUNCTION(opencv_get_rect_sub_pix);
ZEND_BEGIN_ARG_INFO_EX(opencv_get_perspective_transform_arginfo, 0, 0, 5)
ZEND_ARG_INFO(0, src)
ZEND_ARG_INFO(0, dst)
ZEND_ARG_INFO(0, solveMethod)
ZEND_END_ARG_INFO()
PHP_FUNCTION(opencv_get_perspective_transform);
ZEND_BEGIN_ARG_INFO_EX(opencv_warp_perspective_arginfo, 0, 0, 7)
ZEND_ARG_INFO(0, src)
ZEND_ARG_INFO(1, dst)
ZEND_ARG_INFO(0, M)
ZEND_ARG_INFO(0, dsize)
ZEND_ARG_INFO(0, flags)
ZEND_ARG_INFO(0, borderMode)
ZEND_ARG_INFO(0, borderValue)
ZEND_END_ARG_INFO()
PHP_FUNCTION(opencv_warp_perspective);
#endif //OPENCV_OPENCV_IMGPROC_H
+6 -9
Ver Arquivo
@@ -103,18 +103,16 @@ PHP_METHOD(opencv_k_nearest, train)
RETURN_BOOL(obj->KNearest->train(*samples_obj->mat, (int)layout, *responses_obj->mat));
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0)
ZEND_END_ARG_INFO()
/**
* opencv_k_nearest_methods[]
*/
const zend_function_entry opencv_k_nearest_methods[] = {
PHP_ME(opencv_k_nearest, create, arginfo_void, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_MALIAS(opencv_k_nearest, getDefaultK ,get_default_k, arginfo_void, ZEND_ACC_PUBLIC)
PHP_MALIAS(opencv_k_nearest, setDefaultK ,set_default_k, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_k_nearest, train, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_k_nearest, create, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_MALIAS(opencv_k_nearest, getDefaultK ,get_default_k, NULL, ZEND_ACC_PUBLIC)
PHP_MALIAS(opencv_k_nearest, setDefaultK ,set_default_k, NULL, ZEND_ACC_PUBLIC)
PHP_ME(opencv_k_nearest, train, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
/* }}} */
@@ -125,9 +123,9 @@ const zend_function_entry opencv_k_nearest_methods[] = {
*/
zend_object* opencv_k_nearest_handler(zend_class_entry *type)
{
size_t size = sizeof(opencv_k_nearest_object)+zend_object_properties_size(type);
size_t size = sizeof(opencv_k_nearest_object);
opencv_k_nearest_object *obj = (opencv_k_nearest_object *)ecalloc(1,size);
memset(obj, 0, size);
memset(obj, 0, sizeof(opencv_k_nearest_object));
zend_object_std_init(&obj->std, type);
object_properties_init(&obj->std, type);
obj->std.ce = type;
@@ -154,5 +152,4 @@ void opencv_k_nearest_init(int module_number){
zend_get_std_object_handlers(), sizeof(zend_object_handlers));
opencv_k_nearest_object_handlers.clone_obj = NULL;
opencv_k_nearest_object_handlers.free_obj = opencv_k_nearest_free_obj;
opencv_k_nearest_object_handlers.offset = XtOffsetOf(opencv_k_nearest_object, std);
}
+1 -1
Ver Arquivo
@@ -32,8 +32,8 @@ extern void opencv_ml_sample_types_init(int module_number);
extern zend_class_entry *opencv_k_nearest_ce;
typedef struct _opencv_k_nearest_object{
Ptr<cv::ml::KNearest> KNearest;
zend_object std;
Ptr<cv::ml::KNearest> KNearest;
}opencv_k_nearest_object;
#define Z_PHP_K_NEAREST_OBJ_P(zv) get_opencv_k_nearest_object(Z_OBJ_P(zv))
+8 -12
Ver Arquivo
@@ -30,9 +30,9 @@ zend_object_handlers opencv_cascade_classifier_object_handlers;
*/
zend_object* opencv_cascade_classifier_create_handler(zend_class_entry *type)
{
int size = sizeof(opencv_cascade_classifier_object)+zend_object_properties_size(type);
int size = sizeof(opencv_cascade_classifier_object);
opencv_cascade_classifier_object *obj = (opencv_cascade_classifier_object *)ecalloc(1,size);
memset(obj, 0, size);
memset(obj, 0, sizeof(opencv_cascade_classifier_object));
zend_object_std_init(&obj->std, type);
object_properties_init(&obj->std, type);
obj->std.ce = type;
@@ -132,15 +132,12 @@ PHP_METHOD(opencv_cascade_classifier, detect_multi_scale)
RETURN_NULL();
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0)
ZEND_END_ARG_INFO()
/**
* opencv_cascade_classifier_methods[]
*/
const zend_function_entry opencv_cascade_classifier_methods[] = {
PHP_ME(opencv_cascade_classifier, __construct, arginfo_void, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(opencv_cascade_classifier, load, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_cascade_classifier, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(opencv_cascade_classifier, load, NULL, ZEND_ACC_PUBLIC)
PHP_MALIAS(opencv_cascade_classifier, detectMultiScale ,detect_multi_scale, opencv_cascade_classifier_detect_multi_scale_arginfo, ZEND_ACC_PUBLIC)
PHP_FE_END
};
@@ -170,7 +167,6 @@ void opencv_cascade_classifier_init(int module_number){
opencv_cascade_classifier_object_handlers.clone_obj = NULL;
// opencv_cascade_classifier_object_handlers.write_property = opencv_mat_write_property;
opencv_cascade_classifier_object_handlers.free_obj = opencv_cascade_classifier_free_obj;
opencv_cascade_classifier_object_handlers.offset = XtOffsetOf(opencv_cascade_classifier_object, std);
}
@@ -178,10 +174,10 @@ void opencv_cascade_classifier_init(int module_number){
void opencv_objdetect_constants_init(int module_number)
{
// REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "CV_HAAR_DO_CANNY_PRUNING", CV_HAAR_DO_CANNY_PRUNING, CONST_CS | CONST_PERSISTENT);
// REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "CV_HAAR_SCALE_IMAGE", CV_HAAR_SCALE_IMAGE, CONST_CS | CONST_PERSISTENT);
// REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "CV_HAAR_FIND_BIGGEST_OBJECT", CV_HAAR_FIND_BIGGEST_OBJECT, CONST_CS | CONST_PERSISTENT);
// REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "CV_HAAR_DO_ROUGH_SEARCH", CV_HAAR_DO_ROUGH_SEARCH, CONST_CS | CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "CV_HAAR_DO_CANNY_PRUNING", CV_HAAR_DO_CANNY_PRUNING, CONST_CS | CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "CV_HAAR_SCALE_IMAGE", CV_HAAR_SCALE_IMAGE, CONST_CS | CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "CV_HAAR_FIND_BIGGEST_OBJECT", CV_HAAR_FIND_BIGGEST_OBJECT, CONST_CS | CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "CV_HAAR_DO_ROUGH_SEARCH", CV_HAAR_DO_ROUGH_SEARCH, CONST_CS | CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "CASCADE_DO_CANNY_PRUNING", CASCADE_DO_CANNY_PRUNING, CONST_CS | CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT(OPENCV_NS, "CASCADE_SCALE_IMAGE", CASCADE_SCALE_IMAGE, CONST_CS | CONST_PERSISTENT);
+1 -1
Ver Arquivo
@@ -25,8 +25,8 @@ extern zend_class_entry *opencv_cascade_classifier_ce;
#define Z_PHP_CASCADE_CLASSIFIER_OBJ_P(zv) get_cascade_classifier_obj(Z_OBJ_P(zv))
typedef struct _opencv_cascade_classifier_object{
CascadeClassifier *cascadeClassifier;
zend_object std;
CascadeClassifier *cascadeClassifier;
}opencv_cascade_classifier_object;
extern void opencv_objdetect_init(int module_number);
+5 -9
Ver Arquivo
@@ -24,9 +24,9 @@ zend_object_handlers opencv_video_capture_object_handlers;
zend_object* opencv_video_capture_create_handler(zend_class_entry *type)
{
size_t size = sizeof(opencv_video_capture_object)+zend_object_properties_size(type);
size_t size = sizeof(opencv_video_capture_object);
opencv_video_capture_object *obj = (opencv_video_capture_object *)ecalloc(1,size);
memset(obj, 0, size);
memset(obj, 0, sizeof(opencv_video_capture_object));
zend_object_std_init(&obj->std, type);
object_properties_init(&obj->std, type);
obj->std.ce = type;
@@ -179,16 +179,13 @@ PHP_METHOD(opencv_video_capture, read)
RETURN_BOOL(result);
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_void, 0, 0, 0)
ZEND_END_ARG_INFO()
/**
* opencv_video_capture_methods[]
*/
const zend_function_entry opencv_video_capture_methods[] = {
PHP_ME(opencv_video_capture, __construct, arginfo_void, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(opencv_video_capture, open, arginfo_void, ZEND_ACC_PUBLIC)
PHP_MALIAS(opencv_video_capture, isOpened ,is_opened, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(opencv_video_capture, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(opencv_video_capture, open, NULL, ZEND_ACC_PUBLIC)
PHP_MALIAS(opencv_video_capture, isOpened ,is_opened, NULL, ZEND_ACC_PUBLIC)
PHP_ME(opencv_video_capture, read, opencv_video_capture_read_arginfo, ZEND_ACC_PUBLIC)
PHP_FE_END
};
@@ -212,7 +209,6 @@ void opencv_video_capture_init(int module_number){
zend_get_std_object_handlers(), sizeof(zend_object_handlers));
opencv_video_capture_object_handlers.clone_obj = NULL;
opencv_video_capture_object_handlers.free_obj = opencv_video_capture_free_obj;
opencv_video_capture_object_handlers.offset = XtOffsetOf(opencv_video_capture_object, std);
}
void opencv_videoio_init(int module_number){
+1 -1
Ver Arquivo
@@ -22,8 +22,8 @@ extern zend_class_entry *opencv_video_capture_ce;
#define Z_PHP_VIDEO_CAPTURE_P(zv) get_video_capture_obj(Z_OBJ_P(zv))
typedef struct _opencv_video_capture_object{
VideoCapture *videoCapture;
zend_object std;
VideoCapture *videoCapture;
}opencv_video_capture_object;
extern void opencv_videoio_init(int module_number);
+2 -6
Ver Arquivo
@@ -22,7 +22,7 @@ var_dump($dst);
$dst->print();
--EXPECT--
object(CV\Mat)#3 (5) {
object(CV\Mat)#3 (4) {
["type":"CV\Mat":private]=>
int(0)
["rows"]=>
@@ -31,8 +31,6 @@ object(CV\Mat)#3 (5) {
int(3)
["dims"]=>
int(2)
["shape"]=>
NULL
}
[ 10, 10, 10;
10, 10, 10;
@@ -51,7 +49,7 @@ object(CV\Scalar)#3 (1) {
}
}
[0, 0, 0, 0]
object(CV\Mat)#3 (5) {
object(CV\Mat)#3 (4) {
["type":"CV\Mat":private]=>
int(16)
["rows"]=>
@@ -60,8 +58,6 @@ object(CV\Mat)#3 (5) {
int(3)
["dims"]=>
int(2)
["shape"]=>
NULL
}
[ 0, 0, 0, 0, 0, 0, 0, 0, 0;
0, 0, 0, 0, 0, 0, 0, 0, 0;
+1 -3
Ver Arquivo
@@ -13,7 +13,7 @@ var_dump($im);
//CV::imwrite('2222.png',$im);
?>
--EXPECT--
object(CV\Mat)#1 (5) {
object(CV\Mat)#1 (4) {
["type":"CV\Mat":private]=>
int(16)
["rows"]=>
@@ -22,6 +22,4 @@ object(CV\Mat)#1 (5) {
int(50)
["dims"]=>
int(2)
["shape"]=>
NULL
}
-28
Ver Arquivo
@@ -1,28 +0,0 @@
--TEST--
DNN::blobFromImage
--SKIPIF--
<?php if (!extension_loaded("opencv")) print "skip"; ?>
--FILE--
<?php
use CV\Scalar;
use function CV\{imread};
$src = imread("./tests/Obama_gray.png");
$blob = \CV\DNN\blobFromImage($src, 1, new \CV\Size(48, 48), new Scalar(104, 177, 123));
var_export($blob);
?>
--EXPECT--
CV\Mat::__set_state(array(
'type' => 5,
'rows' => -1,
'cols' => -1,
'dims' => 4,
'shape' =>
array (
0 => 1,
1 => 3,
2 => 48,
3 => 48,
),
))
-39
Ver Arquivo
@@ -1,39 +0,0 @@
--TEST--
LBPHFaceRecognizer
--SKIPIF--
<?php if (!extension_loaded("opencv")) print "skip"; ?>
--FILE--
<?php
use CV\Face\LBPHFaceRecognizer;
use function CV\{imread, cvtColor, equalizeHist};
use const CV\{COLOR_BGR2GRAY};
$faceRecognizer = LBPHFaceRecognizer::create();
//hihozhou
$src = imread("./tests/face_recognizer.jpg");
$gray = cvtColor($src, COLOR_BGR2GRAY);
equalizeHist($gray, $gray);
$faceRecognizer->train([$gray], [1]);
//Obama
$src = imread("./tests/Obama.png");
$gray = cvtColor($src, COLOR_BGR2GRAY);
equalizeHist($gray, $gray);
//Obama grey
$faceRecognizer->train([$gray], [41]);
$src = imread("./tests/Obama_gray.png");
$gray = cvtColor($src, COLOR_BGR2GRAY);
equalizeHist($gray, $gray);
$faceLabel = $faceRecognizer->predict($gray, $faceConfidence);
$faceLabel = $faceRecognizer->predict($gray);
echo "{$faceLabel}";
?>
--EXPECT--
41
-42
Ver Arquivo
@@ -1,42 +0,0 @@
--TEST--
LBPHFaceRecognizer with Decode
--SKIPIF--
<?php if (!extension_loaded("opencv")) print "skip"; ?>
--FILE--
<?php
use CV\Face\LBPHFaceRecognizer;
use function CV\{imdecode, cvtColor, equalizeHist};
use const CV\{COLOR_BGR2GRAY};
$faceRecognizer = LBPHFaceRecognizer::create();
//hihozhou
$str = file_get_contents('./tests/face_recognizer.jpg');
$src = imdecode($str);
$gray = cvtColor($src, COLOR_BGR2GRAY);
equalizeHist($gray, $gray);
$faceRecognizer->train([$gray], [1]);
//Obama
$str = file_get_contents('./tests/Obama.png');
$src = imdecode($str);
$gray = cvtColor($src, COLOR_BGR2GRAY);
equalizeHist($gray, $gray);
//Obama grey
$faceRecognizer->train([$gray], [41]);
$str = file_get_contents('./tests/Obama_gray.png');
$src = imdecode($str);
$gray = cvtColor($src, COLOR_BGR2GRAY);
equalizeHist($gray, $gray);
$faceLabel = $faceRecognizer->predict($gray, $faceConfidence);
$faceLabel = $faceRecognizer->predict($gray);
echo "{$faceLabel}";
?>
--EXPECT--
41
-14
Ver Arquivo
@@ -1,14 +0,0 @@
--TEST--
FacemarkLBF::create
--SKIPIF--
<?php if (!extension_loaded("opencv")) print "skip"; ?>
--FILE--
<?php
use CV\Face\FacemarkLBF;
$facemark = FacemarkLBF::create();
var_export($facemark);
?>
--EXPECT--
CV\Face\FacemarkLBF::__set_state(array(
))
+1 -3
Ver Arquivo
@@ -14,7 +14,7 @@ var_dump($element);
$element->print();
--EXPECT--
object(CV\Mat)#3 (5) {
object(CV\Mat)#3 (4) {
["type":"CV\Mat":private]=>
int(0)
["rows"]=>
@@ -23,8 +23,6 @@ object(CV\Mat)#3 (5) {
int(7)
["dims"]=>
int(2)
["shape"]=>
NULL
}
[ 0, 0, 0, 1, 0, 0, 0;
0, 1, 1, 1, 1, 1, 0;
+3 -9
Ver Arquivo
@@ -24,7 +24,7 @@ $ones = $ones->divide(1/9);
$ones->print(Formatter::FMT_PYTHON);
?>
--EXPECT--
object(CV\Mat)#2 (5) {
object(CV\Mat)#2 (4) {
["type":"CV\Mat":private]=>
int(16)
["rows"]=>
@@ -33,15 +33,13 @@ object(CV\Mat)#2 (5) {
int(5)
["dims"]=>
int(2)
["shape"]=>
NULL
}
[[[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 (5) {
object(CV\Mat)#3 (4) {
["type":"CV\Mat":private]=>
int(0)
["rows"]=>
@@ -50,8 +48,6 @@ object(CV\Mat)#3 (5) {
int(10)
["dims"]=>
int(2)
["shape"]=>
NULL
}
[[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
@@ -63,7 +59,7 @@ object(CV\Mat)#3 (5) {
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
object(CV\Mat)#4 (5) {
object(CV\Mat)#4 (4) {
["type":"CV\Mat":private]=>
int(0)
["rows"]=>
@@ -72,8 +68,6 @@ object(CV\Mat)#4 (5) {
int(10)
["dims"]=>
int(2)
["shape"]=>
NULL
}
[[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
+1 -3
Ver Arquivo
@@ -20,7 +20,7 @@ $roi->print(Formatter::FMT_PYTHON);
?>
--EXPECT--
object(CV\Mat)#3 (5) {
object(CV\Mat)#3 (4) {
["type":"CV\Mat":private]=>
int(0)
["rows"]=>
@@ -29,8 +29,6 @@ object(CV\Mat)#3 (5) {
int(5)
["dims"]=>
int(2)
["shape"]=>
NULL
}
[[ 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0],
+4 -2
Ver Arquivo
@@ -8,11 +8,13 @@ use CV\VideoCapture;
$video=new VideoCapture();
var_dump($video->isOpened());
//$video->open(0);
$video->open(0);
var_dump($video);
var_dump($video->isOpened());
?>
--EXPECT--
bool(false)
object(CV\VideoCapture)#1 (0) {
}
}
bool(true)