diff --git a/opencv/CMakeLists.txt b/opencv/CMakeLists.txt index f15ae7b20f165c39d203c50aefaaf2adf296e074..fcc8a99c8e7f328802f636cf378f25ea3701409e 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 f36cf0880f8ee7ead51df16f44313d808e3d9d6e..ceca8046a817c45263394725e768f641db1c36b3 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 c728967016fa0857b440d8e616a30ebb1ecd5f6b..0a3e41c34bb5e22696f874395a035552185b0ef9 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 aa9e6ef1d800e3e84f38a9c928d0e49ec2402217..104c063251d0831c8f717b2d831d128ac50cc311 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");