C# actual combat: Realize enterprise certificate identification and data extraction practice based on Tencent OCR technology

1. Introduction to OCR technology

In today's digital age, OCR (Optical Character Recognition) recognition technology is playing an increasingly important role. OCR technology realizes the digital processing and information extraction of a large number of paper documents by converting the text in the image into an editable text form. The common aspects include the identification of enterprise qualification certificates to the automatic identification of various documents such as ID cards and passports. OCR technology is playing a very important role in paperless office in all walks of life.

2. The working process of OCR technology

The principle of OCR (Optical Character Recognition) technology is to convert the text in the image into an editable text form. The following are the basic principle steps of OCR technology:

Image preprocessing: Preprocessing the input image. This includes removing noise from the image, adjusting the brightness and contrast of the image, and binarizing the image to separate text areas from background areas.

Text detection: In the preprocessed image, a text detection algorithm is used to identify the position and bounding box of the text. Commonly used text detection algorithms include methods based on edge detection, region growing, and template matching.

Character segmentation: For the detected text area, each character needs to be segmented for separate processing. Character segmentation algorithms can be processed based on features such as spacing, connectivity, and pixel density between characters.

Feature extraction: For each character, its features need to be extracted for comparison and matching with known characters. Commonly used feature extraction methods include feature descriptions based on shape, texture, projection, etc.

Character recognition: Recognize each character by comparing the extracted character features with a pre-trained model. Commonly used character recognition methods include template-based matching, statistical models (such as hidden Markov models), and deep learning models (such as convolutional neural networks).

Post-processing: After character recognition, some post-processing steps can be performed to improve the accuracy of the recognition results. This includes correcting errors, removing redundant characters, correcting text orientation, and more.

3. Introduction to Tencent Cloud Text Recognition

Tencent Cloud Optical Character Recognition (OCR) is based on the industry's cutting-edge deep learning technology, which intelligently recognizes the text content on the picture into editable text. It supports printed and handwritten text recognition in multiple scenarios such as general text, card text, bills, and specific scenes. It also supports bill verification and provides customized services, which can effectively replace manual information entry.

Tencent Cloud text recognition supports the integration of multiple development languages, rich cases, and strong interface stability, which is very easy for developers to quickly integrate text recognition needs.

4. Features of Tencent Cloud Text Recognition Function

Multiple recognition capabilities : Tencent Cloud character recognition service supports multiple character recognition capabilities, including general character recognition, ID card recognition, bank card recognition, license plate recognition, business card recognition, handwriting recognition, etc. These capabilities can meet the needs of text recognition in different scenarios.

High-precision recognition : Tencent Cloud's text recognition service is based on deep learning technology and has high text recognition accuracy. It recognizes text content in images and provides editable text results for subsequent processing and analysis.

Multi-language support : Tencent Cloud text recognition service supports text recognition in multiple common languages, including Chinese, English, Chinese and English, Japanese, Korean, Spanish, French, German, Portuguese, Vietnamese, Malay, Russian, Italian, Dutch, Swedish, Finnish, Danish, Norwegian, Hungarian, Thai, Arabic 20 languages. This makes it applicable to text recognition tasks in different language environments.

Image format support : Tencent Cloud text recognition service supports a variety of common image formats, including JPEG, PNG, BMP, etc. This makes it possible to process image files in different formats, which is convenient for developers to perform text recognition operations.

Easy-to-use API interface : Tencent Cloud Text Recognition Service provides an easy-to-use API interface. Developers only need to request and analyze according to the documentation to realize the text recognition function. This allows developers to quickly integrate and use the service.

Scalability and stability : As a cloud service of Tencent Cloud, the text recognition service has good scalability and stability. It can elastically expand capacity according to actual needs, and provide high availability and reliability service guarantee.

5. Integration case

Today, the editor will introduce to you the Tencent Cloud OCR service and realize the rapid identification function of enterprise qualification certificates through C# code.

5.1 Activate service

You need to log in to your Tencent Cloud account, and you can use WeChat to scan the QR code to log in. Then enter the OCR home page of Tencent Cloud.

OCR homepage: https://cloud.tencent.com/product/ocr

Click the Use Now button to enter the activation service page

Then we click to activate the service, wait for the activation to complete, and enter the management console.

