From 30ceaaf75eb415232408a03d139d73e9592f8744 Mon Sep 17 00:00:00 2001
From: Lucas Stauder <git@lucas-stauder.de>
Date: Tue, 4 Feb 2025 09:53:05 +0000
Subject: [PATCH] WiSe 2024/25

---
 opencv/CMakeLists.txt                         | 54 +++++++++++--------
 opencv/src/opencv_exercise.cpp                |  2 +-
 ...{opencv_exercise.h => opencv_exercise.hpp} |  0
 opencv/src/opencv_filter.test.cpp             | 19 ++++---
 opencv/src/opencv_hotpixel_grayscale.test.cpp | 23 ++++----
 5 files changed, 52 insertions(+), 46 deletions(-)
 rename opencv/src/{opencv_exercise.h => opencv_exercise.hpp} (100%)

diff --git a/opencv/CMakeLists.txt b/opencv/CMakeLists.txt
index f15ae7b..fcc8a99 100644
--- a/opencv/CMakeLists.txt
+++ b/opencv/CMakeLists.txt
@@ -3,43 +3,51 @@ project(Uebung7_opencv)
 
 set(CMAKE_CXX_STANDARD 14)
 IF (WIN32)
-	find_package( OpenCV REQUIRED PATHS "C:\\opencv\\")
+    find_package(OpenCV REQUIRED PATHS "C:\\opencv\\")
 ELSE()
-	find_package( OpenCV REQUIRED)
+    find_package(OpenCV REQUIRED)
 ENDIF()
 
-include_directories( ${OpenCV_INCLUDE_DIRS})
+include_directories(${OpenCV_INCLUDE_DIRS})
+
+add_executable(Uebung7_opencv
+        src/main.cpp
+        src/opencv_exercise.cpp
+        src/opencv_exercise.hpp
+)
+
+target_link_libraries(Uebung7_opencv ${OpenCV_LIBS})
 
 # Fetch Catch2
 Include(FetchContent)
 FetchContent_Declare(
-		Catch2
-		GIT_REPOSITORY https://github.com/catchorg/Catch2.git
-		GIT_TAG        v3.4.0
+        googletest
+        GIT_REPOSITORY https://github.com/google/googletest.git
+        GIT_TAG        v1.15.2
 )
-FetchContent_MakeAvailable(Catch2)
+
+set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
+FetchContent_MakeAvailable(googletest)
 enable_testing()
 
-add_executable(Uebung7_opencv
-		src/main.cpp
-        src/opencv_exercise.cpp
-        src/opencv_exercise.h
-)
+
 add_executable(test_opencv_hotpixel_grayscale
-		src/opencv_exercise.cpp
-		src/opencv_exercise.h
-		src/opencv_hotpixel_grayscale.test.cpp
+        src/opencv_exercise.cpp
+        src/opencv_exercise.hpp
+        src/opencv_hotpixel_grayscale.test.cpp
 )
 add_executable(test_opencv_filter
-		src/opencv_exercise.cpp
-		src/opencv_exercise.h
-		src/opencv_filter.test.cpp
+        src/opencv_exercise.cpp
+        src/opencv_exercise.hpp
+        src/opencv_filter.test.cpp
 )
 
-target_link_libraries(Uebung7_opencv ${OpenCV_LIBS})
-target_link_libraries(test_opencv_hotpixel_grayscale ${OpenCV_LIBS} Catch2::Catch2WithMain)
-target_link_libraries(test_opencv_filter ${OpenCV_LIBS} Catch2::Catch2WithMain)
+target_link_libraries(test_opencv_hotpixel_grayscale ${OpenCV_LIBS} GTest::gtest_main)
+target_link_libraries(test_opencv_filter ${OpenCV_LIBS} GTest::gtest_main)
 add_test(test_opencv_hotpixel_grayscale ./test_opencv_hotpixel_grayscale)
 add_test(test_opencv_filter ./test_opencv_filter)
-set_property(TEST test_opencv_hotpixel_grayscale PROPERTY ENVIRONMENT "CTEST_OUTPUT_ON_FAILURE=1")
-set_property(TEST test_opencv_filter PROPERTY ENVIRONMENT "CTEST_OUTPUT_ON_FAILURE=1")
+
+include(GoogleTest)
+
+gtest_discover_tests(test_opencv_hotpixel_grayscale)
+gtest_discover_tests(test_opencv_filter)
diff --git a/opencv/src/opencv_exercise.cpp b/opencv/src/opencv_exercise.cpp
index f36cf08..ceca804 100644
--- a/opencv/src/opencv_exercise.cpp
+++ b/opencv/src/opencv_exercise.cpp
@@ -1,4 +1,4 @@
-#include "opencv_exercise.h"
+#include "opencv_exercise.hpp"
 
 #include <iostream>
 
