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

这是要识别的图片:

8335f4f9ae34

image

最终识别的结果:

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

lzy 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() # 调用上传函数

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