OpenCV-related Backends
Overview
The max()
of the input range for the following backends is all 1.
Name | Initialization Parameters | Input [Type] | Output [Type] | Remarks |
---|---|---|---|---|
DecodeMat | None | data[str/bytes] | result[cv::Mat] color[str] | |
cvtColorMat | color | data[cv::Mat] color[str] | result[cv::Mat] | |
ResizeMat | resize_h,resize_w | data[cv::Mat] | result[cv::Mat] | |
PillowResizeMat | resize_h,resize_w | data[cv::Mat] | result[cv::Mat] | CV_8UC3 |
ResizePadMat | max_h,max_w,pad_value | data[cv::Mat] | - result[cv::Mat] - inverse_trans [std::function<std::pair<float, float>(float x, float y)>] | CV_8UC3 |
Mat2Tensor | device=cpu,gpu | data[cv::Mat] | result[at::Tensor] | Mat2CpuTensor Mat2GpuTensor |
SaveMat | save_dir | data[cv::Mat] | result[cv::Mat] | |
AlignMat | align,resize_h,max_w | data[cv::Mat] | result[cv::Mat],resize_h[int],resize_w[int] | max()=UINT32_MAX |
DynamicResizeMat | data[cv::Mat],resize_h,resize_w[int] | result[cv::Mat] | ||
PerspectiveTransformMat | data[cv::Mat],TASK_BOX_KEY | result[cv::Mat] |
DecodeMat
- Calls OpenCV to decode an image into a
cv::Mat
using theIMREAD_COLOR
mode. The output image will be converted to a 3-channelBGR
image. - If the decoded image is empty, the output will have no
result
key. - The
color
is fixed as "bgr".
cvtColorMat
- The
color
parameter is the target color space during initialization, and the color space of the input data during processing. If they are different, a color space conversion will be performed, otherwise the input value will be returned. - The
color
parameter currently supports "rgb" and "bgr". - When performing a color space conversion, the input data must be three-channel data, otherwise an exception will be thrown.
ResizeMat
- Calls OpenCV to perform a resize operation using the default interpolation method.
resize_h
andresize_w
must be integers and within the valid range of [1, 1024 * 1024].
PillowResizeMat
- The input
cv::Mat
type must be CV_8UC3. resize_h
andresize_w
must be integers and within the valid range of [1, 1024 * 1024].- Strictly maintains consistency with the bilinear interpolation results of Pillow (verified on a large amount of data).
ResizePadMat
- Maintains aspect ratio during resize and pads with a constant
pad_value
aligned to the top left corner. - The input
cv::Mat
type must be CV_8UC3. max_h
andmax_w
must be integers and within the valid range of [1, 1024 * 1024].pad_value
supports integers.inverse_trans
: used to map new coordinates to original coordinates.
Mat2Tensor
- Convert
cv::Mat
toat::Tensor
while keeping the data type unchanged. - Output shape is 1chw.
- Data is deep copied.
- Similar to SyncTensor, it will synchronize with the current stream.
caution
Please insert stream management operations:
Sequential[Mat2Tensor,SyncTensor]
or SyncTensor[Mat2Tensor]
,
otherwise Mat2Tensor
will use the default cuda stream.
Mat2CpuTensor
- Convert
cv::Mat
toat::Tensor(cpu)
while keeping the data type unchanged. - Output shape is 1chw.
- Data is deep copied.
Mat2GpuTensor
- Convert
cv::Mat
toat::Tensor(gpu)
while keeping the data type unchanged. - Output shape is 1chw.
SaveMat
save_dir
: Directory to save the file, which needs to be created in advance.- The file name suffix is
.png
, and the name is unique.
AlignMat
Calculate the target length and width of the input image under the following conditions:
- Keep the aspect ratio basically the same.
- The target height is fixed to
resize_h
. - The target width is no greater than
max_w
. - The length and width are aligned with
align
.
Initialization
Parameters
- resize_h - Target length.
- max_w - Maximum width.
- align - default=32, the target length and width need to be multiples of this parameter.
Forward
Parameters
- data - Input data, needs to be of type
cv::Mat
. - result - Output,
result=data
. - resize_h - Output, target height.
- resize_w - Output, target width.
min()/max()
[1, UINT32_MAX]
DynamicResizeMat
Resize the target image according to the resize_h
and resize_w
provided by the forward input data.
PerspectiveTransformMat
Perform perspective transformation.
Forward
Parameters
- data - Input data, needs to be of type
cv::Mat
. - TASK_BOX_KEY - Original coordinates, type is
std::vector<std::vector<int>>
, external and internal lengths are 4 and 2 respectively, representing four points, and each point has two coordinate values. The order is [top-left, top-right, bottom-right, bottom-left]. - result - Output.