300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > Python 百度智能云文字识别 实现手写文字识别

Python 百度智能云文字识别 实现手写文字识别

时间:2018-10-08 23:47:36

相关推荐

Python 百度智能云文字识别 实现手写文字识别

Python 实现手写文字识别

简介

百度智能云人工智能平台文字识别接口使用下载IP摄像头应用 调用手机摄像头,实现拍照实现文字识别

Python 百度智能云人工智能文字识别接口 实现手写文字识别

百度智能云

创建应用

创建Python文件

注意:其中__init__.py,只需要建立一个,不需要添加东西在里面

环境配置

Pycharm开发环境 python 版本 python3.7Anconda 集成开发环境

第三方库安装

Python 环境pip install opencv-pythonpip install baidu-aip Anconda 环境conda install opencv-pythonconda install baidu-aip

Handwritten.py

from aip import AipOcr #pip install baidu-aipconfig = {'appId':'','apiKey':'','secretKey':''}# appId apiKey secretKey 三元组,添加自己的创建应用里面的client = AipOcr(**config)# 获取图像内容def get_file_content(file):with open(file,'rb') as f:return f.read()# 文字 to 字符def img_to_str(image_path):image = get_file_content(image_path)result = client.handwriting(image)# print(result)if 'words_result' in result:return '\n'.join([w['words'] for w in result['words_result']])

ipdemo.py

import cv2 # pip install openv-pythonfrom Handwritten import img_to_str # 导入 img_to_strif __name__ == '__main__':# 创建一个窗口 1表示不能改变窗口大小cv2.namedWindow("camera",1)# 开启ip摄像头 # http://admin:admin@192.168.137.53:8081/video# 用户名/密码默认admin @ip地址 端口video = 'http://admin:admin@IP地址:端口/video'# 开启摄像头capture = cv2.VideoCapture(video)# 按键处理while True:success,img = capture.read()cv2.imshow("camera",img)# 按键处理key = cv2.waitKey(10)# esc 退出if key == 27:print("esc break")break# 空格 保存图片if key ==32:filename = "filename.png"cv2.imwrite(filename,img)s = img_to_str(filename)print(s) #显示识别内容# 释放摄像头capture.release()#关闭窗口cv2.destroyWindow('camera')

效果

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。