Beispiel #1
0
def pic_search(pic_path):
    '''

    :param pic_path: 要识别图片地址
    :return: 返回list 结果
    '''
    """ 你的 APPID AK SK """
    result1 = []
    APP_ID = '10327828'
    API_KEY = 'PGmsAVMTBtahp6X7PWGbfgur'
    SECRET_KEY = 'xLQGw2bscQXDZgBQpIs36x2W3g8qcedz '

    aipImageSearch = 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(pic_path)
    """ 调用相似图检索—检索 """
    result = aipImageSearch.similarSearch(image)['result']
    for i in result[:3]:
        #print i['brief'][9:11]
        result1.append(i['brief'][9:11])

    return result1
Beispiel #2
0
class BaiduImageSearch(object):
    # 获得连接对象
    APP_ID = '16842923'
    API_KEY = 'BXngiNhk6QxRR2kEhbcbrCAI'
    SECRET_KEY = 'A7NeGhtiNw2WUzbSNfGkRQVzQv3Z57yg'
    client = None

    def __init__(self):
        self.client = AipImageSearch(self.APP_ID, self.API_KEY,
                                     self.SECRET_KEY)

    # 获取图片
    def get_file_content(self, file_path):
        with open(file_path, 'rb') as fp:
            return fp.read()

    def upload(self, path, good_id, sku_id):
        """ 调用相似图检索—入库, 图片参数为本地图片 """
        image = self.get_file_content(path)
        """ 如果有可选参数 """
        options = {}
        params = {}
        params['key'] = path
        params['good_id'] = good_id
        params['sku_id'] = sku_id
        options["brief"] = json.dumps(params)
        # print(options)
        """ 带参数调用相似图检索—入库, 图片参数为本地图片 """
        res = self.client.similarAdd(image, options)
        # client.similarAddUrl(url, options) # 远程图片
        return res

    def upload_remote_url(self, url, good_id, sku_id):
        """ 如果有可选参数 """
        pass
        # options = {}
        # params = {}
        # params['key'] = url
        # params['good_id'] = good_id
        # params['sku_id'] = sku_id
        # options["brief"] =  json.dumps(params)
        # print(options)

        # # """ 带参数调用相似图片搜索—入库, 图片参数为远程url图片 """
        # res = self.client.similarAddUrl(url, options)
        # return res

    def delete(self, key):
        """ 调用删除相似图,图片参数为远程url图片 """
        url = 'http://tbcdn.tajansoft.com/' + key
        self.client.similarDeleteByUrl(url)

    def search(self, path):
        image = self.get_file_content(path)
        res = self.client.similarSearch(image)
        return res
Beispiel #3
0
def jpg_jiansuo_api(image_content):
    client = AipImageSearch(a_id[0]['APP_ID'], a_id[0]['API_KEY'],
                            a_id[0]['SECRET_KEY'])
    options = {}
    options["tags"] = "100,11"
    options["tag_logic"] = "0"
    options["pn"] = "100"
    options["rn"] = "250"
    a = client.similarSearch(image_content, options)
    return a['result'][:15]
Beispiel #4
0
def jpg_jiansuo():
    for i in a_id:
        client = AipImageSearch(i['APP_ID'], i['API_KEY'], i['SECRET_KEY'])
        for root, dirs, files in os.walk(r'D:\api_diaoyong'):
            for file in files:
                re_result = re.match('(\d+)', file)
                if re_result:
                    aa = re_result.group(1)
                options["tags"] = "100,11"
                options["tag_logic"] = "0"
                options["pn"] = "100"
                options["rn"] = "250"
                a = client.similarSearch(get_file_content(os.path.join(root, file)), options)
                print(a)
Beispiel #5
0
def jpg_jiansuo():
    for i in a_id:
        client = AipImageSearch(i['APP_ID'], i['API_KEY'], i['SECRET_KEY'])
        for root, dirs, files in os.walk(r'D:\api_diaoyong'):
            for file in files:
                re_result = re.match('(\d+)', file)
                if re_result:
                    aa = re_result.group(1)
                options["tags"] = "100,11"
                options["tag_logic"] = "0"
                options["pn"] = "100"
                options["rn"] = "250"
                a = client.similarSearch(
                    get_file_content(os.path.join(root, file)), options)
                i['score'] -= 1
                if i['score'] > 0:
                    # move_file(src_path, dst_path, file)
                    a_data = pd.DataFrame(a['result'])[:8]
                    a_data['taobao_goods_id'] = aa
                    print(a_data)
