http://www.velocityreviews.com/forums/t126795-java-ocr-.html
I know that it's quite a long time that those posts are here but I found them while looking for an OCR solution in Java, and I would like to share the FREE answer I have created.
I browsed lots of posts while searching for OCR in Java, and all was linking to Asprise / javaocr, but those are unaffordable for non-commercial project.
So I searched for OCR software, without language prereq, in the purpose to interface it with Java.
-I discovered GOCR (http://jocr.sourceforge.net/) which is an ocr in command line. It was a beginning ^^ I downloaded and used Windows version. After few tests I was able to figure how to use it but I've to feed it with PPM images.
-Here come the second software nconvert (http://pagesperso-orange.fr/pierre.g..._nconvert.html) which can convert images to PPM.
So I have done 2 static classes to act like OCR.
The main part is the class OCR, which take a screenshot of the screen, put the proper color (I've made gorc work only with Black letters on White background), write the image to the disk and then call nconvert and gorc.
By parsing outputstream of GOCR process you should have your text recognized. There is the "replace" thing in return because I work on numbers and gorc make some mistakes with 1-l and O-0 ^^
That's not a Strong OCR facility but it can help with little application. Hope it'll help and lot of thanks to nconvert and gocr
package t3x.tnn.utility;
import java.awt.Color;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class OCR {
static public String recognize(Point hg, Point bd, Color color, boolean isColorEcriture){
String res = null;
File fImg = new File("screenshot.png");
while(res == null){
BufferedImage img = ScreenHandler.getScreen(hg, bd);
if(isColorEcriture)
img = changeWithColorEcriture(img, color);
else
img = changeWithColorFond(img, color);
try {
ImageIO.write(img, "PNG", fImg);
Process p = Runtime.getRuntime().exec("nconvert -out ppm -o text.ppm screenshot.png");
p.waitFor();
p.destroy();
p = Runtime.getRuntime().exec("gocr045 text.ppm");
p.waitFor();
if(p.getInputStream().available()>0)
res = IOHandler.getResponse(p.getInputStream());
p.destroy();
}catch (InterruptedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
if(fImg.exists())
fImg.delete();
File texte = new File("text.ppm");
if(texte.exists())
texte.delete();
return res.replace("l", "1").replace("O", "0").trim();
}
private static BufferedImage changeWithColorEcriture(BufferedImage bi, Color ecriture) {
if (bi != null) {
int w = bi.getWidth();
int h = bi.getHeight();
int pixel;
BufferedImage bitmp = new BufferedImage(w, h, bi.getType());
BufferedImage biOut = new BufferedImage(w, h, bi.getType());
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
pixel = bi.getRGB(x, y);
if(pixel != ecriture.getRGB())
pixel = Color.BLUE.getRGB();
else
pixel = Color.BLACK.getRGB();
bitmp.setRGB(x, y, pixel);
}
}
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
pixel = bitmp.getRGB(x, y);
if(pixel == Color.BLUE.getRGB())
pixel = Color.WHITE.getRGB();
biOut.setRGB(x, y, pixel);
}
}
return biOut;
} else {
return bi;
}
}
private static BufferedImage changeWithColorFond(BufferedImage bi, Color fond) {
if (bi != null) {
int w = bi.getWidth();
int h = bi.getHeight();
int pixel;
BufferedImage bitmp = new BufferedImage(w, h, bi.getType());
BufferedImage biOut = new BufferedImage(w, h, bi.getType());
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
pixel = bi.getRGB(x, y);
if(pixel == fond.getRGB())
pixel = Color.BLUE.getRGB();
else
pixel = Color.WHITE.getRGB();
bitmp.setRGB(x, y, pixel);
}
}
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
pixel = bitmp.getRGB(x, y);
if(pixel == Color.BLUE.getRGB())
pixel = Color.WHITE.getRGB();
biOut.setRGB(x, y, pixel);
}
}
return biOut;
} else {
return bi;
}
}
}
package t3x.tnn.utility;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
public class ScreenHandler {
public static Color getPixelColor(Point p){
return getPixelColor(p.x, p.y);
}
public static BufferedImage getScreen(Point hg, Point bd){
checkNano();
return nano.createScreenCapture(new Rectangle(hg, new Dimension(bd.x-hg.x, bd.y-hg.y)));
}
public static boolean areImagesEqual(BufferedImage img1, BufferedImage img2){
int[] timg1 = getPixels(img1);
int[] timg2 = getPixels(img2);
for(int i = 0 ; i < timg1.length; i++){
if(timg1[i]!=timg2[i]){
return false;
}
}
return true;
}
public static Color analyse(Point depart, int deviation, Color fond){
for(int i= depart.x; i < depart.x+deviation; i++){
Color col = ScreenHandler.getPixelColor(i, depart.y);
if(!col.equals(fond))
return col;
}
//IOHandler.abort("[ScreenHandler.analyse] : Aucune couleur de jeu trouvée");
return null;
}
///////////////////////////////////////////////////////////////////////////////////
private static Robot nano;
private static Color getPixelColor(int x, int y){
checkNano();
return nano.getPixelColor(x, y);
}
private static int[] getPixels(BufferedImage img){
return img.getRaster().getPixels(img.getRaster().getMinX(), img.getRaster().getMinY(), img.getRaster().getWidth(), img.getRaster().getHeight(), new int[ img.getRaster().getWidth()*img.getRaster().getHeight()*10]);
}
private static void checkNano(){
if(nano == null)
try {
nano = new Robot();
} catch (AWTException e) {
e.printStackTrace();
}
}
}
分享到:
相关推荐
如果你的Office 2003安装没有包含MODI,可以通过Office XP Resource Kit或者单独下载MODI进行添加。 在具备了OCR组件之后,我们可以开始利用PowerBuilder 9.0来创建一个应用程序,以调用OCR功能。PowerBuilder是一...
标题中的“hw_num_ocr.rar”表明这是一个关于OCR(光学字符识别)技术的项目,特别是针对手写数字的识别。OCR技术是计算机视觉领域的一种重要技术,它允许计算机自动识别并转换图像中的文本或数字为可编辑的文本格式...
例如,“crsctl relocate resource”命令可以用来重新定位资源,而“crsctl stat resource”可以用来查看资源的状态信息。 CSS(Cluster Synchronization Services)参数对于集群的健康和稳定性至关重要。其中,...
4. **Resource1.Designer.cs和Resource1.resx**:这两个文件是资源管理相关的,Designer.cs文件通常包含了资源文件的元数据和自动生成的代码,而resx文件则存储了项目中的资源,比如图标、字符串、图像等。...
需要指出的是,由于文档是由OCR技术扫描生成的,可能会存在一些字词的识别错误或遗漏。因此,在实际使用文档时,开发者应该对照OneNET平台的最新官方文档,以及相关的API接口文档,来确保信息的准确性和操作的正确性...
下载地址:https://gitee.com/giteesource/app/blob/master/resource/3.md 这款软件确实是一款集截图工具与OCR文字识别于一体的强大工具,相较于QQ、Snipaste等同类产品,其优势在于功能更加丰富且操作体验更为出色...
AutoJs源码-百度ocr 简单版。本资源购买前提醒:本源码都是实际autojs项目模板,安装好autojs直接运行即可打开。1、支持低版本autojs。2、资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己承担...
根据给定文件信息,标题是"Resource Guide BCM47xx",描述为"Linux and VxWorks Resource Guide",标签是"Broadcom VxWorks"。这意味着文档是一份面向Linux和VxWorks操作系统的Broadcom BCM47xx系列设备的资源指南。...
AutoJs源码-百度ocr图片文字识别。本资源购买前提醒:本源码都是实际autojs项目模板,安装好autojs直接运行即可打开。1、支持低版本autojs。2、资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己...
AutoJs源码-百度ocr图片文字识别(1)。本资源购买前提醒:本源码都是实际autojs项目模板,安装好autojs直接运行即可打开。1、支持低版本autojs。2、资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您...
AutoJs源码-百度ocr图片文字识别修改开始按钮,作者xxoo。本资源购买前提醒:本源码都是实际autojs项目模板,安装好autojs直接运行即可打开。1、支持低版本autojs。2、资源仅供学习与参考,请勿用于商业用途,否则...
标题“Dynamic Resource Allocation for Load Balancing in Fog Environment”所指的知识点集中在雾计算环境下动态资源分配对负载均衡的支持上。负载均衡是任何计算资源管理的关键因素之一,目的在于提高资源效率,...
OCR存储整个集群的配置信息,包括系统、数据库和CRS(Cluster Resource Stack)的设置,以键值对的形式保存。OCR的重要性在于解决了"脑裂"和"健忘"问题,即确保配置信息在所有节点间的一致性。Voting Disks则用于...
OCR在Oracle 10g之后进行了重构,存储集群的系统、数据库和CRS(Cluster Resource Software)等信息。OCR的位置信息保存在ocr.loc文件中,其内容以键值对的形式组织,分为SYSTEM、DATABASE和CRS三个主要分支。SYSTEM...
Oracle Clusterware的后台进程中,CRSD(Cluster Resource State Daemon)是核心进程,负责资源的管理与监控;CSSD(Cluster Synchronization Services Daemon)处理集群同步,确保节点间的信息一致;而EVMD(Event ...
VIP会在节点故障时由CRS(Cluster Resource Manager)自动转移到正常节点。 2. **OCR(Oracle Cluster Registry)和VOTING DISK**: - **OCR**:存储集群配置信息,解决"健忘"问题,确保配置同步。OCR磁盘必须是...
将`libtesseract.so`放在`resource`目录下的`linux-x86-64`子目录下,意味着它是专门为64位Linux系统准备的,并且可能需要在编译或运行时将其路径添加到LD_LIBRARY_PATH环境变量中,以便正确地找到和加载这个库。...
项目文件"code_resource_010"可能是代码资源的一部分,可能包含了实现以上功能的部分或全部代码。这些代码可能涉及到数据读取、预处理、特征抽取和模型训练等多个步骤,是实现整个数据提取流程的关键。 总结来说,...