From e8e6043ae9d7e967f74bd9e77b20e3680e73ea69 Mon Sep 17 00:00:00 2001 From: Ethan Fahnestock Date: Mon, 9 Dec 2024 16:55:11 -0500 Subject: [PATCH] adding video common --- common/BUILD | 11 +++++++++++ common/video.cc | 15 +++++++++++++++ common/video.hh | 9 +++++++++ 3 files changed, 35 insertions(+) create mode 100644 common/video.cc create mode 100644 common/video.hh diff --git a/common/BUILD b/common/BUILD index 9d2bf3da..412a2f52 100644 --- a/common/BUILD +++ b/common/BUILD @@ -78,3 +78,14 @@ cc_test( "@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.cc b/common/video.cc new file mode 100644 index 00000000..19cd6709 --- /dev/null +++ b/common/video.cc @@ -0,0 +1,15 @@ +#include "opencv2/opencv.hpp" + +namespace robot::common { + +bool images_equal(const cv::Mat& img1, const cv::Mat& img2) { + if (img1.size() != img2.size() || img1.type() != img2.type()) { + return false; + } + cv::Mat diff; + cv::absdiff(img1, img2, diff); + diff = diff.reshape(1); + return cv::countNonZero(diff) == 0; +} + +} diff --git a/common/video.hh b/common/video.hh new file mode 100644 index 00000000..369f1a42 --- /dev/null +++ b/common/video.hh @@ -0,0 +1,9 @@ +#pragma once + +#include "opencv2/opencv.hpp" + +namespace robot::common { + +bool images_equal(const cv::Mat& img1, const cv::Mat& img2); + +} \ No newline at end of file