Skip to content

Commit 6533985

Browse files
committed
update examples for working with blobFromImage as function instead of method
1 parent 729c6b4 commit 6533985

File tree

7 files changed

+103
-34
lines changed

7 files changed

+103
-34
lines changed

Diff for: categorize_image_by_dnn_mobilenet.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
$src = cvtColor($src, CV\COLOR_BGR2RGB); // convert BGR to RGB
1010
//var_export($src);
1111

12-
$blob = \CV\DNN\Net::blobFromImage($src, 0.017, new \CV\Size(224,224), new Scalar(103.94, 116.78, 123.68)); // convert image to 4 dimensions matrix
12+
$blob = \CV\DNN\blobFromImage($src, 0.017, new \CV\Size(224,224), new Scalar(103.94, 116.78, 123.68)); // convert image to 4 dimensions matrix
1313
//var_export($blob);
1414

15-
$net = \CV\DNN\Net::readNetFromCaffe('models/mobilenet/mobilenet_deploy.prototxt', 'models/mobilenet/mobilenet.caffemodel');
15+
$net = \CV\DNN\readNetFromCaffe('models/mobilenet/mobilenet_deploy.prototxt', 'models/mobilenet/mobilenet.caffemodel');
1616

1717
$net->setInput($blob, "");
1818

Diff for: detect_face_by_dnn_ssd.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111

1212
\CV\resize($src, $resised, new Size(300, 300));
1313

14-
$blob = \CV\DNN\Net::blobFromImage($resised, 1, new Size(300, 300), new Scalar(104, 177, 123));
14+
$blob = \CV\DNN\blobFromImage($resised, 1, new Size(300, 300), new Scalar(104, 177, 123));
1515

16-
$net = \CV\DNN\Net::readNetFromCaffe('models/ssd/res10_300x300_ssd_deploy.prototxt', 'models/ssd/res10_300x300_ssd_iter_140000.caffemodel');
16+
$net = \CV\DNN\readNetFromCaffe('models/ssd/res10_300x300_ssd_deploy.prototxt', 'models/ssd/res10_300x300_ssd_iter_140000.caffemodel');
1717

1818
$net->setInput($blob, "");
1919

2020
$r = $net->forward();
2121

2222
$scalar = new Scalar(0, 0, 255);
2323
for ($i = 0; $i < $r->shape[2]; $i++) {
24-
$confidence = $r->atIdx([0,0,$i,2], 1);
24+
$confidence = $r->atIdx([0,0,$i,2]);
2525
//var_export($confidence);echo "\n";
2626
if ($confidence > 0.5) {
27-
rectangle($src, $r->atIdx([0,0,$i,3], 1)*$src->cols, $r->atIdx([0,0,$i,4], 1)*$src->rows, $r->atIdx([0,0,$i,5], 1)*$src->cols, $r->atIdx([0,0,$i,6], 1)*$src->rows, $scalar, 3);
27+
rectangle($src, $r->atIdx([0,0,$i,3])*$src->cols, $r->atIdx([0,0,$i,4])*$src->rows, $r->atIdx([0,0,$i,5])*$src->cols, $r->atIdx([0,0,$i,6])*$src->rows, $scalar, 3);
2828
}
2929
}
3030

Diff for: docker/ubuntu-17.10_opencv-3.4/Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM ubuntu:17.10
2+
3+
RUN apt update && apt install -y wget pkg-config cmake git checkinstall
4+
5+
RUN echo 1
6+
7+
RUN git clone https://github.com/opencv/opencv_contrib.git && git clone https://github.com/opencv/opencv.git
8+
9+
RUN cd opencv_contrib && git checkout 3.4 && cd ../opencv && git checkout 3.4
10+
11+
RUN mkdir build && cd build && cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules ../opencv && make -j4 && make install
12+
13+
RUN ldconfig
14+
15+
#build deb package:
16+
17+
RUN cd build && checkinstall --default --type debian --install=no --pkgname opencv --pkgversion "3.4" --pkglicense "3-clause BSD License" --pakdir ~ --maintainer "php-opencv" --addso --autodoinst make install

Diff for: docker/ubuntu-17.10_php-7.1/Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM ubuntu:17.10
2+
3+
RUN apt update && apt install -y php-cli wget pkg-config cmake git php-cli php-dev checkinstall
4+
5+
RUN echo 1
6+
7+
RUN wget https://raw.githubusercontent.com/php-opencv/php-opencv-packages/master/opencv_3.4_amd64.deb && dpkg -i opencv_3.4_amd64.deb && rm opencv_3.4_amd64.deb
8+
9+
RUN git clone https://github.com/php-opencv/php-opencv.git
10+
11+
RUN cd php-opencv && phpize && ./configure --with-php-config=/usr/bin/php-config && make && make install
12+
13+
RUN echo "extension=opencv.so" > /etc/php/7.1/cli/conf.d/opencv.ini
14+
15+
#build deb package:
16+
17+
RUN cd php-opencv && checkinstall --default --type debian --install=no --pkgname php-opencv --pkgversion "7.1-3.4" --pkglicense "Apache 2.0" --pakdir ~ --maintainer "php-opencv" --addso --autodoinst make install

