Location>code7788 >text

Simplify Text Processing, Universal Text Recognition Helps Improve Information Collection Efficiency

Popularity:710 ℃/2024-08-15 10:08:30

With the development of information technology, the popularity of the use of mobile devices and the globalization of business needs, the demand for unstructured data to be converted into structured data is growing, and digitization has become the mainstream trend of information storage and management. In this context, OCR technology came into being, which can convert text information in images into character information that can be used by computers and other devices, and has become a key technology for modern information processing.

OCR technology enriches the text processing capability of mobile devices, automates document processing, reduces manual input, provides users with diverse and convenient services, dramatically improves efficiency, and becomes an indispensable feature in apps. Users can convert documents to electronic text by simple scanning, take photos to get timely foreign language translation, automatically extract document information to simplify the verification process, etc.

HarmonyOS SDK Basic Visual Services(Core Vision Kit) providesuniversal character recognition (UCR)The ability supports text recognition in scenes such as text tilt within a specific angle range, shooting angle tilt, complex lighting conditions, and complex text backgrounds. It currently supports the recognition of 10+ languages such as Chinese and English.

Applicable Scenarios

Suitable for image and text recognition of bills, cards, forms, newspapers, books and so on.

Support text detection and recognition for document flipping and street view flipping.

It can be integrated into other applications to extend text detection and recognition functions, and provide translation and search services based on the recognition results.

development step

1. When using General Text Recognition, add the class related to the implementation of text recognition to the project.

import { textRecognition } from '@';

2. Obtain image resources through the gallery, and convert the images intoPixelMap

private async selectImage() {
  let uri = await ();
  if (uri === undefined) {
    (0x0000, 'OCRDemo', "Failed to get uri.");
    return;
  }
  (uri);
}

private openPhoto(): Promise<string> {
  return new Promise<string>((resolve, reject) => {
    let photoPicker = new ();
    ({
      MIMEType: .IMAGE_TYPE,
      maxSelectNumber: 1
    }).then((res: ) => {
      resolve([0]);
    }).catch((err: BusinessError) => {
      (0x0000, 'OCRDemo', `Failed to get photo image uri. code:${},message:${}`);
      resolve('');
    })
  })
}

private loadImage(name: string) {
  setTimeout(async () => {
    let imageSource:  | undefined = undefined;
    let fileSource = await (name, .READ_ONLY);
    imageSource = ();
     = await ();
  }, 100)
}

3. InstantiationVisionInfoobject and pass in the PixelMap of the image to be detected.

VisionInfo is the entry to be recognized by OCR detection, and currently only supports PixelMap type of visual information.

let visionInfo:  = {
  pixelMap: 
};

4. Configure generic text recognition configuration itemsTextRecognitionConfiguration, which is used to configure whether orientation detection is supported.

let textConfiguration:  = {
  isDirectionDetectionSupported: false
};

5. Call textRecognition'srecognizeTextinterface to process the recognized results.

When the call succeeds, the result code 0 is returned; when the call fails, the corresponding error code will be returned.

recognizeText interface provides three types of calls, the current one as an example, the other way can refer to theAPI documentation

(visionInfo, textConfiguration, (error: BusinessError, data: ) => {
  if ( !== 0) {
    (0x0000, 'OCRDemo', `Failed to recognize text. Code: ${}, message: ${}`);
    return;
  }
  // Recognition success,Get the corresponding result
  let recognitionString = (data);
  (0x0000, 'OCRDemo', `Succeeded in recognizing text:${recognitionString}`);

  // Update the results to theTextdisplayed in
   = ;

  if( && ) {
    ();
    ();
  }
});

Learn more >>

interviewsBasic Visual Services Alliance Official Website

gainUniversal Text Recognition Service Development Guidance Document