php-opencv/php-opencv-examples

PHP OpenCV Library Issue

markeddolphin opened this issue · 7 comments

Sir.
I did integrating php-opencv to my project. while doing that, I got stuck at php library issue.
when I use your face recognition code sample, I came to face with undefined method error.
Here is error message.
{
"message": "Call to undefined method CV\Mat::data()",
"exception": "Error",
"file": "/var/www/vhosts/fofik.com/dbd.fofik.com/app/Services/CVDNNService.php",
"line": 89,
"trace": [
{
"file": "/var/www/vhosts/fofik.com/dbd.fofik.com/app/Http/Controllers/CelebController.php",
"line": 287,
"function": "recognize",
"class": "App\Services\CVDNNService",
"type": "->"
},
{
"file": "/var/www/vhosts/fofik.com/dbd.fofik.com/app/Http/Controllers/CelebController.php",
"line": 83,
"function": "vision",
"class": "App\Http\Controllers\CelebController",
"type": "->"
},
.........

and here is my code.

foreach ($cvData as $item) {
$label = $item->label;
$photo = $item->photo;
$src = imread(public_path($photo));
$faces = $this->image2faces($src);
foreach ($faces as $i => $face) {
$vec = $this->face2vec($face);
$faceVectors[$label.$i] = $vec->data();
}
}
and It's perfect same as you described on your example code.

I am really clueless about it.
when I print method list of $vec, there wasn't data method on it.

Array
(
[0] => __construct
[1] => type
[2] => depth
[3] => channels
[4] => empty
[5] => print
[6] => size
[7] => clone
[8] => ones
[9] => zeros
[10] => zerosBySize
[11] => isContinuous
[12] => isSubmatrix
[13] => row
[14] => col
[15] => at
[16] => atIdx
[17] => getImageROI
[18] => copyTo
[19] => convertTo
[20] => plus
[21] => divide
[22] => reshape
[23] => setTo
[24] => add
[25] => subtract
)
This is method list of CV\Mat class($vec) what I printed.
I hope you to take care of my trouble. solution for me please.
Thanks. N.J

aaaaa, now I understand. You have problem with CV\Mat::data(), not with CV\imread()
This new method and it works only in php8. I didn't recompile package php-opencv_8.0-4.5.0_amd64.deb yet. Also I didn't add it php7.

So if you have php 8 you can compile php-opencv from sources or whait an I will recompile it today/tomorrow.

I recompiled php-opencv_8.0-4.5.0_amd64.deb if you used it please reinstall it.

Sorry for bothering you again.
Frankly. I need php-opencv for php7.4
I am running project on sever which is not allowed to install php8 on it.
If you have recompiled opencv library(opencv.so) for php7.4, that would be better for me.
Thanks. N.J

I backported methods: toString, data, norm, dnn_read_net_from_onnx, read_net_from_darknet, read_net_from_model_optimizer.
Also I recompiled php-opencv_7.4-4.5.0_amd64.deb.

If you will have errors like:

Warning: CV\Mat::__construct() expects parameter 3 to be int, unknown given
Segmentation fault (core dumped)

Than use command export USE_ZEND_ALLOC=0 before run php your_script.php