首先通过API Key和Secret Key获取access_token
一、相同图片检索-后台图片入库
- 输入:
from aip import AipImageSearch
# 先建立客户端
""" 你的 APPID AK SK """
APP_ID = '21273006'
API_KEY = '0w6DwUthWTIodqUyniUkCrAh'
SECRET_KEY = 'TOoXgl1yv2Gf41GSlrPFda4M3G678bqo'
client = AipImageSearch(APP_ID, API_KEY, SECRET_KEY)
AipImageClassify = AipImageSearch(APP_ID, API_KEY, SECRET_KEY)
# 入库函数
""" 读取图片 """
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
image = get_file_content('3.jpg')
""" 调用图片检索—入库, 图片参数为本地图片 """
client.sameHqAdd(image);
""" 如果有可选参数 """
options = {}
options["brief"] = "{\"name\":\"图案\", \"id\":\"666\"}"
options["class_id1"] = 1
options["class_id2"] = 1
""" 带参数调用图片检索—入库, 图片参数为本地图片 """
client.sameHqAdd(image, options)
result = AipImageClassify.sameHqAdd(image,options)
print(result)
-
输出:
一、相同图片检索-用户图片检索
- 输入:
from aip import AipImageSearch
# 先建立客户端
""" 你的 APPID AK SK """
APP_ID = '21273006'
API_KEY = '0w6DwUthWTIodqUyniUkCrAh'
SECRET_KEY = 'TOoXgl1yv2Gf41GSlrPFda4M3G678bqo'
client = AipImageSearch(APP_ID, API_KEY, SECRET_KEY)
AipImageClassify = AipImageSearch(APP_ID, API_KEY, SECRET_KEY)
""" 读取图片 """
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
image = get_file_content('5.jpg')
""" 调用相同图像检索—检索, 图片参数为本地图片 """
client.sameHqSearch(image);
""" 带参数调用相同图像检索—检索, 图片参数为本地图片 """
client.similarSearch(image)
result = AipImageClassify.sameHqSearch(image)
print(result)
-
输出:
二、相似图片检索-用户图片检索
- 输入:
from aip import AipImageSearch
# 先建立客户端
""" 你的 APPID AK SK """
APP_ID = '21273006'
API_KEY = '0w6DwUthWTIodqUyniUkCrAh'
SECRET_KEY = 'TOoXgl1yv2Gf41GSlrPFda4M3G678bqo'
client = AipImageSearch(APP_ID, API_KEY, SECRET_KEY)
AipImageClassify = AipImageSearch(APP_ID, API_KEY, SECRET_KEY)
""" 读取图片 """
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
image = get_file_content('5.jpg')
""" 调用相似图像检索—检索, 图片参数为本地图片 """
client.similarSearch(image);
""" 带参数调用相似图像检索—检索, 图片参数为本地图片 """
client.similarSearch(image)
result = AipImageClassify.similarSearch(image)
print(result)
-
输出: