Skip to content

Commit

Permalink
reformat image compare into video directory
Browse files Browse the repository at this point in the history
  • Loading branch information
efahnestock committed Dec 10, 2024
1 parent 3b208fa commit c399960
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 14 deletions.
11 changes: 0 additions & 11 deletions common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)
21 changes: 21 additions & 0 deletions common/video/BUILD
Original file line number Diff line number Diff line change
@@ -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",
]
)
4 changes: 2 additions & 2 deletions common/video.cc → common/video/image_compare.cc
Original file line number Diff line number Diff line change
@@ -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()) {
Expand All @@ -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
2 changes: 1 addition & 1 deletion common/video.hh → common/video/image_compare.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
31 changes: 31 additions & 0 deletions common/video/image_compare_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "common/video/image_compare.hh"
#include "opencv2/opencv.hpp"
#include <gtest/gtest.h>

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

0 comments on commit c399960

Please sign in to comment.