/* This file is part of the CVD Library. Copyright (C) 2022 The Authors This library is free software, see LICENSE file for details */ #include "test_utility.h" #include #include #include #include #include namespace { using CVD::Testing::assert_equal; using CVD::Testing::assert_image_equal; using CVD::Testing::assert_vector_equal; using CVD::Testing::init; template TooN::Matrix ToTooN(const Eigen::Matrix& m) { if constexpr(Options & Eigen::RowMajor) { return TooN::Matrix(const_cast(m.data())); } else { return TooN::Matrix(const_cast(m.data())); } } } int main() { CVD::Image in = init({ { 1, 2 }, { 3, 4 } }); CVD::Image out({ 4, 4 }); Eigen::Matrix transformation; transformation << 0, -1, 2, 1, 0, 1; CVD::OpenCV::warpAffine(in, out, transformation, cv::INTER_NEAREST); assert_image_equal(init({ { 0, 0, 0, 0 }, { 0, 3, 1, 0 }, { 0, 4, 2, 0 }, { 0, 0, 0, 0 }, }), out); CVD::Image toon_out({ 4, 4 }); double values[6] = { 0, -1, 2, 1, 0, 1 }; TooN::Matrix<2, 3> toon_transform = ToTooN(transformation); CVD::OpenCV::warpAffine(in, toon_out, toon_transform, cv::INTER_NEAREST); assert_image_equal(init({ { 0, 0, 0, 0 }, { 0, 3, 1, 0 }, { 0, 4, 2, 0 }, { 0, 0, 0, 0 }, }), toon_out); CVD::Image mask = init({ { 0, 0, 0, 0, 0, 0 }, { 0, 0, 1, 1, 0, 0 }, { 0, 1, 1, 1, 1, 0 }, { 0, 1, 1, 1, 1, 0 }, { 0, 0, 1, 1, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, }); std::vector> contours; CVD::OpenCV::findContours(mask, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_NONE); assert_equal(static_cast(1), contours.size()); assert_vector_equal(std::vector { { 2, 1 }, { 1, 2 }, { 1, 3 }, { 2, 4 }, { 3, 4 }, { 4, 3 }, { 4, 2 }, { 3, 1 } }, contours[0]); std::vector>> toon_contours; CVD::OpenCV::findContours(mask, toon_contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_NONE); assert_equal(static_cast(1), toon_contours.size()); assert_vector_equal(std::vector> { TooN::makeVector(2, 1), TooN::makeVector(1, 2), TooN::makeVector(1, 3), TooN::makeVector(2, 4), TooN::makeVector(3, 4), TooN::makeVector(4, 3), TooN::makeVector(4, 2), TooN::makeVector(3, 1) }, toon_contours[0]); }