java 如何将带有字母的图像转换为文本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25020064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 07:10:03  来源:igfitidea点击:

How could I convert a image with letters to text?

javawebclientcaptchabufferedimagejavax.imageio

提问by bpedroso

I need to find letters in a image. I need a help to write an algorithm to decode the image.

我需要在图像中找到字母。我需要帮助来编写算法来解码图像。

I got the image an there is converted in a ByteArrayOutputStreambut I don′t know what I do with it.

我得到的图像在那里被转换成 aByteArrayOutputStream但我不知道我用它做什么。

There is my java code:

有我的java代码:

URL url = new URL(urlImg);
WebClient webClient = new WebClient(BrowserVersion.getDefault());
WebRequest reqImg = new WebRequest(url);
reqImg.setHttpMethod(HttpMethod.GET);
InputStream imgStream = webClient.getPage(reqImg).getWebResponse().getContentAsStream();
BufferedImage img = ImageIO.read(imgStream);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageIO.write(img, "png", out);

Dependencies: net.sourceforge.htmlunit htmlunit 2.15

依赖项:net.sourceforge.htmlunit htmlunit 2.15

JDK 1.6.0_43

JDK 1.6.0_43

回答by Alex Podworny

http://scraping.pro/example-captcha-solver-java/

http://scraping.pro/example-captcha-solver-java/

I noticed that you're using Java, this is a way to do it in Java. Decoding Captchas is very possible, assuming the captcha is not very secure. This is exactly why captchas are always getting more complex - people can break them.

我注意到您正在使用 Java,这是在 Java 中实现的一种方式。假设验证码不是很安全,解码验证码是非常可能的。这正是验证码总是变得越来越复杂的原因——人们可以破解它们。

EditIf you aren't hard set on Java and don't want to use a paid service, you could use this tutorial with Python: http://www.boyter.org/decoding-captchas/

编辑如果您对 Java 不是很熟悉,并且不想使用付费服务,则可以将本教程与 Python 一起使用:http: //www.boyter.org/decoding-captchas/

-By the way- Decoding Captchas is not always unethical. Sometimes it is required or makes life much easier. For example a company I'm working with will not disable the Captcha on their sites for automated tests that I've made. If I wanted to run my automated tests, I'd have to bypass the Captcha. Granted that also means other people can also bypass the Captcha if they really wanted to, but the company apparently doesn't care and wants easy to read, traditional Captchas.

-顺便说一句-解码验证码并不总是不道德的。有时它是必需的或使生活更轻松。例如,与我合作的公司不会在他们的网站上禁用验证码以进行我所做的自动化测试。如果我想运行我的自动化测试,我必须绕过验证码。当然,这也意味着其他人也可以绕过 Captcha,如果他们真的想要,但该公司显然不在乎并且想要易于阅读的传统 Captcha。