C# 通用OCR识别 文字识别 中文识别

软件说明

基于以下两个开源项目,做了再次封装

https://github.com/paddlepaddle/PaddleOCR

PaddleOCRSharp: 本项目是一个基于PaddleOCR的C++代码修改并封装的.NET的OCR工具类库。包含文本识别、文本检测、基于文本检测结果的统计分析的表格识别功能,同时针对小图识别不准的情况下,做了优化,提高识别准确率。包含总模型仅8.6M的超轻量级中文OCR,单模型支持中英文数字组合识别、竖排文本识别、长文本识别。同时支持多种文本检测。

可以一键开启服务;

自带模型,可离线部署;

自带C++相关动态库;

测试地址http://47.108.88.211/manual/OCRTest.html

软件目录

软件界面

测试

选择图片测试效果

 截图识别效果 

html页面测试效果

接口调用测试效果

软件下载

VB调用代码

        Dim request As WebRequest = WebRequest.Create("http://47.108.88.211:8082/ocr/base64")
        request.Method = "POST"

        Dim postData As String = "base64str=%2F9j%2F4AAQSkZJRgABAQEAYABgAAD%2F2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL%2F2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL%2FwAARCAAYAE8DASIAAhEBAxEB%2F8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL%2F8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4%2BTl5ufo6erx8vP09fb3%2BPn6%2F8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL%2F8QAtREAAgECBAQDBAcFBAQAAQJ3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ContentType = "application/x-www-form-urlencoded"
        request.ContentLength = byteArray.Length

        Dim dataStream As Stream = request.GetRequestStream()
        dataStream.Write(byteArray, 0, byteArray.Length)
        dataStream.Close()

        Dim response As System.Net.HttpWebResponse = CType(request.GetResponse(), System.Net.HttpWebResponse)
        Dim ReStream As StreamReader = New StreamReader(response.GetResponseStream, System.Text.Encoding.GetEncoding("utf-8"))

        Dim resStr As String = ReStream.ReadToEnd()
        response.Close()
        MsgBox(resStr)

 C#调用代码

var client = new RestClient("http://47.108.88.211:8082/ocr/base64");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("application/x-www-form-urlencoded", "base64str=%2F9j%2F4AAQSkZJRgABAQEAYABgAAD%2F2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL%2F2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL%2FwAARCAAYAE8DASIAAhEBAxEB%2F8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL%2F8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4%2BTl5ufo6erx8vP09fb3%2BPn6%2F8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL%2F8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3%2BPn6%2F9oADAMBAAIRAxEAPwD1PUdStNKtTc3kvlxjgcZJPoBWbpXi7S9Xufs0LSRzH7qyrjd9Oafr2gR641oZpzHFbuXZNuQ4%2Fp%2F9euWVItZ8cQNpkQS1s8b5UGFbb%2FnFeZOcovQ9vC4ehUpvmbvZvyVtr%2Bp1eseJ9N0RxHdSO0xGfLjXJx6ntU2ka7Ya3Ez2chJT7yOMMv4VxWpbdJ8cXF9qtvJNayjMb7Nw6DHXjjBFO8JyxTeKb%2B%2FtU8ixWNmIPAUHGP5E1KrS57G7wFP6vzq97Xv09DsNa8QWOhJEbsuWlPypGAT9evSm3viTTrLTLfUJHkaC4%2F1ZRck8ZrgdVuF10arqssihIsRWsbNzjIycfT%2BddhoUcM%2FgiFXVJAkDZDANg8%2FrTjVcpNImeCp0qMZyve6T%2Baua2k6xa61atcWhfarbWDjBBq%2FXG%2FDr%2FkD3P%2FXb%2FwBlFdlWlOTlFNnDjKUaVaUI7IKKKK0OY5vxgusT6fHbaXCzrKSJmQgMB6fjWJ4eGv6S0NqmjIIXkHmuThiO5znsKKK5ZfGerhKt8M4OKt8%2F8zoPFqanPpa2%2BmweY8zbXcEZRfUf40ukeG7aw0J9Pky%2FnqfOcHBYkf0oorblTlqc8684UOSO1zH1fwHZJpkz6fHK90ADGpk688%2FpmtXw9oZ0zw40BjKXM8ZMqls%2FMRgUUVCpxUtCpY2vVo2m76kXgnTLrTNLmju4jFI02QpPbAFdNRRWkVaKsY4qbqVZTluFFFFWcx%2F%2F2Q%3D%3D", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

JAVA调用代码

OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType,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8cXF9qtvJNayjMb7Nw6DHXjjBFO8JyxTeKb%2B%2FtU8ixWNmIPAUHGP5E1KrS57G7wFP6vzq97Xv09DsNa8QWOhJEbsuWlPypGAT9evSm3viTTrLTLfUJHkaC4%2F1ZRck8ZrgdVuF10arqssihIsRWsbNzjIycfT%2BddhoUcM%2FgiFXVJAkDZDANg8%2FrTjVcpNImeCp0qMZyve6T%2Baua2k6xa61atcWhfarbWDjBBq%2FXG%2FDr%2FkD3P%2FXb%2FwBlFdlWlOTlFNnDjKUaVaUI7IKKKK0OY5vxgusT6fHbaXCzrKSJmQgMB6fjWJ4eGv6S0NqmjIIXkHmuThiO5znsKKK5ZfGerhKt8M4OKt8%2F8zoPFqanPpa2%2BmweY8zbXcEZRfUf40ukeG7aw0J9Pky%2FnqfOcHBYkf0oorblTlqc8684UOSO1zH1fwHZJpkz6fHK90ADGpk688%2FpmtXw9oZ0zw40BjKXM8ZMqls%2FMRgUUVCpxUtCpY2vVo2m76kXgnTLrTNLmju4jFI02QpPbAFdNRRWkVaKsY4qbqVZTluFFFFWcx%2F%2F2Q%3D%3D");
Request request = new Request.Builder()
  .url("http://47.108.88.211:8082/ocr/base64")
  .post(body)
  .addHeader("content-type", "application/x-www-form-urlencoded")
  .build();

Response response = client.newCall(request).execute();

Python3调用代码

import http.client

conn = http.client.HTTPConnection("47.108.88.211:8082")

payload = "base64str=%2F9j%2F4AAQSkZJRgABAQEAYABgAAD%2F2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL%2F2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL%2FwAARCAAYAE8DASIAAhEBAxEB%2F8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL%2F8QAtRAAAgEDAwIEAwUFBAQAAAF9A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IIXkHmuThiO5znsKKK5ZfGerhKt8M4OKt8%2F8zoPFqanPpa2%2BmweY8zbXcEZRfUf40ukeG7aw0J9Pky%2FnqfOcHBYkf0oorblTlqc8684UOSO1zH1fwHZJpkz6fHK90ADGpk688%2FpmtXw9oZ0zw40BjKXM8ZMqls%2FMRgUUVCpxUtCpY2vVo2m76kXgnTLrTNLmju4jFI02QpPbAFdNRRWkVaKsY4qbqVZTluFFFFWcx%2F%2F2Q%3D%3D"

headers = {
    'content-type': "application/x-www-form-urlencoded"
    }

conn.request("POST", "/ocr/base64", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

posted @ 2023-02-20 17:14  天天代码码天天  阅读(503)  评论(0编辑  收藏  举报  来源