Diff for: docker/ubuntu-18.10_php-7.2/Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM ubuntu:18.04
2+
3+
RUN apt update && export DEBIAN_FRONTEND=noninteractive && apt install -y php-cli wget pkg-config cmake git php-cli php-dev checkinstall
4+
5+
RUN echo 1
6+
7+
RUN wget https://raw.githubusercontent.com/php-opencv/php-opencv-packages/master/opencv_3.4_amd64.deb && dpkg -i opencv_3.4_amd64.deb && rm opencv_3.4_amd64.deb
8+
9+
RUN git clone https://github.com/php-opencv/php-opencv.git
10+
11+
RUN cd php-opencv && phpize && ./configure --with-php-config=/usr/bin/php-config && make && make install
12+
13+
RUN echo "extension=opencv.so" > /etc/php/7.2/cli/conf.d/opencv.ini
14+
15+
#build deb package:
16+
17+
RUN cd php-opencv && checkinstall --default --type debian --install=no --pkgname php-opencv --pkgversion "7.2-3.4" --pkglicense "Apache 2.0" --pakdir ~ --maintainer "php-opencv" --addso --autodoinst make install

Diff for: phpdoc.php

+41-23
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ public function at(int $row, int $col, int $channel, $value = null) {
180180
* @param array $idx
181181
* @param int $channel
182182
* @param null $value
183-
* @return int|null
183+
* @return Mat $mat
184184
*/
185-
public function atIdx(array $idx, int $channel, $value = null) {
185+
public function atIdx(array $idx, int $channel = 1, $value = null) {
186186

187187
}
188188

@@ -991,27 +991,6 @@ public function fit(Mat $mat, array $faces, array &$landmarks) {
991991
use CV\Size;
992992

993993
class Net {
994-
public static function blobFromImage(Mat $image, float $scalefactor = 1.0, Size $size = null, Scalar $mean = null, $swapRB = true, $crop = true) {
995-
return new Mat();
996-
}
997-
998-
/**
999-
* @param string $filename
1000-
* @return Net
1001-
*/
1002-
public static function readNetFromTorch(string $filename) {
1003-
1004-
}
1005-
1006-
/**
1007-
* @param string $protoFilename
1008-
* @param string $modelFilename
1009-
* @return Net
1010-
*/
1011-
public static function readNetFromCaffe(string $protoFilename, $modelFilename) {
1012-
1013-
}
1014-
1015994
/**
1016995
* @param Mat $blob
1017996
* @param string $name
@@ -1027,4 +1006,43 @@ public function setInput(Mat $blob, string $name) {
10271006
public function forward() {
10281007

10291008
}
1009+
}
1010+
1011+
/**
1012+
* @param Mat $image
1013+
* @param float $scalefactor
1014+
* @param Size $size
1015+
* @param Scalar $mean
1016+
* @param bool $swapRB
1017+
* @param bool $crop
1018+
* @return Mat
1019+
*/
1020+
function blobFromImage(Mat $image, float $scalefactor = 1.0, Size $size, Scalar $mean, $swapRB = true, $crop = true) {
1021+
return new Mat();
1022+
}
1023+
1024+
/**
1025+
* @param string $filename
1026+
* @return Net
1027+
*/
1028+
function readNetFromTorch(string $filename) {
1029+
1030+
}
1031+
1032+
/**
1033+
* @param string $protoFilename
1034+
* @param string $modelFilename
1035+
* @return Net
1036+
*/
1037+
function readNetFromCaffe(string $protoFilename, $modelFilename) {
1038+
1039+
}
1040+
1041+
/**
1042+
* @param string $protoFilename
1043+
* @param string $modelFilename
1044+
* @return Net
1045+
*/
1046+
function readNetFromTensorflow(string $model, $config) {
1047+
10301048
}

Diff for: upscale_image_x2_by_dnn_waifu2x.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
\CV\copyMakeBorder($src, $src, 7, 7, 7, 7, 1); // add borders 7px
1010
//var_export($src);
1111

12-
$blob = \CV\DNN\Net::blobFromImage($src, 1, $src->size(), new Scalar()); // convert image to 4 dimensions matrix
12+
$blob = \CV\DNN\blobFromImage($src, 1, $src->size(), new Scalar()); // convert image to 4 dimensions matrix
1313
//var_export($blob);
1414
$blob = $blob->divide(255); // convert color values from 0-255 to 0-1
1515

16-
$net = \CV\DNN\Net::readNetFromCaffe('models/waifu2x/scale2.0x_model.prototxt', 'models/waifu2x/scale2.0x_model.caffemodel');
16+
$net = \CV\DNN\readNetFromCaffe('models/waifu2x/scale2.0x_model.prototxt', 'models/waifu2x/scale2.0x_model.caffemodel');
1717

1818
$net->setInput($blob, "");
1919

@@ -26,9 +26,9 @@
2626

2727
for ($i = 0; $i < $r->shape[2]; $i++) {
2828
for ($j = 0; $j < $r->shape[3]; $j++) {
29-
$mat->at($i, $j, 0, $r->atIdx([0,0,$i,$j], 1)); //R
30-
$mat->at($i, $j, 1, $r->atIdx([0,1,$i,$j], 1)); //G
31-
$mat->at($i, $j, 2, $r->atIdx([0,2,$i,$j], 1)); //B
29+
$mat->at($i, $j, 0, $r->atIdx([0,0,$i,$j])); //R
30+
$mat->at($i, $j, 1, $r->atIdx([0,1,$i,$j])); //G
31+
$mat->at($i, $j, 2, $r->atIdx([0,2,$i,$j])); //B
3232
}
3333
}
3434

0 commit comments

Comments
 (0)