百度OCR识别图片文字,解决image format error错误

本文涉及的产品
票据凭证识别,票据凭证识别 200次/月
应用型负载均衡 ALB,每月750个小时 15LCU
公共DNS(含HTTPDNS解析),每月1000万次HTTP解析
简介: 百度OCR识别图片文字,解决image format error错误

1 方法一

  • 依赖
        <!-- 阿里JSON解析器 -->
        <dependency>
            <groupId>com.alibaba.fastjson2</groupId>
            <artifactId>fastjson2</artifactId>
            <version>2.0.16</version>
        </dependency>

1.1 新建HttpUtils,用来发送post请求

package com.xinglong.spider.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;

/**
 * @Author:胡云峰
 * @Date:2022/12/7 10:43
 */
public class HttpUtils {
    private static final Logger log = LoggerFactory.getLogger(HttpUtils.class);

    /**
     * 向指定 URL 发送POST方法的请求
     *
     * @param url 发送请求的 URL
     * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
     * @return 所代表远程资源的响应结果
     */
    public static String sendPost(String url, String param,String contentType)
    {
        PrintWriter out = null;
        BufferedReader in = null;
        StringBuilder result = new StringBuilder();
        try
        {
            log.info("sendPost - {}", url);
            URL realUrl = new URL(url);
            URLConnection conn = realUrl.openConnection();
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            conn.setRequestProperty("Accept-Charset", "utf-8");
            conn.setRequestProperty("content-type", contentType);
            conn.setDoOutput(true);
            conn.setDoInput(true);
            out = new PrintWriter(conn.getOutputStream(),true);
            out.print(param);
            out.flush();
            in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
            String line;
            while ((line = in.readLine()) != null)
            {
                result.append(line);
            }
            log.info("recv - {}", result);
        }
        catch (ConnectException e)
        {
            log.error("调用HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e);
        }
        catch (SocketTimeoutException e)
        {
            log.error("调用HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e);
        }
        catch (IOException e)
        {
            log.error("调用HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e);
        }
        catch (Exception e)
        {
            log.error("调用HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e);
        }
        finally
        {
            try
            {
                if (out != null)
                {
                    out.close();
                }
                if (in != null)
                {
                    in.close();
                }
            }
            catch (IOException ex)
            {
                log.error("调用in.close Exception, url=" + url + ",param=" + param, ex);
            }
        }
        return result.toString();
    }
}

1.2 获取 access token

/**
     * @ author 胡云峰
     * 获取   access token
     * 注意: access_token的有效期为30天,需要每30天进行定期更换;
     */
    public static String getAccessToken(){
        //向https://aip.baidubce.com/oauth/2.0/token发送请求
        String url = "https: //aip.baidubce.com/oauth/2.0/token";
        //设置contentType格式
        String contentType = "application/x-www-form-urlencoded";
        // 固定值为client_credentials
        String grant_type = "client_credentials";
        //应用的 API Key  这里使用自己的
        String client_id = "***********";
        //应用的 Secret Key  这里使用自己的
        String client_secret = "************";
        //参数
        String para = "grant_type="+grant_type+"&client_id="+client_id+"&client_secret=" + client_secret;
        //发起post请求
        String resp = HttpUtils.sendPost(url, para, contentType);
        //解析返回信息获取access_token
        JSONObject jsonObject = JSONObject.parseObject(resp);
        return jsonObject.get("access_token").toString();
    }

1.3 获取图片的文字信息

/**
     * 获取图片文字信息
     * @return
     */
    public static String getOcrMessage(){
        String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic" + "?access_token=" +getAccessToken();
        //设置contentType格式
        String contentType = "application/x-www-form-urlencoded";
        //image base64 
        //请求格式支持:PNG、JPG、JPEG、BMP、TIFF、PNM、WebP
        String imgStr = "/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PT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xXJf8JPe/8APK3/AO+W/wAaX/hKL3/nlb/98t/jR7aIe2ideKdtBrj/APhKr7/nlb/98t/jS/8ACV33/PK2/wC+W/xo9tEPbROvES+gqVUArjP+Etv/APnjbf8AfLf40v8Awl+of88bb/vlv/iqPbRD20TtgKeK4f8A4TDUP+eNr/3y3/xVL/wmWo/88bX/AL5b/wCKo9tEPbRO5xkUnkKTnFcR/wAJnqP/ADxtf++G/wDiqX/hNdS/54Wn/fDf/FUe2iHtoneIoUcVIK4D/hNtS/54Wn/fDf8AxVL/AMJxqf8AzwtP++G/+Ko9tEPbRPQRVXV/+QHqH/XtJ/6Ca4r/AITnU/8Anhaf98N/8VUdz4z1G6tZrd4bUJKjIxVWyARjj5qmVaNmKVWNmf/Z";
        //注意:一定要urlencoder,否则会出现图片格式不对的报错
        try {
            //使用Postman工具或 Python、PHP 等请求库会自动进行urlencode,无需自行处理
            imgStr = URLEncoder.encode(imgStr, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        //发起请求
        String resp = HttpUtils.sendPost(url, "image=" + imgStr, contentType);
        //利用阿里的fastjson解析
        JSONObject jsonObject = JSONObject.parseObject(resp);
        String wordsResult = jsonObject.get("words_result").toString();
        //words_result是一个集合
        JSONArray jsonArray = JSONArray.parseArray(wordsResult);
        //组装解析后的结果
        StringBuilder sb = new StringBuilder();
        for (Object o : jsonArray) {
            //Object强转成JSONObject
            JSONObject jObject = (JSONObject) o;
            //解析words
            String words = jObject.get("words").toString();
            //组装到sb
            sb.append(words);
        }
        //返回结果
        return sb.toString();
    }

1.4 测试

    public static void main(String[] args) {
        String ocrMessage = getOcrMessage();
        System.out.println(ocrMessage);
    }

1.5 结果

9*9=3

2 方法二使用jsoup

  • 依赖
        <!-- 阿里JSON解析器 -->
        <dependency>
            <groupId>com.alibaba.fastjson2</groupId>
            <artifactId>fastjson2</artifactId>
            <version>2.0.16</version>
        </dependency>
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.15.3</version>
        </dependency>

2.1 获取 access token

public static String getAccessToken() throws IOException {
        //获取请求连接
        Connection con = Jsoup.connect("https://aip.baidubce.com/oauth/2.0/token");
        con.header("Content-Type","application/x-www-form-urlencoded");
        con.data("grant_type","client_credentials");
        con.data("client_id","************");
        con.data("client_secret","****************");
        Connection.Response response = con.ignoreContentType(true).method(Connection.Method.POST).execute();
        String body = response.body();
        JSONObject jsonObject = JSONObject.parseObject(body);
        String accessToken = jsonObject.get("access_token").toString();
        return accessToken;
    }

2.2 获取图片的文字信息

public static String getOcrMessage(String imgStr) throws IOException {
        String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic" + "?access_token=" + getAccessToken();
        Connection con = Jsoup.connect(url);
        con.header("Content-Type","application/x-www-form-urlencoded");
        con.data("image",imgStr);
        Connection.Response execute = con.ignoreContentType(true).method(Connection.Method.POST).execute();
        String body = execute.body();
        //利用阿里的fastjson解析
        JSONObject jsonObject = JSONObject.parseObject(body);
        String wordsResult = jsonObject.get("words_result").toString();
        //words_result是一个集合
        JSONArray jsonArray = JSONArray.parseArray(wordsResult);
        //组装解析后的结果
        StringBuilder sb = new StringBuilder();
        for (Object o : jsonArray) {
            //Object强转成JSONObject
            JSONObject jObject = (JSONObject) o;
            //解析words
            String words = jObject.get("words").toString();
            //组装到sb
            sb.append(words);
        }
        //返回结果
        return sb.toString();
    }

2.3 测试

public static void main(String[] args) throws IOException {
        //image base64 使用jsoup不需要urlencode
        String imgStr = "/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAA8AKADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAA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f8A4TDUP+eNr/3y3/xVL/wmWo/88bX/AL5b/wCKo9tEPbRO5xkUnkKTnFcR/wAJnqP/ADxtf++G/wDiqX/hNdS/54Wn/fDf/FUe2iHtoneIoUcVIK4D/hNtS/54Wn/fDf8AxVL/AMJxqf8AzwtP++G/+Ko9tEPbRPQRVXV/+QHqH/XtJ/6Ca4r/AITnU/8Anhaf98N/8VUdz4z1G6tZrd4bUJKjIxVWyARjj5qmVaNmKVWNmf/Z";
        String ocrMessage = getOcrMessage(imgStr);
        System.out.println(ocrMessage);
    }
目录
相关文章
|
4天前
|
编解码 文字识别 自然语言处理
如何使用OCR技术批量识别图片中的文字并重命名文件,OCR 技术批量识别图片中的文字可能出现的错误
### 简介 【批量识别图片内容重命名】工具可批量识别图片中的文字并重命名文件,方便高效处理大量图片。然而,OCR 技术面临字符识别错误(如形近字混淆、生僻字识别不佳)、格式错误(段落错乱、换行问题)和语义理解错误等挑战。为提高准确性,建议提升图片质量、选择合适的 OCR 软件及参数,并结合自动校对与人工审核,确保最终文本的正确性和完整性。
30 12
如何使用OCR技术批量识别图片中的文字并重命名文件,OCR 技术批量识别图片中的文字可能出现的错误
|
5月前
|
机器学习/深度学习 文字识别 前端开发
基于 Spring Boot 3.3 + OCR 实现图片转文字功能
【8月更文挑战第30天】在当今数字化信息时代,图像中的文字信息越来越重要。无论是文档扫描、名片识别,还是车辆牌照识别,OCR(Optical Character Recognition,光学字符识别)技术都发挥着关键作用。本文将围绕如何使用Spring Boot 3.3结合OCR技术,实现图片转文字的功能,分享工作学习中的技术干货。
274 2
|
5月前
|
机器学习/深度学习 人工智能 文字识别
轻松识别文字,这款Python OCR库支持超过80种语言
轻松识别文字,这款Python OCR库支持超过80种语言
299 2
|
5月前
|
人工智能 JSON 文字识别
【实操】Java+百度ocr,实现图片识别文字小工具
本文介绍了一个基于Java和百度OCR的文字识别工具,能够通过截图或上传图片实现文字识别,并使用exe4j将工具封装为exe文件以便于使用。文章详细介绍了实现过程,包括Java Swing页面布局、百度OCR配置及使用方法,以及如何将Java项目打包成jar和exe文件。此外,还提供了一些相关资源供读者参考。
86 0
【实操】Java+百度ocr,实现图片识别文字小工具
|
5月前
|
开发框架 文字识别 前端开发
基于百度智能云的OCR接口进行图文识别
基于百度智能云的OCR接口进行图文识别
|
6月前
|
人工智能 文字识别 开发工具
印刷文字识别使用问题之是否支持识别并返回文字在图片中的位置信息
印刷文字识别产品,通常称为OCR(Optical Character Recognition)技术,是一种将图像中的印刷或手写文字转换为机器编码文本的过程。这项技术广泛应用于多个行业和场景中,显著提升文档处理、信息提取和数据录入的效率。以下是印刷文字识别产品的一些典型使用合集。
|
6月前
|
人工智能 JSON 文字识别
印刷文字识别使用问题之如何数电发票进行识别
印刷文字识别产品,通常称为OCR(Optical Character Recognition)技术,是一种将图像中的印刷或手写文字转换为机器编码文本的过程。这项技术广泛应用于多个行业和场景中,显著提升文档处理、信息提取和数据录入的效率。以下是印刷文字识别产品的一些典型使用合集。
|
6月前
|
文字识别 数据安全/隐私保护 iOS开发
印刷文字识别使用问题之如何识别礼品册上的卡号、密码信息
印刷文字识别产品,通常称为OCR(Optical Character Recognition)技术,是一种将图像中的印刷或手写文字转换为机器编码文本的过程。这项技术广泛应用于多个行业和场景中,显著提升文档处理、信息提取和数据录入的效率。以下是印刷文字识别产品的一些典型使用合集。
|
5月前
|
数据采集 机器学习/深度学习 文字识别
OCR -- 文本检测 - 训练DB文字检测模型
OCR -- 文本检测 - 训练DB文字检测模型
119 0
|
5月前
|
机器学习/深度学习 文字识别 算法
百度飞桨(PaddlePaddle) - PaddleHub OCR 文字识别简单使用
百度飞桨(PaddlePaddle) - PaddleHub OCR 文字识别简单使用
374 0