Skip to content
Snippets Groups Projects
Commit 30ceaaf7 authored by Stauder, Lucas's avatar Stauder, Lucas
Browse files

WiSe 2024/25

parent 8168258c
Branches master
No related tags found
No related merge requests found
...@@ -10,36 +10,44 @@ ENDIF() ...@@ -10,36 +10,44 @@ 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 # Fetch Catch2
Include(FetchContent) Include(FetchContent)
FetchContent_Declare( FetchContent_Declare(
Catch2 googletest
GIT_REPOSITORY https://github.com/catchorg/Catch2.git GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v3.4.0 GIT_TAG v1.15.2
) )
FetchContent_MakeAvailable(Catch2)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
enable_testing() enable_testing()
add_executable(Uebung7_opencv
src/main.cpp
src/opencv_exercise.cpp
src/opencv_exercise.h
)
add_executable(test_opencv_hotpixel_grayscale add_executable(test_opencv_hotpixel_grayscale
src/opencv_exercise.cpp src/opencv_exercise.cpp
src/opencv_exercise.h src/opencv_exercise.hpp
src/opencv_hotpixel_grayscale.test.cpp src/opencv_hotpixel_grayscale.test.cpp
) )
add_executable(test_opencv_filter add_executable(test_opencv_filter
src/opencv_exercise.cpp src/opencv_exercise.cpp
src/opencv_exercise.h src/opencv_exercise.hpp
src/opencv_filter.test.cpp src/opencv_filter.test.cpp
) )
target_link_libraries(Uebung7_opencv ${OpenCV_LIBS}) target_link_libraries(test_opencv_hotpixel_grayscale ${OpenCV_LIBS} GTest::gtest_main)
target_link_libraries(test_opencv_hotpixel_grayscale ${OpenCV_LIBS} Catch2::Catch2WithMain) target_link_libraries(test_opencv_filter ${OpenCV_LIBS} GTest::gtest_main)
target_link_libraries(test_opencv_filter ${OpenCV_LIBS} Catch2::Catch2WithMain)
add_test(test_opencv_hotpixel_grayscale ./test_opencv_hotpixel_grayscale) add_test(test_opencv_hotpixel_grayscale ./test_opencv_hotpixel_grayscale)
add_test(test_opencv_filter ./test_opencv_filter) 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)
#include "opencv_exercise.h" #include "opencv_exercise.hpp"
#include <iostream> #include <iostream>
......
File moved
#include <algorithm> #include <algorithm>
#include <catch2/catch_test_macros.hpp> #include <gtest/gtest.h>
#include <catch2/matchers/catch_matchers_vector.hpp>
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include "opencv_exercise.h" #include "opencv_exercise.hpp"
void compare_images(const cv::Mat& input, const cv::Mat& correct) { void compare_images(const cv::Mat& input, const cv::Mat& correct) {
REQUIRE(input.rows == correct.rows); ASSERT_EQ(input.rows, correct.rows);
REQUIRE(input.cols == correct.cols); ASSERT_EQ(input.cols, correct.cols);
REQUIRE(input.channels() == correct.channels()); ASSERT_EQ(input.channels(), correct.channels());
REQUIRE(input.depth() == correct.depth()); 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 = cv::imread("../input/rover.jpg");
const cv::Mat img_correct = cv::imread("../output/blur_correct.png"); const cv::Mat img_correct = cv::imread("../output/blur_correct.png");
const cv::Mat result = gaussianBlur(img); const cv::Mat result = gaussianBlur(img);
...@@ -22,7 +21,7 @@ TEST_CASE("blur") { ...@@ -22,7 +21,7 @@ TEST_CASE("blur") {
compare_images(result, img_correct); 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 = cv::imread("../input/rover.jpg");
const cv::Mat img_correct = cv::imread("../output/border_correct.bmp"); const cv::Mat img_correct = cv::imread("../output/border_correct.bmp");
const cv::Mat result = borderDetect(img); const cv::Mat result = borderDetect(img);
......
#include <algorithm> #include <algorithm>
#include <catch2/catch_test_macros.hpp> #include <gtest/gtest.h>
#include <catch2/matchers/catch_matchers_vector.hpp>
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include "opencv_exercise.h" #include "opencv_exercise.hpp"
void compare_images(const cv::Mat& input, const cv::Mat& correct) { void compare_images(const cv::Mat& input, const cv::Mat& correct) {
REQUIRE(input.rows == correct.rows); ASSERT_EQ(input.rows, correct.rows);
REQUIRE(input.cols == correct.cols); ASSERT_EQ(input.cols, correct.cols);
REQUIRE(input.channels() == correct.channels()); ASSERT_EQ(input.channels(), correct.channels());
REQUIRE(input.depth() == correct.depth()); 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 cv::Mat img = cv::imread("../input/rover.jpg");
const Point p = findHotPixel(img); const Point p = findHotPixel(img);
REQUIRE(p.x == 1284); ASSERT_EQ(p.x, 1284);
REQUIRE(p.y == 792); ASSERT_EQ(p.y, 792);
} }
TEST_CASE("grayscale") { TEST(OpenCVExerciseTest, Grayscale) {
const cv::Mat img = cv::imread("../input/rover.jpg"); const cv::Mat img = cv::imread("../input/rover.jpg");
const cv::Mat original = img.clone(); const cv::Mat original = img.clone();
const cv::Mat img_correct = cv::imread("../output/grayscale_correct.png"); const cv::Mat img_correct = cv::imread("../output/grayscale_correct.png");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment