So my “observation” was correct. there is information loss
I have implemented the changes to PNG, and it’s working as expected.
test_extract_object.cpp
:
bool is_mat_eq(image &im1, image &im2) {
cv::Mat diff;
cv::absdiff(im1, im2, diff);
bool eq = cv::countNonZero(diff) == 0;
return eq;
}
TEST_P(ExtractObjectFixture, ExtractsObjectCorrectly) {
ExtractObjectSample sample = GetParam();
auto imageUtils = this->getInjector()->get<ImageUtils *>();
std::optional<image> resultObject = imageUtils->extract_object(imageUtils->read(sample.mainImage));
ASSERT_TRUE(resultObject);
image object = *resultObject;
image sample_object = imageUtils->read(sample.object);
image fake_object = imageUtils->read(sample.fake_object);
EXPECT_EQ(object.rows, sample_object.rows);
EXPECT_EQ(object.cols, sample_object.cols);
bool eq = is_mat_eq(object, sample_object);
EXPECT_TRUE(eq);
eq = is_mat_eq(sample_object, fake_object);
EXPECT_FALSE(eq);
eq = is_mat_eq(object, fake_object);
EXPECT_FALSE(eq);
}