求易语言调用tesseract-OCR例子
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了求易语言调用tesseract-OCR例子相关的知识,希望对你有一定的参考价值。
参考技术A 这里可以参照cxf7394373的 字符识别Google开源Tesseract-ocr的DLL调用方法使用其API的一种模式大致是这样:先包含头文件,连接库;然后再定义一个api类,配置好参数之后提取识别结果
#include "strngs.h"
#include "baseapi.h"
#pragma comment(lib,"libtesseract302d.lib")
////////////////
tesseract::TessBaseAPI api;
api.Init(NULL, "eng", tesseract::OEM_DEFAULT); //初始化,设置语言包,中文简体:chi_sim;英文:eng;也可以自己训练语言包
//api.SetVariable( "tessedit_char_whitelist", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" );
STRING text_out;
if (!api.ProcessPages("kaze.tif", NULL, 0, &text_out))
//AfxMessageBox("tesseract 处理出现异常");
return 0;
cout<<text_out.string();
cout<<UTF8ToGBK(text_out.string()).c_str();追问
感谢回答,不过我需要的是易语言调用AIP
Python调用Tesseract-OCR和Zxing完成图片OCR识别和二维码解码
先贴代码:
# 1.Install tesseract-ocr*.exe from http://jaist.dl.sourceforge.net/project/tesseract-ocr-alt/tesseract-ocr-setup-3.02.02.exe # 2.Install pillow as"pip install form *.whl" # 3.Install pytesseract as"pip install form *.whl" import os.path import pytesseract from PIL import Image from jpype import *
##################################################### Tesserace-ocr #################################################### #image = Image.open(r"D:\Project\AI\1.MachineLearning\A.Tensorflow\2.Python_Prj\FirstPython\processed_7039.png") image = Image.open(r"D:\Project\AI\1.MachineLearning\A.Tensorflow\2.Python_Prj\FirstPython\OCR2.png") code = pytesseract.image_to_string(image) code = code.replace(‘ ‘, ‘‘); code = code.replace(‘-‘, ‘‘); code = code.replace(‘\r‘, ‘‘); code = code.replace(‘\n‘, ‘‘); print(code) ##################################################### Zxing Decode ##################################################### # Start jvm jarpath = os.path.join(os.path.abspath(‘.‘), ‘D:/Project/AI/1.MachineLearning/A.Tensorflow/2.Python_Prj/FirstPython/‘) startJVM("C:/Program Files/Java/jre6/bin/server/jvm.dll", "-ea", ("-Djava.class.path=%s" % (jarpath + "javase-2.2.jar" + ";" + jarpath + "core-2.2.jar"))) # Load the useful library classes File = JClass("java.io.File") BufferedImage = JClass("java.awt.image.BufferedImage") ImageIO = JClass("javax.imageio.ImageIO") BinaryBitmap = JClass("com.google.zxing.BinaryBitmap") DecodeHintType = JClass("com.google.zxing.DecodeHintType") LuminanceSource = JClass("com.google.zxing.LuminanceSource") BufferedImageLuminanceSource = JClass("com.google.zxing.client.j2se.BufferedImageLuminanceSource") MultiFormatReader = JClass("com.google.zxing.MultiFormatReader") NotFoundException = JClass("com.google.zxing.NotFoundException") Result = JClass("com.google.zxing.Result") HybridBinarizer = JClass("com.google.zxing.common.HybridBinarizer") Hashtable = JClass("java.util.Hashtable") # Do the qrcode decode image = ImageIO.read(File("D:/Project/AI/1.MachineLearning/A.Tensorflow/2.Python_Prj/FirstPython/Qrcode1.jpg")) source = BufferedImageLuminanceSource(image) bitmap = BinaryBitmap(HybridBinarizer(source)) hints = Hashtable() hints.put(DecodeHintType.CHARACTER_SET, "GBK") result = MultiFormatReader().decode(bitmap, hints) print(result) # Shutdown JVM shutdownJVM()
以上是关于求易语言调用tesseract-OCR例子的主要内容,如果未能解决你的问题,请参考以下文章