Skip to content

Commit

Permalink
Add CenterCrop tests and fix a bug 🔧
Browse files Browse the repository at this point in the history
  • Loading branch information
MicheleCancilla committed Feb 25, 2021
1 parent f808dc4 commit 3d13580
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions modules/core/src/cpu_hal_imgproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2121,11 +2121,11 @@ struct CenterCropStruct
ECVL_ERROR_WRONG_PARAMS("Malformed src image")
}

vector<int> v_start(channels, 0);
vector<int> v_start(src.dims_.size(), 0);
v_start[x_pos] = offset_w;
v_start[y_pos] = offset_h;

vector<int> v_size(channels, -1);
vector<int> v_size(src.dims_.size(), -1);
v_size[x_pos] = new_width;
v_size[y_pos] = new_height;
v_size[c_pos] = channels;
Expand Down
25 changes: 24 additions & 1 deletion modules/core/test/test_imgproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* All rights reserved.
*/

#include <vector>

#include <gmock/gmock.h>
#include <gtest/gtest.h>

Expand Down Expand Up @@ -729,7 +731,28 @@ TEST_F(Imgproc, Normalize##type) \
EXPECT_TRUE(out_v({ 1,0,2 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 1,0,2 }) - mean) / std)); \
EXPECT_TRUE(out_v({ 0,1,2 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 0,1,2 }) - mean) / std)); \
EXPECT_TRUE(out_v({ 1,1,2 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 1,1,2 }) - mean) / std)); \
}
} \
\
TEST_F(Imgproc, CenterCrop##type) \
{ \
std::vector<int> size { 1,1 }; \
CenterCrop(g1_##type, out, size); \
View<DataType::type> 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
Expand Down

0 comments on commit 3d13580

Please sign in to comment.