Exemplo n.º 1
0
 def __init__(self):
     self.image = None
     self.client = AipImageSearch(SamePic.APP_ID, SamePic.API_KEY,
                                  SamePic.SECRET_KEY)
     self.options = {}
     self.url = None
     self.contSign = None
Exemplo n.º 2
0
 def __init__(self, filePath):
     self.image = get_file_content(filePath)
     self.client = AipImageSearch(SamePic.APP_ID, SamePic.API_KEY,
                                  SamePic.SECRET_KEY)
     self.options = {}
     self.url = None
     self.contSign = None
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
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]
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
0
def pic_indatebase(filePath, Name):
    """ 你的 APPID AK SK """
    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(filePath)
    """ 如果有可选参数 """
    options = {}
    options["brief"] = "{\"name\":\"%s\",}" % Name
    """ 带参数调用相似图检索—入库 """
    result = aipImageSearch.similarAdd(image, options)

    # """ 调用相似图检索—检索 """
    # result =aipImageSearch.sameHqSearch(image)

    print result
Exemplo n.º 9
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)
Exemplo n.º 10
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)
""" 读取图片 """

contSign = "4043096407,707976548"
""" 调用删除相同图,传入参数为图片签名 """
print(client.similarDeleteBySign(contSign))
Exemplo n.º 11
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")
Exemplo n.º 12
0
# 上传图片到百度图片搜索图库里
import xlrd
import xlwt
from xlwt import easyxf
from xlutils.copy import copy
from aip import AipImageSearch
""" 你的 APPID AK SK """
APP_ID = '16690686'
API_KEY = 'nrQRHTdphvkcVG9l8V0vkiRt'
SECRET_KEY = 'GRZMxVfpVWRVGRI0cIG0uygWwxn3yahn'

client = AipImageSearch(APP_ID, API_KEY, SECRET_KEY)
""" 读取图片 """


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


""" 打开excel """
file = 'E:\\商品图片excel\\商品库存列表(1-8095).xlsx'
# file = 'C:\\Users\\28015\\Desktop\\test.xlsx'
rb = xlrd.open_workbook(filename=file)  # 打开文件
sheet1 = rb.sheet_by_index(0)  #通过索引获取表格

wb = copy(rb)
w_sheet1 = wb.get_sheet(0)
""" 带参数调用商品图片搜索—入库, 图片参数为本地图片 """

Exemplo n.º 13
0
from aip import AipFace
import cv2
import base64
import sys
import os
import time
import sqlite3
import shutil
from aip import AipImageSearch, AipOcr
import re

face = AipFace(appId='16058688',
               apiKey="AyGxQXLmWTfftUueyVSyjVVe",
               secretKey="oPR4BQ5sdhUwvxxsClUxWTpIeqf8dTXW")
image_search = AipImageSearch(appId='16058688',
                              apiKey="AyGxQXLmWTfftUueyVSyjVVe",
                              secretKey="oPR4BQ5sdhUwvxxsClUxWTpIeqf8dTXW")
ocr = AipOcr(appId='16058688',
             apiKey="AyGxQXLmWTfftUueyVSyjVVe",
             secretKey="oPR4BQ5sdhUwvxxsClUxWTpIeqf8dTXW")


class Search:
    def __init__(self):
        pass

    def password(self):
        try:
            user_name, password = input('请输入使用者名称,登录密码').split(',')
            conn = sqlite3.connect('user_info.db')
            params = (user_name, password)
Exemplo n.º 14
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from aip import AipImageSearch

# a = 'ab'+'bc'
# print(a)
# a = {"a":123}
# print(a["a"])
# print("a" in a.keys())
""" 你的APPID AK SK """
APP_ID = '15900910'
API_KEY = 'w9GDvddBuCn86NwxSTfFiocG'
SECRET_KEY = 'W8GgfxwpMpFjDlrFV4mLT1i1Y6pu4Lx1'

client = AipImageSearch(APP_ID, API_KEY, SECRET_KEY)
print(client.productDeleteBySign("1160357892,4224460940"))
#
# """  读取图片 """
# def get_file_content(filePath):
#     with open(filePath, 'rb') as fp:
#         return fp.read()
#
# image = get_file_content('sample.jpg')
#
# f = open('sample_1.jpg', 'wb')
# f.write(image)
# f.close()

# """ 调用相同图检索-入库,图片参数为本地图片 """
# client.similarAdd(image);
Exemplo n.º 15
0
from aip import AipImageSearch

