From c3999605ba6f7308ef51690e7e22ccb40dbc5407 Mon Sep 17 00:00:00 2001 From: Ethan Fahnestock Date: Tue, 10 Dec 2024 11:43:37 -0500 Subject: [PATCH] reformat image compare into video directory --- common/BUILD | 11 -------- common/video/BUILD | 21 ++++++++++++++ common/{video.cc => video/image_compare.cc} | 4 +-- common/{video.hh => video/image_compare.hh} | 2 +- common/video/image_compare_test.cc | 31 +++++++++++++++++++++ 5 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 common/video/BUILD rename common/{video.cc => video/image_compare.cc} (81%) rename common/{video.hh => video/image_compare.hh} (76%) create mode 100644 common/video/image_compare_test.cc diff --git a/common/BUILD b/common/BUILD index db426109..096ee465 100644 --- a/common/BUILD +++ b/common/BUILD @@ -105,15 +105,4 @@ cc_test( "@bs_thread_pool", "@com_google_googletest//:gtest_main", ], -) - -cc_library( - name = "video", - hdrs = ["video.hh"], - srcs = ["video.cc"], - deps = [ - "@eigen", - "@opencv", - ], - visibility = ["//visibility:public"] ) \ No newline at end of file diff --git a/common/video/BUILD b/common/video/BUILD new file mode 100644 index 00000000..8696c6ba --- /dev/null +++ b/common/video/BUILD @@ -0,0 +1,21 @@ +package(features=["warning_compile_flags"]) + +cc_library( + name = "image_compare", + hdrs = ["image_compare.hh"], + srcs = ["image_compare.cc"], + deps = [ + "@eigen//:eigen", + "@opencv", + ], + visibility = ["//visibility:public"], +) + +cc_test( + name = "image_compare_test", + srcs = ["image_compare_test.cc"], + deps = [ + ":image_compare", + "@com_google_googletest//:gtest_main", + ] +) diff --git a/common/video.cc b/common/video/image_compare.cc similarity index 81% rename from common/video.cc rename to common/video/image_compare.cc index 79be9f9f..145befb6 100644 --- a/common/video.cc +++ b/common/video/image_compare.cc @@ -1,6 +1,6 @@ #include "opencv2/opencv.hpp" -namespace robot::common { +namespace robot::common::video { bool images_equal(const cv::Mat& img1, const cv::Mat& img2) { if (img1.size() != img2.size() || img1.type() != img2.type()) { @@ -12,4 +12,4 @@ bool images_equal(const cv::Mat& img1, const cv::Mat& img2) { return cv::countNonZero(diff) == 0; } -} // namespace robot::common +} // namespace robot::common::video diff --git a/common/video.hh b/common/video/image_compare.hh similarity index 76% rename from common/video.hh rename to common/video/image_compare.hh index 4661059d..c9d56195 100644 --- a/common/video.hh +++ b/common/video/image_compare.hh @@ -2,7 +2,7 @@ #include "opencv2/opencv.hpp" -namespace robot::common { +namespace robot::common::video { bool images_equal(const cv::Mat& img1, const cv::Mat& img2); diff --git a/common/video/image_compare_test.cc b/common/video/image_compare_test.cc new file mode 100644 index 00000000..434e94a6 --- /dev/null +++ b/common/video/image_compare_test.cc @@ -0,0 +1,31 @@ +#include "common/video/image_compare.hh" +#include "opencv2/opencv.hpp" +#include + +namespace robot::common::video { + +TEST(ImageCompareTest, ImagesEqual_SameImages) { + cv::Mat img1 = cv::Mat::zeros(100, 100, CV_8UC3); + cv::Mat img2 = img1.clone(); + EXPECT_TRUE(images_equal(img1, img2)); +} + +TEST(ImageCompareTest, ImagesEqual_DifferentSizes) { + cv::Mat img1 = cv::Mat::zeros(100, 100, CV_8UC3); + cv::Mat img2 = cv::Mat::zeros(200, 200, CV_8UC3); + EXPECT_FALSE(images_equal(img1, img2)); +} + +TEST(ImageCompareTest, ImagesEqual_DifferentTypes) { + cv::Mat img1 = cv::Mat::zeros(100, 100, CV_8UC3); + cv::Mat img2 = cv::Mat::zeros(100, 100, CV_8UC1); + EXPECT_FALSE(images_equal(img1, img2)); +} + +TEST(ImageCompareTest, ImagesEqual_DifferentContent) { + cv::Mat img1 = cv::Mat::zeros(100, 100, CV_8UC3); + cv::Mat img2 = cv::Mat::ones(100, 100, CV_8UC3); + EXPECT_FALSE(images_equal(img1, img2)); +} + +} // namespace robot::common::video \ No newline at end of file