-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding video common (correct this time) (#351)
- Loading branch information
1 parent
580fe60
commit 616f187
Showing
5 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,4 +105,4 @@ cc_test( | |
"@bs_thread_pool", | ||
"@com_google_googletest//:gtest_main", | ||
], | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "opencv2/opencv.hpp" | ||
|
||
namespace robot::common::video { | ||
|
||
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; | ||
} | ||
|
||
} // namespace robot::common::video |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
#include "opencv2/opencv.hpp" | ||
|
||
namespace robot::common::video { | ||
|
||
bool images_equal(const cv::Mat& img1, const cv::Mat& img2); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "common/video/image_compare.hh" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "opencv2/opencv.hpp" | ||
|
||
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 |