diff --git a/CMakeLists.txt b/CMakeLists.txt index 8921996..64ae5ee 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,7 +80,6 @@ find_package(Wayland REQUIRED COMPONENTS Client) find_package(PlasmaWaylandProtocols REQUIRED) find_package(LayerShellQt REQUIRED) find_package(KPipeWire) -find_package(OpenCV REQUIRED core imgproc) set_package_properties(KPipeWire PROPERTIES DESCRIPTION "Used to record pipewire streams into a file" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 66fda75..2565192 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -89,11 +89,6 @@ ki18n_wrap_ui(spectacle Gui/SettingsDialog/VideoSaveOptions.ui ) -# Needed to compile with OpenCV -target_compile_options (spectacle PRIVATE -fexceptions) - -target_include_directories(spectacle PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ${OpenCV_INCLUDE_DIRS}) - target_link_libraries(spectacle PRIVATE Qt::Concurrent Qt::DBus @@ -121,7 +116,6 @@ target_link_libraries(spectacle PRIVATE K::KPipeWireRecord Wayland::Client LayerShellQt::Interface - ${OpenCV_LIBRARIES} ) set_source_files_properties(Gui/QmlUtils.qml PROPERTIES diff --git a/src/QtCV.h b/src/QtCV.h deleted file mode 100755 index 2b87599..0000000 --- a/src/QtCV.h +++ /dev/null @@ -1,95 +0,0 @@ -/* SPDX-FileCopyrightText: 2024 Noah Davis - * SPDX-License-Identifier: LGPL-2.0-or-later - */ - -#pragma once - -#include -#include - -/** - * Convenience functions for using OpenCV with Qt APIs. - */ -namespace QtCV -{ -static constexpr int INVALID_MAT_TYPE = -1; -static_assert(CV_8U == 0); -static_assert(std::same_as); - -inline constexpr int matType(QPixelFormat::TypeInterpretation typeInterpretation) -{ - switch (typeInterpretation) { - case QPixelFormat::UnsignedByte: - return CV_8U; - case QPixelFormat::UnsignedShort: - return CV_16U; - case QPixelFormat::FloatingPoint: - return CV_32F; - default: - return INVALID_MAT_TYPE; - } -} - -inline constexpr int matType(QPixelFormat pixelFormat) -{ - const auto baseType = matType(pixelFormat.typeInterpretation()); - if (baseType == INVALID_MAT_TYPE) { - return INVALID_MAT_TYPE; - } - return CV_MAKETYPE(baseType, pixelFormat.channelCount()); -} - -// Get a cv::Mat that reuses the data of a QImage. -// Use cv::Mat::clone() if the owner of the data might be destroyed before you're done using it. -// Expects an image with the right format. If the image has an ARGB32 format (premultiplied or not), -// it needs to be converted to BGRA. RGBX8888 and RGBA8888 formats shouldn't need to be converted. -inline cv::Mat qImageToMat(QImage &image) -{ - const auto type = matType(image.pixelFormat()); - if (type == INVALID_MAT_TYPE) { - return {}; - } - // Use the constructor with cv::Size as the first arg to avoid type ambiguity in the args. - return cv::Mat(cv::Size{image.width(), image.height()}, type, image.bits(), image.bytesPerLine()); -} - -// Same as qImageToMat, but with cv::Ptr (subclass of std::shared_ptr). -inline cv::Ptr qImageToMatPtr(QImage &image) -{ - const auto type = matType(image.pixelFormat()); - if (type == INVALID_MAT_TYPE) { - return nullptr; - } - return cv::makePtr(cv::Size{image.width(), image.height()}, type, image.bits(), image.bytesPerLine()); -} - -// For use with filters that require odd kernel dimensions. -template -inline auto sigmaToKSize(Number value) -{ - return cvRound(value + 1) | 1; -} - -// Stack blur looks like Gaussian blur, but doesn't become as slow with larger kernel sizes. -// Stack blur is unavailable in OpenCV versions before 4.7. -// We need this because of the FreeBSD 14 CI pipeline. FreeBSD 14 is only on OpenCV 4.6. -inline void stackOrGaussianBlurCompatibility(cv::InputArray &in, cv::OutputArray &out, cv::Size ksize, double sigmaX, double sigmaY = 0, [[maybe_unused]] int borderType = cv::BORDER_DEFAULT) -{ -#if CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7) - // Replicate the behavior of cv::GaussianBlur with automatic kernel size. - const auto gaussianKSizeFactor = (in.depth() == CV_8U ? 3 : 4) * 2; - if( ksize.width <= 0 && sigmaX > 0 ) { - ksize.width = sigmaToKSize(sigmaX * gaussianKSizeFactor); - } - if( ksize.height <= 0 && sigmaY > 0 ) { - ksize.height = sigmaToKSize(sigmaY * gaussianKSizeFactor); - } - cv::stackBlur(in, out, ksize); -#else - cv::GaussianBlur(in, out, ksize, sigmaX, sigmaY, borderType); -#endif -} -} - - -