After the service is activated, enter the OCR API debugging page, and you can test to confirm whether the service is normal

address:

https://console.cloud.tencent.com/api/explorer?Product=ocr&Version=2018-11-19&Action=BizLicenseOC

The figure below shows that interface calls are normal. On the right side, you can see the supported mainstream development languages ​​such as: Java, Net, PHP, Python, C++, Golang.

5.2 Apply for a personal key

Then apply for a personal API key, which is a necessary link for system integration services.

address:

https://console.cloud.tencent.com/cam/capi

You can click to create a new key, and after the creation is successful, the effect is shown in the following figure:

5.3 Code Integration

The Net method is used here for integration. First, use VS2019 to create a Net console application.

After the creation is complete, refer to the dependency package of the Tencent Cloud OCR service, here directly use nuget to search and install directly.

Method: Open the nuget package manager, enter "TencentCloudSDK.Ocr" to search, and click Install.

After the installation is successful, write the program.cs code, the complete code is as follows:

Here we use the url method to identify the enterprise qualification certificate.

using System;
using System.Threading.Tasks;
using TencentCloud.Common;
using TencentCloud.Common.Profile;
using TencentCloud.Ocr.V20181119;
using TencentCloud.Ocr.V20181119.Models;
namespace EnterpriseRecognition
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
                // 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305
                // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
                Credential cred = new Credential
                {
                    SecretId = "你的SecretId",
                    SecretKey = "你的SecretKey"
                };
                // 实例化一个client选项,可选的,没有特殊需求可以跳过
                ClientProfile clientProfile = new ClientProfile();
                // 实例化一个http选项,可选的,没有特殊需求可以跳过
                HttpProfile httpProfile = new HttpProfile();
                httpProfile.Endpoint = ("ocr.tencentcloudapi.com");
                clientProfile.HttpProfile = httpProfile;

                // 实例化要请求产品的client对象,clientProfile是可选的
                OcrClient client = new OcrClient(cred, "ap-beijing", clientProfile);
                // 实例化一个请求对象,每个接口都会对应一个request对象
                BizLicenseOCRRequest req = new BizLicenseOCRRequest();
                req.ImageUrl = "https://p8.itc.cn/q_70/images03/20201121/bfa9d2cace6740fb9ace776250d6cd0a.jpeg";

                // 返回的resp是一个BizLicenseOCRResponse的实例,与请求对象对应
                BizLicenseOCRResponse resp = client.BizLicenseOCRSync(req);
                // 输出json格式的字符串回包
                Console.WriteLine(AbstractModel.ToJsonString(resp));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            Console.Read();
        }
    }
}

The solution is as follows:

To find a picture of a business license, we can obtain the address of the picture through a web search:

Run the code as shown below:

The formatting effect is as follows:

{
    "RegNum":"",
    "Name":"大连长山渔港水产有限公司",
    "Capital":"",
    "Person":"王黎明",
    "Address":"辽宁省大连市长海县小长山岛镇房 身村盐场屯",
    "Business":"许可项目:食品生产,食品经营(依法须经批准的项目,经相关部门批准后方可开展经营活动,具体经营项目以审 批结果为准)一般项目;水产品批发,水产品收购,水产品零售(除依法须经批准的项目外,凭营业执照依法自主开展经营活动)",
    "Type":"有 限责任公司(法人独资)",
    "Period":"2020年11月20日至长期",
    "ComposingForm":"",
    "SetDate":"2020年11月20日",
    "RecognizeWarnCode":[

    ],
    "RecognizeWarnMsg":[

    ],
    "IsDuplication":-1,
    "RegistrationDate":"",
    "RequestId":"3b68eaff-5c51-4f3a-b592-34d7b14bc45b"
}

Based on the transfer data obtained, we can process the corresponding business. Here is only a function demonstration, and the function only does this step.

6. Summary

Tencent Cloud text recognition service is a high-performance, high-accuracy text recognition service that can be widely used in various text recognition scenarios, such as image OCR, ID card recognition, bank card recognition, etc. It provides an easy-to-use API interface for developers to quickly integrate and use. It is recommended for friends who need text recognition!

Tencent Cloud OCR Technology Helps Enterprise Certificate Identification and Data Extraction Practice

추천

출처blog.csdn.net/xishining/article/details/132542431