added example for: TensorFlow Object Detection API
Esse commit está contido em:
@@ -19,6 +19,9 @@
|
||||

|
||||
Results: 87%: Egyptian cat, 4%: tabby, tabby cat, 2%: tiger cat
|
||||
|
||||
- [detect objects by dnn mobilenet](https://github.com/php-opencv/php-opencv-examples/blob/master/detect_objects_by_dnn_mobilenet.php)
|
||||

|
||||
|
||||
#### Helper for autocomplete and highlighting in your IDE
|
||||
- [phpdoc file](https://github.com/php-opencv/php-opencv-examples/blob/master/phpdoc.php)
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use CV\Scalar;
|
||||
use function CV\{imread, cvtColor};
|
||||
|
||||
$categories = file('models/mobilenet/synset.txt');
|
||||
$categories = explode("\n", file_get_contents('models/mobilenet/classes.txt'));
|
||||
|
||||
$src = imread("images/cat.jpg"); // opencv loads image to matrix with BGR order
|
||||
$src = cvtColor($src, CV\COLOR_BGR2RGB); // convert BGR to RGB
|
||||
@@ -30,5 +30,5 @@ arsort($confidences);
|
||||
$confidences = array_slice($confidences, 0, 5, true);
|
||||
|
||||
foreach ($confidences as $label => $confidence) {
|
||||
echo "$confidence%: {$categories[$label]}";
|
||||
echo "$confidence%: {$categories[$label]}\n";
|
||||
}
|
||||
@@ -24,7 +24,12 @@ for ($i = 0; $i < $r->shape[2]; $i++) {
|
||||
$confidence = $r->atIdx([0,0,$i,2]);
|
||||
//var_export($confidence);echo "\n";
|
||||
if ($confidence > 0.5) {
|
||||
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);
|
||||
$startX = $r->atIdx([0,0,$i,3]) * $src->cols;
|
||||
$startY = $r->atIdx([0,0,$i,4]) * $src->rows;
|
||||
$endX = $r->atIdx([0,0,$i,5]) * $src->cols;
|
||||
$endY = $r->atIdx([0,0,$i,6]) * $src->rows;
|
||||
|
||||
rectangle($src, $startX, $startY, $endX, $endY, $scalar, 3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use CV\Scalar;
|
||||
use function CV\{imread, cvtColor};
|
||||
|
||||
//$categories = explode("\n", file_get_contents('models/ssd_mobilenet_v1_coco/classes.txt'));
|
||||
$categories = explode("\n", file_get_contents('models/ssdlite_mobilenet_v2_coco/classes.txt'));
|
||||
|
||||
$src = imread("images/objects.jpg"); // opencv loads image to matrix with BGR order
|
||||
//var_export($src);
|
||||
|
||||
$blob = \CV\DNN\blobFromImage($src, 0.017, new \CV\Size(300,300), new Scalar(127.5, 127.5, 127.5), true, false); // convert image to 4 dimensions matrix
|
||||
//var_export($blob);
|
||||
|
||||
//$net = \CV\DNN\readNetFromTensorflow('models/ssd_mobilenet_v1_coco/frozen_inference_graph.pb', 'models/ssd_mobilenet_v1_coco/ssd_mobilenet_v1_coco.pbtxt');
|
||||
$net = \CV\DNN\readNetFromTensorflow('models/ssdlite_mobilenet_v2_coco/frozen_inference_graph.pb', 'models/ssdlite_mobilenet_v2_coco/ssdlite_mobilenet_v2_coco.pbtxt');
|
||||
$net->setInput($blob, "");
|
||||
|
||||
$r = $net->forward();
|
||||
var_export($r);
|
||||
|
||||
$rectangles = [];
|
||||
for ($i = 0; $i < $r->shape[2]; $i++) {
|
||||
$classId = $r->atIdx([0,0,$i,1]);
|
||||
$confidence = intval($r->atIdx([0,0,$i,2]) * 100);
|
||||
if ($classId && $confidence > 30) {
|
||||
$startX = $r->atIdx([0,0,$i,3]) * $src->cols;
|
||||
$startY = $r->atIdx([0,0,$i,4]) * $src->rows;
|
||||
$endX = $r->atIdx([0,0,$i,5]) * $src->cols;
|
||||
$endY = $r->atIdx([0,0,$i,6]) * $src->rows;
|
||||
|
||||
$scalar = new Scalar(0, 0, 255);
|
||||
\CV\rectangle($src, $startX, $startY, $endX, $endY, $scalar, 2);
|
||||
|
||||
$text = "{$categories[$classId]} $confidence%";
|
||||
\CV\rectangle($src, $startX, $startY + 10, $startX + 20 * strlen($text), $startY - 30, new Scalar(255,255,255), -2);
|
||||
\CV\putText($src, "{$categories[$classId]} $confidence%", new \CV\Point($startX, $startY - 2), 0, 1.5, new Scalar(), 2);
|
||||
}
|
||||
}
|
||||
|
||||
\CV\imwrite("results/_detect_objects_by_dnn_mobilenet.png", $src);
|
||||
Arquivo binário não exibido.
|
Depois Largura: | Altura: | Tamanho: 120 KiB |
+3
-1
@@ -5,4 +5,6 @@ Sources:
|
||||
* openface - https://github.com/cmusatyalab/openface/blob/master/docs/models-and-accuracies.md
|
||||
* ssd - https://github.com/opencv/opencv_3rdparty/tree/dnn_samples_face_detector_20170830
|
||||
* waifu2x - https://github.com/HomeOfVapourSynthEvolution/VapourSynth-Waifu2x-caffe/tree/master/Waifu2x-caffe/models/upconv_7_anime_style_art_rgb
|
||||
* mobilenet - https://github.com/shicai/MobileNet-Caffe
|
||||
* mobilenet - https://github.com/shicai/MobileNet-Caffe
|
||||
* ssd_mobilenet_v1_coco - https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md
|
||||
* ssdlite_mobilenet_v2_coco - https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
unclassified
|
||||
person
|
||||
bicycle
|
||||
car
|
||||
motorcycle
|
||||
airplane
|
||||
bus
|
||||
train
|
||||
truck
|
||||
boat
|
||||
traffic
|
||||
fire
|
||||
street
|
||||
stop
|
||||
parking
|
||||
bench
|
||||
bird
|
||||
cat
|
||||
dog
|
||||
horse
|
||||
sheep
|
||||
cow
|
||||
elephant
|
||||
bear
|
||||
zebra
|
||||
giraffe
|
||||
hat
|
||||
backpack
|
||||
umbrella
|
||||
shoe
|
||||
eye
|
||||
handbag
|
||||
tie
|
||||
suitcase
|
||||
frisbee
|
||||
skis
|
||||
snowboard
|
||||
sports
|
||||
kite
|
||||
baseball
|
||||
baseball
|
||||
skateboard
|
||||
surfboard
|
||||
tennis
|
||||
bottle
|
||||
plate
|
||||
wine
|
||||
cup
|
||||
fork
|
||||
knife
|
||||
spoon
|
||||
bowl
|
||||
banana
|
||||
apple
|
||||
sandwich
|
||||
orange
|
||||
broccoli
|
||||
carrot
|
||||
hot
|
||||
pizza
|
||||
donut
|
||||
cake
|
||||
chair
|
||||
couch
|
||||
potted
|
||||
bed
|
||||
mirror
|
||||
dining
|
||||
window
|
||||
desk
|
||||
toilet
|
||||
door
|
||||
tv
|
||||
laptop
|
||||
mouse
|
||||
remote
|
||||
keyboard
|
||||
cell
|
||||
microwave
|
||||
oven
|
||||
toaster
|
||||
sink
|
||||
refrigerator
|
||||
blender
|
||||
book
|
||||
clock
|
||||
vase
|
||||
scissors
|
||||
teddy
|
||||
hair
|
||||
toothbrush
|
||||
hair
|
||||
banner
|
||||
blanket
|
||||
branch
|
||||
bridge
|
||||
building-other
|
||||
bush
|
||||
cabinet
|
||||
cage
|
||||
cardboard
|
||||
carpet
|
||||
ceiling-other
|
||||
ceiling-tile
|
||||
cloth
|
||||
clothes
|
||||
clouds
|
||||
counter
|
||||
cupboard
|
||||
curtain
|
||||
desk-stuff
|
||||
dirt
|
||||
door-stuff
|
||||
fence
|
||||
floor-marble
|
||||
floor-other
|
||||
floor-stone
|
||||
floor-tile
|
||||
floor-wood
|
||||
flower
|
||||
fog
|
||||
food-other
|
||||
fruit
|
||||
furniture-other
|
||||
grass
|
||||
gravel
|
||||
ground-other
|
||||
hill
|
||||
house
|
||||
leaves
|
||||
light
|
||||
mat
|
||||
metal
|
||||
mirror-stuff
|
||||
moss
|
||||
mountain
|
||||
mud
|
||||
napkin
|
||||
net
|
||||
paper
|
||||
pavement
|
||||
pillow
|
||||
plant-other
|
||||
plastic
|
||||
platform
|
||||
playingfield
|
||||
railing
|
||||
railroad
|
||||
river
|
||||
road
|
||||
rock
|
||||
roof
|
||||
rug
|
||||
salad
|
||||
sand
|
||||
sea
|
||||
shelf
|
||||
sky-other
|
||||
skyscraper
|
||||
snow
|
||||
solid-other
|
||||
stairs
|
||||
stone
|
||||
straw
|
||||
structural-other
|
||||
table
|
||||
tent
|
||||
textile-other
|
||||
towel
|
||||
tree
|
||||
vegetable
|
||||
wall-brick
|
||||
wall-concrete
|
||||
wall-other
|
||||
wall-panel
|
||||
wall-stone
|
||||
wall-tile
|
||||
wall-wood
|
||||
water-other
|
||||
waterdrops
|
||||
window-blind
|
||||
window-other
|
||||
wood
|
||||
Arquivo binário não exibido.
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -0,0 +1,183 @@
|
||||
unclassified
|
||||
person
|
||||
bicycle
|
||||
car
|
||||
motorcycle
|
||||
airplane
|
||||
bus
|
||||
train
|
||||
truck
|
||||
boat
|
||||
traffic
|
||||
fire
|
||||
street
|
||||
stop
|
||||
parking
|
||||
bench
|
||||
bird
|
||||
cat
|
||||
dog
|
||||
horse
|
||||
sheep
|
||||
cow
|
||||
elephant
|
||||
bear
|
||||
zebra
|
||||
giraffe
|
||||
hat
|
||||
backpack
|
||||
umbrella
|
||||
shoe
|
||||
eye
|
||||
handbag
|
||||
tie
|
||||
suitcase
|
||||
frisbee
|
||||
skis
|
||||
snowboard
|
||||
sports
|
||||
kite
|
||||
baseball
|
||||
baseball
|
||||
skateboard
|
||||
surfboard
|
||||
tennis
|
||||
bottle
|
||||
plate
|
||||
wine
|
||||
cup
|
||||
fork
|
||||
knife
|
||||
spoon
|
||||
bowl
|
||||
banana
|
||||
apple
|
||||
sandwich
|
||||
orange
|
||||
broccoli
|
||||
carrot
|
||||
hot
|
||||
pizza
|
||||
donut
|
||||
cake
|
||||
chair
|
||||
couch
|
||||
potted
|
||||
bed
|
||||
mirror
|
||||
dining
|
||||
window
|
||||
desk
|
||||
toilet
|
||||
door
|
||||
tv
|
||||
laptop
|
||||
mouse
|
||||
remote
|
||||
keyboard
|
||||
cell
|
||||
microwave
|
||||
oven
|
||||
toaster
|
||||
sink
|
||||
refrigerator
|
||||
blender
|
||||
book
|
||||
clock
|
||||
vase
|
||||
scissors
|
||||
teddy
|
||||
hair
|
||||
toothbrush
|
||||
hair
|
||||
banner
|
||||
blanket
|
||||
branch
|
||||
bridge
|
||||
building-other
|
||||
bush
|
||||
cabinet
|
||||
cage
|
||||
cardboard
|
||||
carpet
|
||||
ceiling-other
|
||||
ceiling-tile
|
||||
cloth
|
||||
clothes
|
||||
clouds
|
||||
counter
|
||||
cupboard
|
||||
curtain
|
||||
desk-stuff
|
||||
dirt
|
||||
door-stuff
|
||||
fence
|
||||
floor-marble
|
||||
floor-other
|
||||
floor-stone
|
||||
floor-tile
|
||||
floor-wood
|
||||
flower
|
||||
fog
|
||||
food-other
|
||||
fruit
|
||||
furniture-other
|
||||
grass
|
||||
gravel
|
||||
ground-other
|
||||
hill
|
||||
house
|
||||
leaves
|
||||
light
|
||||
mat
|
||||
metal
|
||||
mirror-stuff
|
||||
moss
|
||||
mountain
|
||||
mud
|
||||
napkin
|
||||
net
|
||||
paper
|
||||
pavement
|
||||
pillow
|
||||
plant-other
|
||||
plastic
|
||||
platform
|
||||
playingfield
|
||||
railing
|
||||
railroad
|
||||
river
|
||||
road
|
||||
rock
|
||||
roof
|
||||
rug
|
||||
salad
|
||||
sand
|
||||
sea
|
||||
shelf
|
||||
sky-other
|
||||
skyscraper
|
||||
snow
|
||||
solid-other
|
||||
stairs
|
||||
stone
|
||||
straw
|
||||
structural-other
|
||||
table
|
||||
tent
|
||||
textile-other
|
||||
towel
|
||||
tree
|
||||
vegetable
|
||||
wall-brick
|
||||
wall-concrete
|
||||
wall-other
|
||||
wall-panel
|
||||
wall-stone
|
||||
wall-tile
|
||||
wall-wood
|
||||
water-other
|
||||
waterdrops
|
||||
window-blind
|
||||
window-other
|
||||
wood
|
||||
Arquivo binário não exibido.
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
+1
-1
@@ -180,7 +180,7 @@ class Mat {
|
||||
* @param array $idx
|
||||
* @param int $channel
|
||||
* @param null $value
|
||||
* @return Mat $mat
|
||||
* @return int|float $value
|
||||
*/
|
||||
public function atIdx(array $idx, int $channel = 1, $value = null) {
|
||||
|
||||
|
||||
Arquivo binário não exibido.
|
Depois Largura: | Altura: | Tamanho: 377 KiB |
Referência em uma Nova Issue
Bloquear um usuário