Beispiel #6
0
class baidu(object):
    """ 你的 APPID AK SK """
    APP_ID = '11183322'
    API_KEY = '8UF9PssmdeEM1CikKrnI78Tj'
    SECRET_KEY = 'ourP7NkBa1Lbn84RCeSu4e39OC9Ttbm4'

    def __init__(self):
        self.client = AipImageSearch(self.APP_ID, self.API_KEY,
                                     self.SECRET_KEY)

    def image_add(self, filename):  # 添加
        image = get_file_content(filename)
        options = {
            "tags": "100,1",
            "brief": "{\"name\":\"test4\"}"
        }  # tags是进行二维分组
        result = self.client.similarAdd(image, options)  # 调用参数入库
        return False if result.get('error_code') else True

    def image_search(self, filename):  # 搜索
        image = get_file_content(filename)
        options = {
            "tags": "100,1",
            "pn": "0",
            "rn": "1"
        }  # tages在二维分组里查找,pn是分页,rn是截取条数
        result = self.client.similarSearch(image, options)
        for line in result.get('result'):  # 检查第一个返回的
            pass
        if int(line.get('score')) > 0.8:  # 相似度大于0.8返回相同
            return True
        else:
            return False

    def image_delete(self, contSign):  # 删除
        # contSign = "385018571,3552852085"
        self.client.similarDeleteBySign(contSign)
Beispiel #7
0
class SimilarityPic(Pic):
    """ 你的APPID AK SK """
    APP_ID = '15900910'
    API_KEY = 'w9GDvddBuCn86NwxSTfFiocG'
    SECRET_KEY = 'W8GgfxwpMpFjDlrFV4mLT1i1Y6pu4Lx1'

    def __init__(self):
        self.image = None
        self.client = AipImageSearch(SimilarityPic.APP_ID,
                                     SimilarityPic.API_KEY,
                                     SimilarityPic.SECRET_KEY)
        self.options = {}
        self.url = None
        self.contSign = None

    # 相似图入库
    def putIn(self, sign):
        # 调用相似图检索—入库, 图片参数为本地图片
        if sign == 0:
            return self.client.similarAdd(self.image)
        # 带参数调用相似图检索—入库, 图片参数为本地图片
        elif sign == 1:
            return self.client.similarAdd(self.image, self.options)
        # 调用相似图检索—入库, 图片参数为远程url图片
        elif sign == 2:
            return self.client.similarAddUrl(self.url)
        # 带参数调用相似图检索—入库, 图片参数为远程url图片
        elif sign == 3:
            return self.client.similarAddUrl(self.url, self.options)
        else:
            print("请输入正确的sign")

    # 相似图检索
    def check(self, sign):
        # 调用相似图检索—检索, 图片参数为本地图片
        if sign == 0:
            return self.client.similarSearch(self.image)
        # 带参数调用相似图检索—检索, 图片参数为本地图片
        elif sign == 1:
            return self.client.similarSearch(self.image, self.options)
        # 调用相似图检索—检索, 图片参数为远程url图片
        elif sign == 2:
            return self.client.similarSearchUrl(self.url)
        # 带参数调用相似图检索—检索, 图片参数为远程url图片
        elif sign == 3:
            return self.client.similarSearchUrl(self.url, self.options)
        else:
            print("请输入正确的sign")

    # 相似图更新
    def update(self, sign):
        # 调用相似图检索—更新, 图片参数为本地图片
        if sign == 0:
            return self.client.similarUpdate(self.image)
        # 带参数调用相似图检索—更新, 图片参数为本地图片
        elif sign == 1:
            return self.client.similarUpdate(self.image, self.options)
        # 调用相似图检索—更新, 图片参数为远程url图片
        elif sign == 2:
            return self.client.similarUpdateUrl(self.url)
        # 带参数调用相似图检索—更新, 图片参数为远程url图片
        elif sign == 3:
            return self.client.similarUpdateUrl(self.url, self.options)
        else:
            print("请输入正确的sign")

    # 相似图删除
    def delete(self, sign):
        # 调用删除相似图,传入参数为图片
        if sign == 0:
            return self.client.similarDeleteByImage(self.image)
        # 调用删除相似图,图片参数为远程url图片
        elif sign == 1:
            return self.client.similarDeleteByUrl(self.url)
        # 调用删除相似图,传入参数为图片签名
        elif sign == 2:
            return self.client.similarDeleteBySign(self.contSign)
        else:
            print("请输入正确的sign")
Beispiel #8
0
from aip import AipImageSearch
""" 你的 APPID AK SK """
APP_ID = '11183322'
API_KEY = '8UF9PssmdeEM1CikKrnI78Tj'
SECRET_KEY = 'ourP7NkBa1Lbn84RCeSu4e39OC9Ttbm4'

client = 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('7.png')

options = {"tags": "100,1", "pn": "0", "rn": "7"}
""" 带参数调用相似图检索—检索 """
result = client.similarSearch(image, options)
for line in result.get('result'):
    print(line)
Beispiel #9
0
import os, sys
from aip import AipImageSearch
APP_ID = '16415257'
API_KEY = 'd8McO2IaD1NZ9d3gVK9uoqFr'
SECRET_KEY = 'Ta6gBIPzr98z5ofe5VsSyqeQemdzO8Pm'
client = AipImageSearch(APP_ID, API_KEY, SECRET_KEY)
""" 读取图片 """


def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()


filePath = os.path.join(sys.path[0], 'images/man.jpg')
image = get_file_content(filePath)
client.similarSearch(image)