!13750 Add check of ResizePreserveARWithFiller operation
From: @shenwei41 Reviewed-by: Signed-off-by:
This commit is contained in:
commit
b1b99b97d7
|
@ -1591,7 +1591,7 @@ bool GetPerspectiveTransform(std::vector<Point> src_point, std::vector<Point> ds
|
|||
return true;
|
||||
}
|
||||
|
||||
bool GetAffineTransformImpl(LiteMat src, LiteMat dst) {
|
||||
bool GetAffineTransformImpl(LiteMat &src, LiteMat &dst) {
|
||||
int m = src.height_;
|
||||
int n = dst.width_;
|
||||
for (int i = 0; i < m; i++) {
|
||||
|
@ -1603,6 +1603,8 @@ bool GetAffineTransformImpl(LiteMat src, LiteMat dst) {
|
|||
}
|
||||
|
||||
if (std::abs(src.ptr<double>(k)[i]) < DBL_EPSILON * 100) {
|
||||
double x[6] = {0};
|
||||
dst.Init(1, 6, x, LDataType(LDataType::DOUBLE));
|
||||
return false;
|
||||
}
|
||||
if (k != i) {
|
||||
|
@ -1669,7 +1671,7 @@ bool GetAffineTransform(std::vector<Point> src_point, std::vector<Point> dst_poi
|
|||
}
|
||||
|
||||
GetAffineTransformImpl(src1, src2);
|
||||
M.Init(3, 2, LDataType(LDataType::DOUBLE));
|
||||
M.Init(3, 2, 1, LDataType(LDataType::DOUBLE));
|
||||
for (int i = 0; i < M.height_; i++) {
|
||||
for (int j = 0; j < M.width_; j++) {
|
||||
M.ptr<double>(i)[j] = src2.ptr<double>(i * M.width_ + j)[0];
|
||||
|
@ -1942,6 +1944,12 @@ int ImageWarpAffineHWC(imageToolsImage_t image, imageToolsImage_t warped_image,
|
|||
|
||||
bool ResizePreserveARWithFiller(LiteMat &src, LiteMat &dst, int h, int w, float (*ratioShiftWShiftH)[3],
|
||||
float (*invM)[2][3], int img_orientation) {
|
||||
if (src.IsEmpty() || src.channel_ != 3 || h <= 0 || w <= 0 || h > 10000 || w > 10000) {
|
||||
return false;
|
||||
}
|
||||
if (ratioShiftWShiftH == nullptr || invM == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (dst.IsEmpty()) {
|
||||
dst.Init(w, h, src.channel_, LDataType::FLOAT32);
|
||||
}
|
||||
|
|
|
@ -1847,3 +1847,49 @@ TEST_F(MindDataImageProcess, testResizePreserveARWithFillerv) {
|
|||
cv::Mat dst_image(lite_mat_resize.height_, lite_mat_resize.width_, CV_32FC3, lite_mat_resize.data_ptr_);
|
||||
cv::imwrite("./mindspore_image.jpg", dst_image);
|
||||
}
|
||||
|
||||
TEST_F(MindDataImageProcess, testResizePreserveARWithFillervFail) {
|
||||
std::string filename = "data/dataset/apple.jpg";
|
||||
cv::Mat image = cv::imread(filename, cv::ImreadModes::IMREAD_COLOR);
|
||||
|
||||
// The input lite_mat_rgb object is null.
|
||||
LiteMat lite_mat_rgb;
|
||||
LiteMat lite_mat_resize;
|
||||
float ratioShiftWShiftH[3] = {0};
|
||||
float invM[2][3] = {{0, 0, 0}, {0, 0, 0}};
|
||||
int h = 1000;
|
||||
int w = 1000;
|
||||
bool ret = ResizePreserveARWithFiller(lite_mat_rgb, lite_mat_resize, h, w, &ratioShiftWShiftH, &invM, 0);
|
||||
ASSERT_TRUE(ret == false);
|
||||
|
||||
// The channel of input lite_mat_rgb object is not 3.
|
||||
LiteMat lite_mat_rgb1;
|
||||
lite_mat_rgb1.Init(image.cols, image.rows, 1, image.data, LDataType::UINT8);
|
||||
LiteMat lite_mat_resize1;
|
||||
float ratioShiftWShiftH1[3] = {0};
|
||||
float invM1[2][3] = {{0, 0, 0}, {0, 0, 0}};
|
||||
int h1 = 1000;
|
||||
int w1 = 1000;
|
||||
bool ret1 = ResizePreserveARWithFiller(lite_mat_rgb1, lite_mat_resize1, h1, w1, &ratioShiftWShiftH1, &invM1, 0);
|
||||
ASSERT_TRUE(ret1 == false);
|
||||
|
||||
// The ratioShiftWShiftH2 and invM2 is null.
|
||||
LiteMat lite_mat_rgb2;
|
||||
lite_mat_rgb2.Init(image.cols, image.rows, image.channels(), image.data, LDataType::UINT8);
|
||||
LiteMat lite_mat_resize2;
|
||||
int h2 = 1000;
|
||||
int w2 = 1000;
|
||||
bool ret2 = ResizePreserveARWithFiller(lite_mat_rgb2, lite_mat_resize2, h2, w2, nullptr, nullptr, 0);
|
||||
ASSERT_TRUE(ret2 == false);
|
||||
|
||||
// The width and height of the output image is less than or equal to 0.
|
||||
LiteMat lite_mat_rgb3;
|
||||
lite_mat_rgb3.Init(image.cols, image.rows, image.channels(), image.data, LDataType::UINT8);
|
||||
LiteMat lite_mat_resize3;
|
||||
float ratioShiftWShiftH3[3] = {0};
|
||||
float invM3[2][3] = {{0, 0, 0}, {0, 0, 0}};
|
||||
int h3 = -1000;
|
||||
int w3 = 1000;
|
||||
bool ret3 = ResizePreserveARWithFiller(lite_mat_rgb3, lite_mat_resize3, h3, w3, &ratioShiftWShiftH3, &invM3, 0);
|
||||
ASSERT_TRUE(ret3 == false);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue