1 Star 0 Fork 2

cyd/php-opencv

forked from 带刀医生/php-opencv 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
classify_image_by_dnn_mobilenet.php 985 Bytes
一键复制 编辑 原始数据 按行查看 历史
yangquanliang 提交于 2020-11-23 10:22 . 初始化php-opencv
<?php
use CV\Scalar;
use function CV\{imread, cvtColor};
$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
//var_export($src);
$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
//var_export($blob);
$net = \CV\DNN\readNetFromCaffe('models/mobilenet/mobilenet_deploy.prototxt', 'models/mobilenet/mobilenet.caffemodel');
$net->setInput($blob, "");
$r = $net->forward();
//var_export($r);
$maxConfidence = 0;
$confidences = [];
for ($i = 0; $i < 1000; $i++) {
$confidences[$i] = intval($r->atIdx([0,$i,0,0], 1) * 100);
}
// top 5:
arsort($confidences);
$confidences = array_slice($confidences, 0, 5, true);
foreach ($confidences as $label => $confidence) {
echo "$confidence%: {$categories[$label]}\n";
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/imagys_88960345/php-opencv.git
git@gitee.com:imagys_88960345/php-opencv.git
imagys_88960345
php-opencv
php-opencv
master

搜索帮助