【图像识别】LOGO识别
才能我浪费99 发布于2021-12 浏览:2122 回复:1
1
收藏
最后编辑于2022-04

一、背景
品牌logo识别,可以识别超过2万类商品logo,支持创建自定义品牌logo图库,可准确识别图片中品牌logo的名称,适用于需要快速获取品牌信息的业务场景。

二、技术方案简介
通过品牌Logo识别可以实现品牌信息获取,例如根据拍摄照片,识别图片中商品logo名称,为消费者提供轻松高效的信息获取体验,促进消费者向投资者转化,适用于需要快速获取品牌信息的业务场景

三、具体实现的步骤
3.1.平台接入

具体接入方式比较简单,可以参考我的另一个帖子,这里就不重复了:
http://ai.baidu.com/forum/topic/show/943327

3.2认证授权:

在开始调用任何API之前需要先进行认证授权,具体的说明请参考:

http://ai.baidu.com/docs#/Auth/top

具体Python3代码如下:

# -*- coding: utf-8 -*-
#!/usr/bin/env python

import urllib
import base64
import json
#client_id 为官网获取的AK, client_secret 为官网获取的SK
client_id =【百度云应用的AK】
client_secret =【百度云应用的SK】

#获取token
def get_token():
    host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + client_id + '&client_secret=' + client_secret
    request = urllib.request.Request(host)
    request.add_header('Content-Type', 'application/json; charset=UTF-8')
    response = urllib.request.urlopen(request)
    token_content = response.read()
    if token_content:
        token_info = json.loads(token_content)
        token_key = token_info['access_token']
    return token_key

3.3接口调用:

详细说明请参考:https://ai.baidu.com/ai-doc/IMAGERECOGNITION/Ok3bcxc59

说明的比较清晰,这里就不重复了。

大家需要注意的是:
API访问URL:https://aip.baidubce.com/rest/2.0/image-classify/v2/logo

输入参数image和url二选一:
image : 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式.注意:图片需要base64编码、去掉编码头后再进行urlencode。
url : 图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,当image字段存在时url字段失效。
返回示例
HTTP/1.1 200 OK
x-bce-request-id: 73c4e74c-3101-4a00-bf44-fe246959c05e
Cache-Control: no-cache
Server: BWS
Date: Tue, 18 Oct 2016 02:21:01 GMT
Content-Type: application/json;charset=UTF-8
{
"log_id": 843411868,
"result_num": 1,
"result": [
{
"type": 0,
"name": "科颜氏",
"probability": 0.99998807907104,
"location": {
"width": 296,
"top": 20,
"height": 128,
"left": 23
}
}
]
}

Python3调用代码如下:

def logo(filename):
    request_url = "https://aip.baidubce.com/rest/2.0/image-classify/v2/logo"
    
    # 二进制方式打开图片文件
    f = open(filename, 'rb')
    img = base64.b64encode(f.read())
    
    params = dict()
    params['image'] = img
    params = urllib.parse.urlencode(params).encode("utf-8")
    #params = json.dumps(params).encode('utf-8')
    
    access_token = get_token()
    request_url = request_url + "?access_token=" + access_token
    request = urllib.request.Request(url=request_url, data=params)
    request.add_header('Content-Type', 'application/x-www-form-urlencoded')
    response = urllib.request.urlopen(request)
    content = response.read()
    if content:
        #print(content)
        content=content.decode('utf-8')
        #print(content)
        data = json.loads(content)
        result=data['result']
        
        item=result[0]
        print ('名称:',item['name'])


四、实现的效果:


名称:奔驰

五、总结:
测试下来,整体识别效果不错。LOGO识别的很准确,速度也很快,用起来非常的方便。可以用于多种场景。

收藏
点赞
1
个赞
共1条回复 最后由apYyeRxhNO回复于2022-02
#2用户已被禁言回复于2022-02

https://vk.com/id703340838
https://vk.com/yabotiyu
https://m.vk.com/yabotiyu?act=info
https://m.vk.com/id703340838?act=info
https://vk.com/video703316342_456239018
https://vk.com/video703316342_456239017
https://vk.com/video703340838_456239017
https://vk.com/video703340838_456239018
https://vk.com/video703340838_456239019
https://vk.com/video703340838_456239020
https://vk.com/video703340838_456239021
https://vk.com/video703340838_456239022
https://vk.com/video703340838_456239023
https://vk.com/video703340838_456239024
https://vk.com/video703340838_456239025
https://vk.com/video703340838_456239026
https://vk.com/video703340838_456239027
https://vk.com/video703340838_456239028
https://vk.com/video703340838_456239029
https://vk.com/video703316342_456239019
https://vk.com/video703316342_456239020
https://vk.com/video703316342_456239021
https://vk.com/video703468509_456239017
https://vk.com/video703468509_456239018
https://vk.com/video703468509_456239019
https://vk.com/video703468509_456239020
https://vk.com/video703468509_456239021
https://vk.com/video703468509_456239022
https://vk.com/video703482251_456239017
https://vk.com/video703482251_456239018
https://vk.com/video703468509_456239023
https://vk.com/video703468509_456239024
https://vk.com/video703482251_456239019
https://vk.com/video703482251_456239020
https://vk.com/video703468509_456239025
https://vk.com/video703482251_456239021
https://vk.com/video703468509_456239026
https://vk.com/video703482251_456239022
https://vk.com/video703468509_456239027
https://vk.com/video703482251_456239023
https://vk.com/video703468509_456239028

0
TOP
切换版块