处理图像
Note: Some parts of this article may be in English. We apologize for the inconvenience and are working on adding the translation as soon as possible.
ABBYY FineReader Engine works with images by loading them into an FRDocument object, which represents the document being processed.
打开图像
请执行下列操作之一将图像载入文档:
- Use the CreateFRDocumentFromImage method of the Engine object to create an FRDocument object.
- Add images to an existing FRDocument object from a file. Use the AddImageFile, AddImageFileFromMemory, AddImageFileFromStream, AddImageFileWithPassword, or AddImageFileWithPasswordCallback method.
All these methods receive as a parameter the PrepareImageMode object, which allows you to specify different parameters of image preprocessing. Call the IEngine::CreatePrepareImageMode method to create this object, change its properties as necessary, and then pass it to one of the methods mentioned above.
You can also add an existing ImageDocument object (for example, one loaded from a file in internal format) using the AddImageDocument method of the FRDocument object.
ImageDocument 结构
Once loaded into the document, the image of each page can be accessed via the IFRPage::ImageDocument property. Each open image in ABBYY FineReader Engine is represented by an ImageDocument object. The ImageDocument stores the image in the so-called "internal format," which includes 4 image planes, represented by Image objects:
- 黑白 平面。为源图像的黑白副本。
- 灰色 平面。为源图像的灰色副本。如果源图像为黑白色,则该页面与黑白平面一样。
- 彩色 平面。这是源图像的彩色副本。如果源图像为黑白色,则该页面与黑白平面一样;如果为灰色,则该页面与灰色平面一样。
- 预览。用于在用户界面中显示预览图像的彩色小图像。The preview is created at the call to the GetPreviewImage or GetPreviewImageSpecificSize method. Any modification of the image, automatic or manual, may reset the created preview, and it will have to be created again.
The size and resolution of black-and-white, gray, and color images are the same. The preview image is usually smaller.
The images may be deskewed during image opening. To correlate the coordinates on the original image with the coordinates after opening or after additional modifications, use the CoordinatesConverter object. It stores the state of coordinates at the moment when it was obtained. You can use this object to convert the pixel coordinates between any two stages in the image processing. For example:
- Get this object using the IImageDocument::CoordinatesConverter property directly after image opening, during which image skew was corrected.
- After other modifications, obtain another instance of this object from the ImageDocument.
- Now you can convert pixel coordinates between the initially deskewed image plane and the modified image plane by applying the ConvertCoordinates method twice:
- Convert from the deskewed image plane to the original using the first instance of the CoordinatesConverter.
- Convert the result from the original image plane to the modified image plane using the second instance of the CoordinatesConverter.
The same method lets you convert pixel coordinates from one of the full-size image planes to the preview image plane and back. The coordinates of pixels on the black-and-white, gray, and color image planes are the same.
Important! An image modification, automatic or manual, may reset the preview image plane created earlier, and you will not be able to convert coordinates to or from that preview. Before converting coordinates, call the GetPreviewImage method again if the image was modified.
图像修改
Important! The automatic preprocessing mechanisms are best to prepare the image for OCR. The program determines image origin and document type, detects incorrect orientation, resolution, or image skew, and takes all this data into account to improve the image. We recommend that you only perform additional image modifications if after automatic preprocessing you are not satisfied with the result.
Modifications during image opening are managed by the PrepareImageMode object.
After opening, the image can be modified using:
- Methods of the ImageDocument object
- The ImageModification object, passed to the IImageDocument::Modify method
- Methods of the FRPage and FRDocument objects
图像保存
您可以使用 Image 对象的 WriteToFile 将当前图像平面按指定格式保存到图像文件中。
ABBYY FineReader Engine 也提供将多个图像保存入单个图像文件的功能。通过 MultipageImageWriter 对象:
- 通过 Engine 对象的 CreateMultipageImageWriter 方法创建 MultipageImageWriter 对象。
- 通过 MultipageImageWriter 对象的 AddPage 方法将图像添加到多页图像文件的末尾。每个添加的图像都呈现为单个页面。
- 在使用新创建的图像文件之前,必须释放 MultipageImageWriter 对象的所有引用。
请注意,虽然 ImageDocument 对象提供多种保存方法 (SaveTo,SaveToFile,SaveToMemory),但是这些方法不适用于将图像保存为外部格式的情况。这些方法将 ImageDocument 对象的内容保存为 ABBYY FineReader Engine 内部格式,任何外部程序无法对其进行查看。
另请参阅
11/7/2025 12:48:30 PM