|
发表于 2019-2-19 22:47:08
|
显示全部楼层
黑龙江省鸡西市
不是高手勿喷
个人觉得python本身就是一个脚本语言,很多基础的东西感觉不如易语言入门上手快比较抽象,没有图形界面全靠理解!
优势就是学了一段时间,发现这Py都能干,本身不牛逼,牛逼的是十几万的第三方库
一些官方网站都提供支持,比如调用百度的识图,加载下百度写的第三方库 按文档一调用直接就能用
- """ pip install baidu-aip 安装百度第三方库 """
- from aip import AipOcr
- """ 导入百度第三方库 """
- import time
- """ 你的 APPID AK SK """
- APP_ID="***"
- API_KEY="***"
- SECRET_KEY="*** "
- client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
- import time
- def decorator(func):
- def computation_time(*name,**name1):
- starttinme=time.time()
- func(*name,**name1)
- stoptime = time.time()
- print("运行时间{:.2f}秒...".format(stoptime-starttinme))
- return computation_time
- """ 读取图片 """
- def get_file_content(filePath):
- with open(filePath, 'rb') as fp:
- return fp.read()
- @decorator
- def picture_ocr(Image_name):
- """ 开始执行 """
- The_start_time=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
- print(The_start_time+" 开始请求百度API...")
- """ 添加本地图片 """
- image = get_file_content(Image_name)
- print("开始提交识别图片...")
- """ 调用通用文字识别, 图片参数为本地图片 """
- message=client.basicGeneral(image);
- print("结束识别图片完毕...")
- """ 解析文本内容 """
- for i in message.get('words_result'):
- with open("message.txt","a",encoding="utf-8") as f:
- f.write(i.get('words')+"\n")
- with open("message.txt", "a", encoding="utf-8") as f:
- f.write("----------\n")
- """ 执行完毕 """
- The_start_time=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
- print(The_start_time+" 写入message文本完毕...")
- picture_ocr("1.jpg")
复制代码 |
|