diff --git a/modules/core/src/cpu_hal_imgproc.cpp b/modules/core/src/cpu_hal_imgproc.cpp index 920fa4b8..d7d6e619 100644 --- a/modules/core/src/cpu_hal_imgproc.cpp +++ b/modules/core/src/cpu_hal_imgproc.cpp @@ -2121,11 +2121,11 @@ struct CenterCropStruct ECVL_ERROR_WRONG_PARAMS("Malformed src image") } - vector v_start(channels, 0); + vector v_start(src.dims_.size(), 0); v_start[x_pos] = offset_w; v_start[y_pos] = offset_h; - vector v_size(channels, -1); + vector v_size(src.dims_.size(), -1); v_size[x_pos] = new_width; v_size[y_pos] = new_height; v_size[c_pos] = channels; diff --git a/modules/core/test/test_imgproc.cpp b/modules/core/test/test_imgproc.cpp index e9683f3a..454e00f8 100644 --- a/modules/core/test/test_imgproc.cpp +++ b/modules/core/test/test_imgproc.cpp @@ -11,6 +11,8 @@ * All rights reserved. */ +#include + #include #include @@ -729,7 +731,28 @@ TEST_F(Imgproc, Normalize##type) \ EXPECT_TRUE(out_v({ 1,0,2 }) == saturate_cast>((rgb2_##type##_v({ 1,0,2 }) - mean) / std)); \ EXPECT_TRUE(out_v({ 0,1,2 }) == saturate_cast>((rgb2_##type##_v({ 0,1,2 }) - mean) / std)); \ EXPECT_TRUE(out_v({ 1,1,2 }) == saturate_cast>((rgb2_##type##_v({ 1,1,2 }) - mean) / std)); \ -} +} \ +\ +TEST_F(Imgproc, CenterCrop##type) \ +{ \ + std::vector size { 1,1 }; \ + CenterCrop(g1_##type, out, size); \ + View out_v(out); \ + EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \ + EXPECT_THAT(out.dims_, testing::ElementsAre(1, 1, 1)); \ + \ + CenterCrop(g2_##type, out, size); \ + out_v = out; \ + EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \ + EXPECT_THAT(out.dims_, testing::ElementsAre(1, 1, 1)); \ + \ + CenterCrop(rgb2_##type, out, size); \ + out_v = out; \ + EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \ + EXPECT_TRUE(out_v({ 0,0,1 }) == 50); \ + EXPECT_TRUE(out_v({ 0,0,2 }) == 50); \ + EXPECT_THAT(out.dims_, testing::ElementsAre(1, 1, 3)); \ +} #include "ecvl/core/datatype_existing_tuples.inc.h" #undef ECVL_TUPLE