AI中图像搜索的调用
stroyka 发布于2020-12-22 浏览:976 回复:2
1
收藏

(1)首先需要通过API Key和Secret Key获取access_token

入库:

import requests

import base64

'''相似图检索—入库'''

request_url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/similar/add"

# 二进制方式打开图片文件

f = open('3.jpg', 'rb')

img = base64.b64encode(f.read())params = {"brief":"{\"name\":\"小度\", \"id\":\"1\"}","image":img,"tags":"1,1"}

access_token = '24.e3a2fa24cb2dcb2598cc395e04c2c8cc.2592000.1597571065.282335-21440784'

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())
输出:

{'log_id': 7788790082692754225, 'cont_sign': '3333365105,2628747969'}

检索:

import requests

import base64

'''

相似图检索—检索

'''

request_url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/similar/search"

# 二进制方式打开图片文件

f = open('1.jpg', 'rb')

img = base64.b64encode(f.read())

params = {"image":img,"top_num":5}

access_token = '24.e3a2fa24cb2dcb2598cc395e04c2c8cc.2592000.1597571065.282335-21440784'

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())

www.158tiyu.com
输出:

{'has_more': False, 'log_id': 4387585013355446417, 'result_num': 35, 'result': [{'brief': '{"name":"小度", "id":"1"}', 'score': 0.5721617937088, 'cont_sign': '3333365105,2628747969'}, {'brief': '白T', 'score': 0.52808797359467, 'cont_sign': '233104740,1376635583'}, {'brief': '白T', 'score': 0.50537568330765, 'cont_sign': '3606751988,4294856011'}, {'brief': '外套', 'score': 0.4452508687973, 'cont_sign': '3510458510,189553542'}, {'brief': '红色', 'score': 0.38694509863853, 'cont_sign': '260121004,2282965460'}, {'brief': '外套', 'score': 0.3768130838871, 'cont_sign': '2831396002,2570597463'}, {'brief': '裙子', 'score': 0.37457612156868, 'cont_sign': '3535353956,2258769977'}, {'brief': '裙子', 'score': 0.37416499853134, 'cont_sign': '460452734,2932020579'}, {'brief': '裙子', 'score': 0.36660784482956, 'cont_sign': '1130451379,3319461364'}, {'brief': '黄色', 'score': 0.34903413057327, 'cont_sign': '2785717744,2605163325'}]}

收藏
点赞
1
个赞
共2条回复 最后由seadragon301回复于2021-03-22
#2seadragon301回复于2021-03-22

哪位大侠做过百度图像搜索技术,顺便帮我搭建网站QQ365663749

0
TOP
切换版块