车辆检测vehicleDetect调用失败
不造木木 发布于2021-10 浏览:2169 回复:0
1
收藏

问题

1.调用vehicleDetect()函数时出现以下错误:AipImageClassify中不含有vehicleDetect,但文档中心上表示vehicleDetect确实属于AipImageClassify

Traceback (most recent call last):
  File "D:/pycharm/baiduAI/SDK/车辆检测.py", line 18, in 
    result=client.vehicleDetect(image)
AttributeError: 'AipImageClassify' object has no attribute 'vehicleDetect'

2.按住ctrl键时点击AipImageClassify,跳转到AipImageClassify,我们查看是否含有vehicleDetect

# -*- coding: utf-8 -*-

"""
图像识别
"""

import re
import sys
import math
import time
from .base import AipBase
from .base import base64
from .base import json
from .base import urlencode
from .base import quote

class AipImageClassify(AipBase):

    """
    图像识别
    """

    __advancedGeneralUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general'

    __dishDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v2/dish'

    __carDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/car'

    __logoSearchUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v2/logo'

    __logoAddUrl = 'https://aip.baidubce.com/rest/2.0/realtime_search/v1/logo/add'

    __logoDeleteUrl = 'https://aip.baidubce.com/rest/2.0/realtime_search/v1/logo/delete'

    __animalDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/animal'

    __plantDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/plant'

    __objectDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/object_detect'

    __landmarkUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/landmark'

    __flowerUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/flower'

    __ingredientUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/classify/ingredient'

    __redwineUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/redwine'

    __currencyUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/currency'

    
    def advancedGeneral(self, image, options=None):
        """
            通用物体识别
        """
        options = options or {}

        data = {}
        data['image'] = base64.b64encode(image).decode()

        data.update(options)

        return self._request(self.__advancedGeneralUrl, data)
    
    def dishDetect(self, image, options=None):
        """
            菜品识别
        """
        options = options or {}

        data = {}
        data['image'] = base64.b64encode(image).decode()

        data.update(options)

        return self._request(self.__dishDetectUrl, data)
    
    def carDetect(self, image, options=None):
        """
            车辆识别
        """
        options = options or {}

        data = {}
        data['image'] = base64.b64encode(image).decode()

        data.update(options)

        return self._request(self.__carDetectUrl, data)
    
    def logoSearch(self, image, options=None):
        """
            logo商标识别
        """
        options = options or {}

        data = {}
        data['image'] = base64.b64encode(image).decode()

        data.update(options)

        return self._request(self.__logoSearchUrl, data)
    
    def logoAdd(self, image, brief, options=None):
        """
            logo商标识别—添加
        """
        options = options or {}

        data = {}
        data['image'] = base64.b64encode(image).decode()
        data['brief'] = brief

        data.update(options)

        return self._request(self.__logoAddUrl, data)
    
    def logoDeleteByImage(self, image, options=None):
        """
            logo商标识别—删除
        """
        options = options or {}

        data = {}
        data['image'] = base64.b64encode(image).decode()

        data.update(options)

        return self._request(self.__logoDeleteUrl, data)
    
    def logoDeleteBySign(self, cont_sign, options=None):
        """
            logo商标识别—删除
        """
        options = options or {}

        data = {}
        data['cont_sign'] = cont_sign

        data.update(options)

        return self._request(self.__logoDeleteUrl, data)
    
    def animalDetect(self, image, options=None):
        """
            动物识别
        """
        options = options or {}

        data = {}
        data['image'] = base64.b64encode(image).decode()

        data.update(options)

        return self._request(self.__animalDetectUrl, data)
    
    def plantDetect(self, image, options=None):
        """
            植物识别
        """
        options = options or {}

        data = {}
        data['image'] = base64.b64encode(image).decode()

        data.update(options)

        return self._request(self.__plantDetectUrl, data)
    
    def objectDetect(self, image, options=None):
        """
            图像主体检测
        """
        options = options or {}

        data = {}
        data['image'] = base64.b64encode(image).decode()

        data.update(options)

        return self._request(self.__objectDetectUrl, data)
    
    def landmark(self, image, options=None):
        """
            地标识别
        """
        options = options or {}

        data = {}
        data['image'] = base64.b64encode(image).decode()

        data.update(options)

        return self._request(self.__landmarkUrl, data)
    
    def flower(self, image, options=None):
        """
            花卉识别
        """
        options = options or {}

        data = {}
        data['image'] = base64.b64encode(image).decode()

        data.update(options)

        return self._request(self.__flowerUrl, data)
    
    def ingredient(self, image, options=None):
        """
            食材识别
        """
        options = options or {}

        data = {}
        data['image'] = base64.b64encode(image).decode()

        data.update(options)

        return self._request(self.__ingredientUrl, data)
    
    def redwine(self, image, options=None):
        """
            红酒识别
        """
        options = options or {}

        data = {}
        data['image'] = base64.b64encode(image).decode()

        data.update(options)

        return self._request(self.__redwineUrl, data)
    
    def currency(self, image, options=None):
        """
            货币识别
        """
        options = options or {}

        data = {}
        data['image'] = base64.b64encode(image).decode()

        data.update(options)

        return self._request(self.__currencyUrl, data)
    

3.我们发现AipImageClassify中不含vehicleDetect,由此可见为什么会保这个错误,为了解决这个问题,我们需要在这个代码里加入vehicleDetect()

解决办法

1.我们找到官方提供的python SDK代码

2.进入sdk后找到python SDK 下载

3.下载完成后解压,用pycharm打开SDK,找到AipImageClassify

4.ctrl+A全选复制所有代码,ctrl键点击跳转到AipImageClassify,替换所有代码,替换后可以正常调用vehicleDetect,下面是我的运行代码和结果

收藏
点赞
1
个赞
TOP
切换版块