【百度大脑新品体验】地标识别
wangwei8638 发布于2019-04 浏览:5946 回复:7
0
收藏
最后编辑于2022-04

细粒度图像识别 (fine-grained image recognition),即 精细化分类 。

识别出物体的大类别(比如:花、草、狗等)较易,但比如区分月季和玫瑰,判断更为精细化的物体分类名称,则难度极大。

最大的挑战在于,同一大类别下不同子类别间的视觉差异极小。因此,精细化分类需要更高的图像分辨率。

百度细粒度图像识别目前支持动物、植物、菜品、地标等,能精准识别超过十万种物体和场景,包含多项高精度的识图能力并提供相应的API服务。

http://ai.baidu.com/tech/imagerecognition?track=cp:ainsem|pf:pc|pp:chanpin-tuxiangshibie/sousuo/chuli|pu:tuxiangshibie-pinpai|ci:|kw:10002671

一.平台接入

此步骤比较简单,不多阐述。可参照上篇文档:

https://ai.baidu.com/forum/topic/show/943028

二.分析接口文档

1.打开接口说明文档

http://ai.baidu.com/docs#/ImageClassify-API/2c607890

   (1)接口描述

该请求用于识别地标,即对于输入的一张图片(可正常解码,且长宽比适宜),输出图片中的地标识别结果。

(2)请求说明

需要用到的信息有:

请求URL:https://aip.baidubce.com/rest/2.0/image-classify/v1/landmark

Header格式:Content-Type:application/x-www-form-urlencoded

请求参数:image, 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式 。注意:图片需要base64编码、去掉编码头后再进行urlencode。

(3)返回示例

{"log_id": 3450013152046070669, "result": {"landmark": "狮身人面像"}}

2.获取accesstoken

    @staticmethod

    def _get_access_token(api_key, secret_key):

        api = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials' \

            '&client_id={}&client_secret={}'.format(api_key, secret_key)

        rp = requests.post(api)

        if rp.ok:

            rp_json = rp.json()

            print(rp_json['access_token'])

            return rp_json['access_token']

        else:

            print('=> Error in get access token!')

3.准备一张用于识别的图片,存储在本地

三.识别结果

四.源码共享

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

import os
import requests
import base64
import json
from pprint import pprint
import time
#api_key  为官网获取的AK, secret_key 为官网获取的SK
api_key = '*****************'
secret_key = '********************'

class LandmarkRecognizer(object):
    def __init__(self, api_key, secret_key):
        self.access_token = self._get_access_token(api_key=api_key, secret_key=secret_key)
        self.API_URL = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/landmark' + '?access_token=' \
                      + self.access_token
    #获取token
    @staticmethod
    def _get_access_token(api_key, secret_key):
        api = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials' \
            '&client_id={}&client_secret={}'.format(api_key, secret_key)
        rp = requests.post(api)
        if rp.ok:
            rp_json = rp.json()
            return rp_json['access_token']
        else:
            print('=> Error in get access token!')
    def get_result(self, params):
        rp = requests.post(self.API_URL, data=params)
        if rp.ok:
            rp_json = rp.json()
            return rp_json
        else:
            print('=> Error! token invalid or network error!')
            return None
    #识别地标信息
    def detect(self, img_path):
        f = open(img_path, 'rb')
        strover = '识别结果:'
        img_str = base64.b64encode(f.read())
        params = {'image': img_str}
        rp_json = self.get_result(params)
        result = rp_json['result']
        strover += '  这是:{} \n '.format(result['landmark'])
        print(strover)

if __name__ == '__main__':
    recognizer = LandmarkRecognizer(api_key, secret_key)
    img = 'F:\paddle\dibiao\湖州温泉度假酒店.jpeg'
    recognizer.detect(img)

 

收藏
点赞
0
个赞
共7条回复 最后由用户已被禁言回复于2022-04
#8wangwei8638回复于2019-07
#7 知道认证团回复
国内没敢超过他的

世界奇迹,没有再大的了

0
#7知道认证团回复于2019-07
#6 wangwei8638回复
终于完工了,听说9月试行

国内没敢超过他的

0
#6wangwei8638回复于2019-07
#5 知道认证团回复
这个工程太巨大了,大手笔

终于完工了,听说9月试行

0
#5知道认证团回复于2019-07
#2 wangwei8638回复
用北京大兴国际机场的图片测试一下,未识别出来,百度大脑还在学习吧。 [图片]
展开

这个工程太巨大了,大手笔

0
#4wangwei8638回复于2019-04
#3 用户已被禁言回复
开发者 咱们可以沟通一下么 可以把你的微信号 发送邮件到:v_guoweicheng@baidu.com
展开

请多指教

0
#3用户已被禁言回复于2019-04

开发者 咱们可以沟通一下么 可以把你的微信号 发送邮件到:v_guoweicheng@baidu.com

0
#2wangwei8638回复于2019-04

用北京大兴国际机场的图片测试一下,未识别出来,百度大脑还在学习吧。

0
TOP
切换版块