tesseract_ocr+pytesseract图像识别
一、windows安装配置
其他系统安装配置参考github:https://github.com/tesseract-ocr/tesseract/wiki
下载tesseract-ocr参考:https://github.com/tesseract-ocr/tesseract/wiki/Downloads
下载chi_sim.traineddata参考:https://github.com/tesseract-ocr/tesseract/wiki/Data-Files
1、pip install pytesseract
2、pip install pillow
3、安装tesseract-ocr
4、找到pytesseract模块中pytesseract.py 更改 tesseract_cmd = r'F:\tesseract_ocr\tesseract-Win64\tesseract.exe'
5、添加环境变量(变量名:TESSDATA_PREFIX,变量值:F:\tesseract_ocr\tesseract-Win64,即安装目录)
6、如果识别中文,下载训练数据chi_sim.traineddata,并拷贝到 F:\tesseract_ocr\tesseract-Win64\tessdata目录下
ps:
临时在 cmd 中设置环境变量,测试:set TESSDATA_PREFIX=F:\tesseract_ocr\tesseract-Win64
命令行运行(以.txt文件格式保存):tesseract.exe E:\python\project\mysite\media\tesseract.png C:\Users\konglingxi\Desktop\test -l chi_sim+equ+eng
二、例子
.py文件
#!/usr/bin/python
# coding:utf-8
from __future__ import unicode_literals
from django.conf import settings
import pytesseract
from PIL import Image as pillow_image
from django.shortcuts import render_to_response
from django.template import RequestContext
__author__ = "klx"
# Create your views here.
def binaryzation(threshold, image_address):
"""
# 二值化,输入阈值和文件地址
:param threshold:
:param image_address:
:return:
"""
image = pillow_image.open(image_address) # 打开图片
image = image.convert('L') # 灰度化
table = []
for x in range(256): # 二值化
if x < threshold:
table.append(0)
else:
table.append(1)
image = image.point(table, '1')
return image
def main():
"""
测试
:return:
"""
# 指定配置目录
tessdata_dir_config = '--tessdata-dir "F:\\tesseract_ocr\\tesseract-Win64"'
image_url = settings.MEDIA_ROOT + r"\tesseract.png"
# image_url = settings.MEDIA_ROOT + r"\tesseract.jpg"
image = binaryzation(200, image_url)
image.show() # 展示二值化后的效果,防止图片二值化效果不佳变成一片白无法识别
result = pytesseract.image_to_string(image, config=tessdata_dir_config, lang="chi_sim+eng") # 变图片为字符串
return result
def test(request):
res = main()
return render_to_response("ocr_app/test.html", {"data": res}, context_instance=RequestContext(request))
.html模板
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>tesseract_ocr</title>
</head>
<body>
{{ data }}
</body>
</html>
tesseract_ocr+pytesseract图像识别的更多相关文章
- 基于Eclipse下的python图像识别菜鸟版(利用pytesseract以及tesseract)
这是我注册博客后写的第一篇博客,希望对有相关问题的朋友有帮助. 在图像识别前,首先我们要做好准备工作. 运行环境:windows7及以上版本 运行所需软件:(有基础的可以跳过这一段)eclipse,p ...
- 使用pytesseract进行图像识别
引言 对于简单验证码及一些图像的识别,我们需要使用pytesseract及相应的Tesseract引擎,它是开源的OCR引擎.帮助我们做一些简单的图像识别 当然为了更好将图片识别,对一些像素比较低的图 ...
- 利用Python进行简单的图像识别(验证码)
这是一个最简单的图像识别,将图片加载后直接利用Python的一个识别引擎进行识别 将图片中的数字通过 pytesseract.image_to_string(image)识别后将结果存入到本地的txt ...
- python 简单图像识别--验证码
python 简单图像识别--验证码 记录下,准备工作安装过程很是麻烦. 首先库:pytesseract,image,tesseract,PIL windows安装PIL,直接exe进行安装更方便( ...
- python3光学字符识别模块tesserocr与pytesseract
OCR,即Optical Character Recognition,光学字符识别,是指通过扫描字符,然后通过其形状将其翻译成电子文本的过程,对应图形验证码来说,它们都是一些不规则的字符,这些字符是由 ...
- python 图像识别
这是一个最简单的图像识别,将图片加载后直接利用Python的一个识别引擎进行识别 将图片中的数字通过 pytesseract.image_to_string(image)识别后将结果存入到本地的txt ...
- Python之selenium+pytesseract 实现识别验证码自动化登录脚本
今天写自己的爆破靶场WP时候,遇到有验证码的网站除了使用pkav的工具我们同样可以通过py强大的第三方库来实现识别验证码+后台登录爆破,这里做个笔记~~~ 0x01关于selenium seleniu ...
- tesserocr与pytesseract模块的使用
1.tesserocr的使用 #从文件识别图像字符 In [7]: tesserocr.file_to_text('image.png') Out[7]: 'Python3WebSpider\n\n' ...
- 自动化测试面试官:登录或注册时有验证码怎么处理?OCR图像识别技术大揭秘!
本节大纲 读取cookie实现免登陆 pytesseract+tesseract-ocr实现图像识别 Pillow库对验证码截图 API接口实现图像识别 今天的这个技术点,为什么要给大家分享一下呢? ...
随机推荐
- duilib bkimage 属性
duilib bkimage 属性<Attribute name="bkimage" default="" type="STRING" ...
- Solr记录-solr文档xml
Solr添加文档(XML) 在上一章中,我们学习解释了如何向Solr中添加JSON和.CSV文件格式的数据.在本章中,将演示如何使用XML文档格式在Apache Solr索引中添加数据. 示例数据 假 ...
- ubuntu中mysql中文乱码及用python3.x调用
首先声明解决方法也是网上找来的,知识自己记下来以防以后用到. ubuntu版本是14.04使用apt-get命令安装mysql sudo apt-get install mysql-server ...
- [转载]Markdown——入门指南
http://www.jianshu.com/p/1e402922ee32/ 转载请注明原作者,如果你觉得这篇文章对你有帮助或启发,也可以来请我喝咖啡. 导语: Markdown 是一种轻量级的「标记 ...
- 第10月第25天 java annotation
1. http://snkcxy.iteye.com/blog/1823046
- matrix 矩阵(多维DP)
题面 \(solution:\) 这一题其实就是一个非常明显的三维背包问题(但博主太弱了就10分QAQ) \(F[i][j][k]:\)表示走到\((i,j)\)这个位置并且背包容量为 \(k\) 时 ...
- SpringBoot框架的权限管理系统
springBoot框架的权限管理系统,支持操作权限和数据权限,后端采用springBoot,MyBatis,Shiro,前端使用adminLTE,Vue.js,bootstrap-table.tre ...
- MacOS 下提示APP 损坏 无法安装 解决方法
sudo spctl --master-disable
- elasticsearch常见异常及解决办法
报错信息:Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 20602552 ...
- Springboot分模块开发详解(2):建立子工程
1.创建base-entity 选中base工程,右键创建一个新的maven工程 自动选择了base这个目录存放子工程 创建后,pom.xml修改成如下内容: <?xml version=&qu ...