diff --git a/opencv/src/opencv_exercise.h b/opencv/src/opencv_exercise.hpp
similarity index 100%
rename from opencv/src/opencv_exercise.h
rename to opencv/src/opencv_exercise.hpp
diff --git a/opencv/src/opencv_filter.test.cpp b/opencv/src/opencv_filter.test.cpp
index c728967..0a3e41c 100644
--- a/opencv/src/opencv_filter.test.cpp
+++ b/opencv/src/opencv_filter.test.cpp
@@ -1,20 +1,19 @@
 #include <algorithm>
-#include <catch2/catch_test_macros.hpp>
-#include <catch2/matchers/catch_matchers_vector.hpp>
+#include <gtest/gtest.h>
 #include <opencv2/opencv.hpp>
 
-#include "opencv_exercise.h"
+#include "opencv_exercise.hpp"
 
 void compare_images(const cv::Mat& input, const cv::Mat& correct) {
-    REQUIRE(input.rows == correct.rows);
-    REQUIRE(input.cols == correct.cols);
-    REQUIRE(input.channels() == correct.channels());
-    REQUIRE(input.depth() == correct.depth());
+    ASSERT_EQ(input.rows, correct.rows);
+    ASSERT_EQ(input.cols, correct.cols);
+    ASSERT_EQ(input.channels(), correct.channels());
+    ASSERT_EQ(input.depth(), correct.depth());
 
-    REQUIRE(std::equal(input.begin<uint8_t>(), input.end<uint8_t>(), correct.begin<uint8_t>()));
+    ASSERT_TRUE(std::equal(input.begin<uint8_t>(), input.end<uint8_t>(), correct.begin<uint8_t>()));
 }
 
-TEST_CASE("blur") {
+TEST(OpenCVExerciseTest, Blur) {
     const cv::Mat img = cv::imread("../input/rover.jpg");
     const cv::Mat img_correct = cv::imread("../output/blur_correct.png");
     const cv::Mat result = gaussianBlur(img);
@@ -22,7 +21,7 @@ TEST_CASE("blur") {
     compare_images(result, img_correct);
 }
 
-TEST_CASE("border_detection") {
+TEST(OpenCVExerciseTest, BorderDetection) {
     const cv::Mat img = cv::imread("../input/rover.jpg");
     const cv::Mat img_correct = cv::imread("../output/border_correct.bmp");
     const cv::Mat result = borderDetect(img);
diff --git a/opencv/src/opencv_hotpixel_grayscale.test.cpp b/opencv/src/opencv_hotpixel_grayscale.test.cpp
index aa9e6ef..104c063 100644
--- a/opencv/src/opencv_hotpixel_grayscale.test.cpp
+++ b/opencv/src/opencv_hotpixel_grayscale.test.cpp
@@ -1,27 +1,26 @@
 #include <algorithm>
-#include <catch2/catch_test_macros.hpp>
-#include <catch2/matchers/catch_matchers_vector.hpp>
+#include <gtest/gtest.h>
 #include <opencv2/opencv.hpp>
 
-#include "opencv_exercise.h"
+#include "opencv_exercise.hpp"
 
 void compare_images(const cv::Mat& input, const cv::Mat& correct) {
-    REQUIRE(input.rows == correct.rows);
-    REQUIRE(input.cols == correct.cols);
-    REQUIRE(input.channels() == correct.channels());
-    REQUIRE(input.depth() == correct.depth());
+    ASSERT_EQ(input.rows, correct.rows);
+    ASSERT_EQ(input.cols, correct.cols);
+    ASSERT_EQ(input.channels(), correct.channels());
+    ASSERT_EQ(input.depth(), correct.depth());
 
-    REQUIRE(std::equal(input.begin<uint8_t>(), input.end<uint8_t>(), correct.begin<uint8_t>()));
+    ASSERT_TRUE(std::equal(input.begin<uint8_t>(), input.end<uint8_t>(), correct.begin<uint8_t>()));
 }
 
-TEST_CASE("find_hot_pixel") {
+TEST(OpenCVExerciseTest, FindHotPixel) {
     const cv::Mat img = cv::imread("../input/rover.jpg");
     const Point p = findHotPixel(img);
-    REQUIRE(p.x == 1284);
-    REQUIRE(p.y == 792);
+    ASSERT_EQ(p.x, 1284);
+    ASSERT_EQ(p.y, 792);
 }
 
-TEST_CASE("grayscale") {
+TEST(OpenCVExerciseTest, Grayscale) {
     const cv::Mat img = cv::imread("../input/rover.jpg");
     const cv::Mat original = img.clone();
     const cv::Mat img_correct = cv::imread("../output/grayscale_correct.png");
-- 
GitLab