Package com.itextpdf.pdfocr.onnx.util
Class OpenCvUtil
java.lang.Object
com.itextpdf.pdfocr.onnx.util.OpenCvUtil
Static class with OpenCV utility functions.
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.bytedeco.opencv.opencv_core.MatbinarizeMdArray(FloatBufferMdArray hwMdArray, float threshold) Takes a two-dimensional MD-array and returns a binarized version of it as an OpenCV Mat.static voidfillPolyAtOffset(org.bytedeco.opencv.opencv_core.Mat bitmap, org.bytedeco.opencv.opencv_core.Mat poly, org.bytedeco.opencv.opencv_core.Scalar color, int xOffset, int yOffset) Fill the polygon on the bitmap at a specific offset.static org.bytedeco.opencv.opencv_core.MatminAreaRectBoxPoints(org.bytedeco.opencv.opencv_core.Mat points) Equivalent to calling OpenCVminAreaRect, followed byboxPoints, but with resource handling taken care of.static org.bytedeco.opencv.opencv_core.MatminAreaRectBoxPoly(org.bytedeco.opencv.opencv_core.Mat points) Creates an OpenCV polygon, based on the results of aminAreaRectBoxPoints(points)call, but with resource handling taken care of.static org.bytedeco.opencv.opencv_core.RotatedRectnormalizedMinAreaRect(org.bytedeco.opencv.opencv_core.Mat points) OpenCV minAreaRect, but returns the normalized rectangle immediately.static org.bytedeco.opencv.opencv_core.RotatedRectnormalizeRotatedRect(org.bytedeco.opencv.opencv_core.RotatedRect rect) Normalizes RotatedRect, so that its angle is in the [-45; 45) range.
-
Method Details
-
binarizeMdArray
public static org.bytedeco.opencv.opencv_core.Mat binarizeMdArray(FloatBufferMdArray hwMdArray, float threshold) Takes a two-dimensional MD-array and returns a binarized version of it as an OpenCV Mat.- Parameters:
-
hwMdArray- MD-array to binarize -
threshold- Threshold for a value to be 0xFF instead of 0x00 - Returns:
- binarized version of the MD-array as an OpenCV Mat
-
normalizedMinAreaRect
public static org.bytedeco.opencv.opencv_core.RotatedRect normalizedMinAreaRect(org.bytedeco.opencv.opencv_core.Mat points) OpenCV minAreaRect, but returns the normalized rectangle immediately. Equivalent tonormalizeRotatedRect(opencv_imgproc.minAreaRect(x)).- Parameters:
-
points- vector of 2D points - Returns:
- normalized min area rect
-
normalizeRotatedRect
public static org.bytedeco.opencv.opencv_core.RotatedRect normalizeRotatedRect(org.bytedeco.opencv.opencv_core.RotatedRect rect) Normalizes RotatedRect, so that its angle is in the [-45; 45) range.We want our boxes to have the point order, so that it matches input image orientation. Otherwise, the orientation detection model will get a different box, which is already pre-rotated in some way. Here we will alter the rectangle, so that points would output the expected order.
This will make box have points in the following order, relative to the page: BL, TL, TR, BR. Bottom as in bottom of the image, not the lowest Y coordinate.
- Parameters:
-
rect- RotatedRect to normalize - Returns:
- normalized RotatedRect
-
minAreaRectBoxPoints
public static org.bytedeco.opencv.opencv_core.Mat minAreaRectBoxPoints(org.bytedeco.opencv.opencv_core.Mat points) Equivalent to calling OpenCVminAreaRect, followed byboxPoints, but with resource handling taken care of.- Parameters:
-
points- points to get the rectangle for - Returns:
- min area rectangle points
-
minAreaRectBoxPoly
public static org.bytedeco.opencv.opencv_core.Mat minAreaRectBoxPoly(org.bytedeco.opencv.opencv_core.Mat points) Creates an OpenCV polygon, based on the results of aminAreaRectBoxPoints(points)call, but with resource handling taken care of.- Parameters:
-
points- points to get the rectangle for - Returns:
- min area rectangle polygon
-
fillPolyAtOffset
public static void fillPolyAtOffset(org.bytedeco.opencv.opencv_core.Mat bitmap, org.bytedeco.opencv.opencv_core.Mat poly, org.bytedeco.opencv.opencv_core.Scalar color, int xOffset, int yOffset) Fill the polygon on the bitmap at a specific offset.- Parameters:
-
bitmap- bitmap to fill the polygon on -
poly- polygon to fill -
color- color to fill the polygon with -
xOffset- x offset for the polygon -
yOffset- y offset for the polygon
-