一、介面描述
智能識別黑白影像內容并填充色彩,使黑白影像變得鮮活,
二、使用攻略
-
請求說明
請求示例
HTTP 方法:
POST請求URL:
https://aip.baidubce.com/rest/2.0/image-process/v1/colourizeURL引數:
引數 值 access_token 通過API Key和Secret Key獲取的access_token,參考”Access Token獲取” Header如下:
引數 值 Content-Type application/x-www-form-urlencoded Body中放置請求引數,引數詳情如下:
請求引數
引數 是否必選 型別 可選值范圍 說明 image true string - base64編碼后大小不超過4M,最短邊至少64px,最長邊最大800px,長寬比3:1以內,注意:圖片的base64編碼是不包含圖片頭的,如 (data:image/jpg;base64,) -
回傳說明
回傳引數
欄位 是否必選 型別 說明 log_id 是 uint64 唯一的log id,用于問題定位 image 否 string base64編碼圖片 回傳示例
{ "log_id": "6876747463538438254", "image": "處理后圖片的Base64編碼" } -
原始碼共享
# encoding:utf-8 import requests import base64 #獲取access_token client_id = ' ' # client_id 為官網獲取的AK client_secret = ' ' #client_secret 為官網獲取的SK host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + client_id + '&client_secret=' + client_secret response = requests.get(host) if response: print(response.json()) token = response.json()['access_token'] #黑白影像上色 request_url = "https://aip.baidubce.com/rest/2.0/image-process/v1/colourize" f = open('black.jpg', 'rb') # 二進制方式打開圖片檔案 img = base64.b64encode(f.read()) params = {"image":img} access_token = token request_url = request_url + "?access_token=" + access_token headers = {'content-type': 'application/x-www-form-urlencoded'} response = requests.post(request_url, data=params, headers=headers) if response: print (response.json()) img = base64.b64decode(response.json()['image']) file = open( 'result.jpg', 'wb') file.write(img) file.close
三、效果測驗


轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/250727.html
標籤:其他
