views.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:FaceDetect-TextDetect 作者: FormatFish 项目源码 文件源码
def getTextInfo(filename):
    headers = {'Content-Type':'application/x-www-form-urlencoded'}
    baseUrl = u"https://aip.baidubce.com/rest/2.0/ocr/v1/general?access_token=" + getAccessToken()
    data = {'image': base64.b64encode(open(filename , 'rb').read())}
    data['recognize_granularity'] = 'small'
    data['detect_direction'] = True
    data['vertexes_location'] = True

    r = requests.post(baseUrl , data = data , headers = headers)
    info = json.loads(r.text)
    '''
    wordsRes = info['words_result']
    words = wordsRes[0]['words']
    location = wordsRes[0]['location']

    captha = Image.open(filename)
    draw = ImageDraw.ImageDraw(captha)
    x = location['left']
    y = location['top']
    w = location['width']
    h = location['height']
    draw.rectangle((x , y , x + w , y + h) , outline = 'black')

    chars = wordsRes[0]['chars']
    charMap = {}
    for item in chars:
        charMap[item['char']] = item['location']
    for item in charMap.values():
        x = item['left']
        y = item['top']
        w = item['width']
        h = item['height']
        draw.rectangle((x , y , x + w , y + h) , outline = 'blue')
    '''
    return info
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号