vs2015 c++ 调用百度 API人物转动漫算法

最初想自己用网上的开源代码及训练数据庥,后来发现百度有现成的,还可以免费调用500次,先试一下,等有业务了,再自己训练吧,先白嫖一下,毕竟业务量不大,功能只是展示用的

百度接口文档地址:

https://ai.baidu.com/ai-doc/IMAGEPROCESS/Mk4i6olx5

 

可以直接在在这个网址,用图片上传的形式,试一下是否满足你的效果:

https://ai.baidu.com/tech/imageprocess/selfie_anime

 

 

可以后,开始注册帐号,密码,下载sdk.创建应用:

https://console.bce.baidu.com/ai/#/ai/imageprocess/overview/index

 

然后取得

AppID

API Key

Secret Key

 

然后下载sdk:

https://ai.baidu.com/sdk

一定要下载4.1.15 ,之前版本没有这个接口

最后在程序中调用:

 

        #include "..\bdsdk/image_process.h"





        std::string app_id = "xxxxx";
        std::string api_key = "xxxxxxxxxxxxxxxx";
        std::string secret_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxj";

        aip::Imageprocess client(app_id, api_key, secret_key);

        Json::Value result;;
        std::string image;
        aip::get_file_content("test.jpg", &image);
        // 人像动漫化接口
        result = client.selfieanime(image, aip::null);
        
        std::string res = result["image"].asString();// convert string,asString(),
        std::string result_dec;//decode result
        result_dec = aip::base64_decode(res);
        std::vector<char> base64_img(result_dec.begin(), result_dec.end());
        cv::Mat img_decode = cv::imdecode(base64_img, CV_LOAD_IMAGE_COLOR);
        cv::Mat mask = img_decode * 255;
        cv::imwrite("C:\\GetAni67.png", img_decode);
        cv::imwrite("C:\\GetAni66.png", mask);

 

好了,搞定:

效果如下:

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值