当前位置:   article > 正文

百度AI开发平台图像增强与特效API-SDK接口PHP实战记录_图片效果增强服务api

图片效果增强服务api

百度图像增强与特效:基于领先的深度学习图像处理技术,对质量较低的图片进行去雾、无损放大、对比度增强等多种处理,优化重建高清图像。

图像增强与特效 PHP-SDK目录结构

├── AipImageProcess.php             //图像效果增强
└── lib
    ├── AipHttpClient.php        //内部http请求类
    ├── AipBCEUtil.php           //内部工具类
    └── AipBase                  //Aip基类
  • 1
  • 2
  • 3
  • 4
  • 5

引入封装库,创建对象

require_once 'libs/AipImageProcess.php';
// 你的 APPID AK SK
const APP_ID = '25269***';
const API_KEY = 'LZCiWnVXLUaxkMA***';
const SECRET_KEY = 'hdFwq03nxC4oLdVVYXGHl4***';
$client = new AipImageProcess(APP_ID, API_KEY, SECRET_KEY);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

参数配置

/*""" 如果有可选参数 """*/
$options = array("type" => "anime", "mask_id" => 3);
$image = file_get_contents('wujing.jpg');
  • 1
  • 2
  • 3

组合生成新的图片

/*组合新的base64字符串*/
$fileName = "data:image/jpg;base64," . $obj['image'];
//生成本地图片;
base64_image_content($fileName, 'upload');
$res = array();
$res['log_id'] = $obj["log_id"];
$res['code'] = "1";
$res['msg'] = "success";
die(json_encode($res));
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

Base64图片转换为本地图片并保存

/**
 * 将Base64图片转换为本地图片并保存
 * @param  $base64_image_content ,保存的Base64
 * @param  $path ,保存的路径
 */
function base64_image_content($base64_image_content, $path)
{
    //匹配出图片的格式
    if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)) {
        $type = $result[2];
        $new_file = $path . "/" . date('Ymd', time()) . "/";
        if (!file_exists($new_file)) {
            mkdir($new_file);
        }
        $new_file = $new_file . time() . "." . $type;
        if (file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64_image_content)))) {
            return '/' . $new_file;
        } else {
            return false;
        }
    } else {
        return false;
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

原图

动漫化

在这里插入图片描述

/*01.动漫化*/
$obj = $client->selfieAnime($image, $options);
  • 1
  • 2

评价:这个动漫化,差强人意。但是人脸这个补丁贴的,只能道一声,唉!

图像风格转换

 * cartoon:卡通画风格
 * pencil:铅笔风格
 * color_pencil:彩色铅笔画风格
 * warm:彩色糖块油画风格
 * wave:神奈川冲浪里油画风格
 * lavender:薰衣草油画风格
 * mononoke:奇异油画风格
 * scream:呐喊油画风格
 * gothic:哥特油画风格
*/
$options = array("option" => "cartoon");//替换对应的参数即可
$obj = $client->styleTrans($image, $options);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

@lockdata.cn

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/961921
推荐阅读
相关标签
  

闽ICP备14008679号