Package com.itextpdf.pdfocr.onnxtr.util
Class BufferedImageUtil
java.lang.Object
com.itextpdf.pdfocr.onnxtr.util.BufferedImageUtil
Additional algorithms for working with
BufferedImage
.
-
Method Summary
Modifier and TypeMethodDescriptionstatic List<BufferedImage>
extractBoxes
(BufferedImage image, Collection boxes) Extracts sub-images from an image, based on provided rotated 4-point boxes.static BufferedImage
rotate
(BufferedImage image, TextOrientation orientation) Rotates image based on text orientation.static FloatBufferMdArray
toBchwInput
(Collection<BufferedImage> images, OnnxInputProperties properties) Converts a collection of images to a batched ML model input in a BCHW format with 3 channels.
-
Method Details
-
toBchwInput
public static FloatBufferMdArray toBchwInput(Collection<BufferedImage> images, OnnxInputProperties properties) Converts a collection of images to a batched ML model input in a BCHW format with 3 channels. This does aspect-preserving image resizing to fit the input shape.- Parameters:
-
images
- collection of images to convert to model input -
properties
- model input properties - Returns:
- batched BCHW model input MD-array
-
rotate
Rotates image based on text orientation. If no rotation necessary, same image is returned.- Parameters:
-
image
- image to rotate -
orientation
- text orientation used to rotate the image - Returns:
- new rotated image, or same image, if no rotation is required
-
extractBoxes
Extracts sub-images from an image, based on provided rotated 4-point boxes. Sub-images are transformed to fit the whole image without (in our use cases it is just rotation).- Parameters:
-
image
- original image to be used for extraction -
boxes
- list of 4-point boxes. Points should be in the following order: BL, TL, TR, BR - Returns:
- list of extracted image boxes
-