config = {
    'appId': '22570794',
    'apiKey': 'w97dfwmVaGoWyWAbMbp5BUzz',
    'secretKey': 'wa4qHy5j9xcrzpScyktnv0i0nwatqWw7'
}

client = AipImageSearch(**config)

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


def image_add_to_lib(file_path):
    image = get_file_content(file_path)
    brief = {"name": "operators", "id": "003"}
    client.sameHqAdd(image, brief)

def image_search(img):
    image = get_file_content(img)
    result = client.sameHqSearch(image)

    print(result)
    return result
    # else:
    #     print('Warning: disable to read the input.\n')

Exemplo n.º 16
0
import requests
import json
import sys
import base64
# from urllib.parse import quote
requests.packages.urllib3.disable_warnings()

IMG_APP_ID = '21552210'
IMG_API_KEY = 'dHqG78qSi8HRdEQMwGipXlLS'
IMG_SECRET_KEY = 'X9hoOwCI6rfjttyh6N9Svuif2MXXtNma'

ORC_APP_ID = '21550072'
ORC_API_KEY = 'EtFX49NClWWND3NFOvG8SjAa'
ORC_SECRET_KEY = 'LUe3aFa8Cz7aPQMcWK8FOfWI8Dn4tAXy'

img_client = AipImageSearch(IMG_APP_ID, IMG_API_KEY, IMG_SECRET_KEY)
orc_client = AipOcr(ORC_APP_ID, ORC_API_KEY, ORC_SECRET_KEY)


def get_access_token():
    host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + str(
        IMG_API_KEY) + '&client_secret=' + str(IMG_SECRET_KEY)
    response = requests.get(host)
    result = response.json()
    if result.get('error'):
        return False
    else:
        return result['access_token']


def add_sim_img(filePath, brief):
Exemplo n.º 17
0
from aip import AipImageSearch
from sqlalchemy import create_engine
""" 你的 APPID AK SK """
APP_ID = '19413368'
API_KEY = 'z9Blx6giRyn3MVOwIg7xBEdu'
SECRET_KEY = 'spnwrGf0Pih5KTG2sCWMEZmGUTke9C7K'
user = '******'
passwd = 'Chenfan@123'
host = '10.228.86.203'  ###正式机
port = 11101
dbname1 = 'test'
engine1 = create_engine("mysql+pymysql://%s:%s@%s:%s/%s?charset=utf8" %
                        (user, passwd, host, port, dbname1))
client = AipImageSearch(APP_ID, API_KEY, SECRET_KEY)
""" 读取图片 """


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


import os

options = {}
import random
import time
import pandas as pd
for root, dirs, files in os.walk(r'D:\picture_all_April'):
    bb = []
    for file in files:
Exemplo n.º 18
0
 def __init__(self):
     self.client = AipImageSearch(self.APP_ID, self.API_KEY,
                                  self.SECRET_KEY)
Exemplo n.º 19
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)
Exemplo n.º 20
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)
Exemplo n.º 21
0
class SamePic(Pic):
    """ 你的APPID AK SK """
    APP_ID = '15900910'
    API_KEY = 'w9GDvddBuCn86NwxSTfFiocG'
    SECRET_KEY = 'W8GgfxwpMpFjDlrFV4mLT1i1Y6pu4Lx1'

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

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

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

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

    # 相同图删除
    def delete(self, sign):
        # 调用删除相同图,传入参数为图片
        if sign == 0:
            self.client.sameHqDeleteByImage(self.image)
        # 调用删除相同图,图片参数为远程url图片
        elif sign == 1:
            self.client.sameHqDeleteByUrl(self.url)
        # 调用删除相同图,传入参数为图片签名
        elif sign == 2:
            self.client.sameHqDeleteBySign(self.contSign)
        else:
            print("请输入正确的sign")
Exemplo n.º 22
0
from aip import AipImageSearch

""" 你的 APPID AK SK """
APP_ID = '16210913'
API_KEY = '5wwaTUz3RHiqojeCLvRcEt9n'
SECRET_KEY = 'yyKlQqX5gyavNKfxR1HwrDSRxSqNc7uY'

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('/home/wy/pic/jumao.jpg')

""" 调用相同图检索—入库, 图片参数为本地图片 """
# resp = client.sameHqAdd(image)
# print(resp)

""" 如果有可选参数 """
options = {}
options["brief"] = "{\"name\":\"周杰伦\", \"id\":\"666\"}"
options["tags"] = "100,11"

# """ 带参数调用相同图检索—入库, 图片参数为本地图片 """
resp = client.sameHqAdd(image, options)
print(resp)