作者:Steven
著作權宣告:著作權歸作者所有,商業轉載請聯系作者獲得授權,非商業轉載請注明出處
準備作業
1)登錄網站:人像動漫化-百度AI開放平臺 ,登錄百度AI平臺,
2)創建應用,領取免費次數,
3)復制AppID、API Key、Secret Key,呼叫介面的密鑰,
4)下載SDK,我用的C++,所以我只介紹C++的相關使用,
5)VS創建專案,包含SDK路徑,
6)專案配置OpenSSL庫,詳情見:
Windows下配置OpenSSL(傻瓜式教程,一看就會)_翟天保的博客-CSDN博客
7)專案配置libcurl庫,詳情見:
Windows下用vs2017編譯和配置libcurl庫(手把手教,適合新人)_翟天保的博客-CSDN博客
8)專案配置JsonCpp庫,詳情見:
Windows下用CMake編譯JsonCpp及配置(適合新手)_翟天保的博客-CSDN博客
9)配置好環境,開始測驗,見下方代碼,C++比其其他語言確實是麻煩的多,,,
C++測驗代碼
#include <iostream>
#include <curl/curl.h>
#include <image_process.h>
#include <opencv2/opencv.hpp>
#include <json/json.h>
using namespace std;
using namespace cv;
int main()
{
std::string app_id = "XXXXX";//id
std::string api_key = "XXXXXXX";//api_key
std::string secret_key = "XXXXXXXXX";//secret_key
// 影像處理介面
aip::Imageprocess client(app_id, api_key, secret_key);
// 選擇圖片
Json::Value result;;
std::string image;
aip::get_file_content("test2.jpg", &image);
// 引數設定
std::map<std::string, std::string> options;
options["type"] = "anime_mask";
options["mask_id"] = "3";
// 人像動漫化函式
result = client.selfieanime(image, options);
// 獲取結果
std::string res = result["image"].asString();
std::string result_dec;
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, IMREAD_COLOR);
cv::Mat mask = img_decode * 255;
// 保存影像
cv::imwrite("nresult.jpg", img_decode);
cv::imwrite("nresultm.jpg", mask);
return 0;
}
測驗效果
人像動漫化的API檔案:
https://cloud.baidu.com/doc/IMAGEPROCESS/s/Mk4i6olx5
如果函式有什么可以改進完善的地方,非常歡迎大家指出,一同進步何樂而不為呢~
如果文章幫助到你了,可以點個贊讓我知道,我會很快樂~加油!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/299910.html
標籤:AI
上一篇:三階PLL環路引數計算
