搜狗ocr识别接口

详细情况在代码中说明,如果不想自己使用TensorFlow,可使用下面接口

这是要识别的图片:

最终识别的结果:

This is a lot of 12 point text to test the
ocr code and see if it works on all types
of file format.
The quick brown dog jumped over the
lazy fox.The quick brown dog jumped
over the lazy fox.The quick brown dog
jumped over the lazy fox.The quick
brown dog jumped over the lazy fox.

代码块:

# _*_ coding: utf-8 _*_
# Time: 2019.4.25
# Author: maxiaohui
# Title 搜狗ocr识别接口
# 这个代码涉及到抓包用的fiddler

import requests  # 库文件

def post_image():
    img = "one.png"  # 图片路径
    files = {"pic_path": open(img, "rb")}  # files # 类似data数据
    url = "http://pic.sogou.com/pic/upload_pic.jsp"  # post的url
    html = requests.post(url, files=files).text  # requests 提交图片
    print('html is ',html)
    get_content(html)  # 结果是url就是图片的url sougou 把本地图片上传到sougou服务器变成了他的图片 调用解析函数把url传入


def get_content(keywords):
    url = "http://pic.sogou.com/pic/ocr/ocrOnline.jsp?query=" + keywords  # keywords就是图片url此方式为get请求
    ocrResult = requests.get(url).json()  # 直接转换为json格式
    contents = ocrResult['result']  # 类似字典 把result的value值取出来 是一个list然后里面很多json就是识别的文字
    for content in contents:  # 遍历所有结果
        print(content['content'].strip())  # strip去除空格 他返回的结果自带一个换行

post_image()  # 调用上传函数
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值