From a423e71540342e677b39b5f9e5f2ac5be0a741dc Mon Sep 17 00:00:00 2001 From: Kang Lin Date: Tue, 15 Aug 2023 11:06:15 +0800 Subject: [PATCH] CMake: Use std c++ 11 or 17 --- .github/workflows/ubuntu.yml | 1 + CMakeLists.txt | 31 +++-- Src/CMakeLists.txt | 50 ++++---- Src/CameraQtCaptureVideoFrame.h | 204 ++++++++++++++++---------------- 4 files changed, 142 insertions(+), 144 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 5f6ed1d..3520312 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -60,6 +60,7 @@ jobs: libqt6svg6-dev qt6-l10n-tools qt6-translations-l10n \ qt6-scxml-dev qt6-multimedia-dev libqt6serialport6-dev \ qt6-webengine-dev qt6-webengine-dev-tools \ + libqt6core5compat6-dev \ libutf8proc-dev libpam0g-dev \ libxkbcommon-dev libxkbcommon-x11-dev xorg-dev libx11-xcb-dev \ libx11-dev libxfixes-dev \ diff --git a/CMakeLists.txt b/CMakeLists.txt index 03d80be..8cf1f77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,6 @@ project(FaceRecognizer) SET(CMAKE_INCLUDE_CURRENT_DIR ON) SET(CMAKE_VERBOSE_MAKEFILE ON) -set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) @@ -43,6 +42,9 @@ if(ANDROID AND (Qt${QT_VERSION_MAJOR}_VERSION VERSION_LESS 6.0.0)) endif() if(QT_VERSION_MAJOR GREATER_EQUAL 6) LIST(APPEND QT_COMPONENTS MultimediaWidgets Core5Compat) + set(CMAKE_CXX_STANDARD 17) +else() + set(CMAKE_CXX_STANDARD 11) endif() find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${QT_COMPONENTS}) message("QT_VERSION:${Qt${QT_VERSION_MAJOR}_VERSION}") @@ -67,13 +69,10 @@ IF(MSVC) add_compile_options("$<$:/utf-8>") add_compile_options("$<$:/utf-8>") ENDIF(MSVC) -IF(MINGW) - add_compile_options("-std=c++0x") -ENDIF() IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - add_compile_options(-std=c++0x -Wno-sign-compare -Wno-unused-parameter) + add_compile_options(-Wno-sign-compare -Wno-unused-parameter) if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") add_compile_options(-g -ggdb) @@ -139,21 +138,21 @@ if(NOT RabbitCommon_DIR) endif() endif() if(RabbitCommon_DIR AND EXISTS ${RabbitCommon_DIR}/Src) - message("Use RabbitCommon source code") + message(STATUS "Use RabbitCommon source code") add_subdirectory(${RabbitCommon_DIR}/Src ${CMAKE_BINARY_DIR}/RabbitCommon) else() find_package(RabbitCommon) if(NOT RabbitCommon_FOUND) - message("RabbitCommon_DIR is not found. Please use one of the following ways to set it:") - message("1. Set RabbitCommon_DIR to the install prefix of RabbitCommon.") - message("2. Set RabbitCommon_DIR to source code root of RabbitCommon.") - message("2.1 Please download the source code of RabbitCommon from https://github.com/KangLin/RabbitCommon") - message(" ag:") - message(" git clone https://github.com/KangLin/RabbitCommon.git") - message("2.2 Then set cmake variable or environment variable RabbitCommon_DIR to download root directory.") - message(" ag:") - message(" cmake -DRabbitCommon_DIR= ") - message(FATAL_ERROR "RabbitCommon_DIR isn't set.") + message(FATAL_ERROR + "RabbitCommon_DIR is not found. Please use one of the following ways to set it:\n" + "1. Set RabbitCommon_DIR to the install prefix of RabbitCommon.\n" + "2. Set RabbitCommon_DIR to source code root of RabbitCommon.\n" + "2.1 Please download the source code of RabbitCommon from https://github.com/KangLin/RabbitCommon\n" + " ag:\n" + " git clone https://github.com/KangLin/RabbitCommon.git\n" + "2.2 Then set cmake variable or environment variable RabbitCommon_DIR to download root directory.\n" + " ag:\n" + " cmake -DRabbitCommon_DIR=") endif() endif() diff --git a/Src/CMakeLists.txt b/Src/CMakeLists.txt index be54c84..8895c3c 100644 --- a/Src/CMakeLists.txt +++ b/Src/CMakeLists.txt @@ -10,31 +10,7 @@ endif() project(FaceRecognizer) -OPTION(BUILD_PERFORMANCE "Set to ON to build performance)." OFF) -if(BUILD_PERFORMANCE) - set(LIBS_DEFINES ${LIBS_DEFINES} BUILD_PERFORMANCE) - set(SOURCE_FILES ${SOURCE_FILES} Performance.cpp) -endif() - -option(USE_YUV "Use libyuv" ON) -if(USE_YUV) - #Use: https://github.com/KangLin/libyuv - find_package(YUV) - if(YUV_FOUND) - set(LIBS_DEFINES ${LIBS_DEFINES} HAVE_LIBYUV) - set(LIBS ${LIBS} YUV) -# if(ANDROID) -# INSTALL(FILES $ -# DESTINATION "libs/${ANDROID_ABI}") -# else() -# INSTALL(FILES $ -# DESTINATION "${CMAKE_INSTALL_BINDIR}") -# endif() - endif() -endif(USE_YUV) - set(SOURCE_FILES - ${SOURCE_FILES} CameraQtCaptureVideoFrame.cpp ImageTool.cpp ConverFormat.cpp @@ -49,7 +25,6 @@ set(SOURCE_FILES database/Database.cpp database/DataRegister.cpp database/TableRegister.cpp - Performance.cpp ) set(INSTALLHEADER_FILES @@ -75,6 +50,29 @@ set(HEADER_FILES database/TableRegister.h ) +OPTION(BUILD_PERFORMANCE "Set to ON to build performance)." OFF) +if(BUILD_PERFORMANCE) + set(LIBS_DEFINES ${LIBS_DEFINES} BUILD_PERFORMANCE) + list(APPEND SOURCE_FILES Performance.cpp) +endif() + +option(USE_YUV "Use libyuv" ON) +if(USE_YUV) + #Use: https://github.com/KangLin/libyuv + find_package(YUV) + if(YUV_FOUND) + set(LIBS_DEFINES ${LIBS_DEFINES} HAVE_LIBYUV) + set(LIBS ${LIBS} YUV) +# if(ANDROID) +# INSTALL(FILES $ +# DESTINATION "libs/${ANDROID_ABI}") +# else() +# INSTALL(FILES $ +# DESTINATION "${CMAKE_INSTALL_BINDIR}") +# endif() + endif() +endif(USE_YUV) + string(TOLOWER ${CMAKE_BUILD_TYPE} BUILD_TYPE) if(BUILD_TYPE STREQUAL "debug") set(LIBS_DEFINES ${LIBS_DEFINES} DEBUG) @@ -98,7 +96,7 @@ ADD_TARGET(NAME ${PROJECT_NAME} PRIVATE_DEFINITIONS FaceRecognizer_VERSION="${FaceRecognizer_VERSION}" FaceRecognizer_REVISION="${FaceRecognizer_REVISION}" - DEFINITIONS RABBITCOMMON ${LIBS_DEFINES} BUILD_PERFORMANCE + DEFINITIONS RABBITCOMMON ${LIBS_DEFINES} SOURCE_FILES ${SOURCE_FILES} ${HEADER_FILES} ${RCC_FILES} INSTALL_HEADER_FILES "${INSTALLHEADER_FILES}" OPTIONS ${FACERECOGNIZER_OPTIONS} diff --git a/Src/CameraQtCaptureVideoFrame.h b/Src/CameraQtCaptureVideoFrame.h index 32a53e4..499bf51 100644 --- a/Src/CameraQtCaptureVideoFrame.h +++ b/Src/CameraQtCaptureVideoFrame.h @@ -1,102 +1,102 @@ -/* - * 作者:康林 (Email: kl222@126.com) - * - * 从摄像头(QCarmera)或者(Player)中捕获视频帧。 - * 注意:android后景摄像头捕获的视频翻转-90度,前景摄像头翻转90度。 - * 用法: - * QCamera m_Camera; - * m_Camera.setCaptureMode(QCamera::CaptureVideo); - * CCaptureVideoFrame videoFrame; - * videoFrame.setSource(&m_Camera); - * 注册SLOT: - * connect(&videoFrame, SIGNAL(sigCaptureFrame(const QVideoFrame&)), - * SLOT(CaptureVideoFrame(const QVideoFrame&))); - * 在SLOT 中 CaptureVideoFrame(const QVideoFrame&) 处理捕获到的视频帧。 - * - * 示例代码: - * QList device = QCamera::availableDevices(); - * QList::iterator it; - * for(it = device.begin(); it != device.end(); it++) - * { - * qDebug("Camera:%s", qPrintable(QCamera::deviceDescription(*it))); - * } - * - * QCamera camera(QCamera::availableDevices().at(1)); - * camera.setCaptureMode(QCamera::CaptureVideo); - * CFrmPlayer player; - * CCaptureVideoFrame captureVideoFrame; - * if(captureVideoFrame.setSource(&camera)) - * { - * qDebug("probe.setSource is ok"); - * player.connect(&captureVideoFrame, SIGNAL(CaptureFrame(QVideoFrame)), - * SLOT(present(QVideoFrame))); - * } - * - * player.show(); - * player.activateWindow(); - * camera.start(); - */ - -#ifndef CAPTUREVIDEOFRAME_H -#define CAPTUREVIDEOFRAME_H -#include - -#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0) - #include -#else - #include -#endif -#ifdef ANDROID - #include -#endif -#include -#include -#include - -#include "facerecognizer_export.h" - -/** - * @brief The CCameraQtCaptureVideoFrame class - * @ingroup RABBITIM_IMPLEMENT_CAMERA_QT - */ -class FACERECOGNIZER_EXPORT CCameraQtCaptureVideoFrame -#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0) - : public QVideoSink -#else - : public QAbstractVideoSurface -#endif -{ - Q_OBJECT - Q_CLASSINFO("Author", "Kang Lin ") - -public: - explicit CCameraQtCaptureVideoFrame(QObject *parent = nullptr); - virtual ~CCameraQtCaptureVideoFrame(); - -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - //设置支持的捕获格式 - virtual QList supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const; - - virtual bool present(const QVideoFrame &frame); -#else -public Q_SLOTS: - void present(const QVideoFrame &frame); -#endif - - int SetCameraAngle(int angle); - -signals: - //从摄像头捕获的原始帧 - void sigCaptureFrame(const QVideoFrame &frame); - void sigCaptureFrame(const QImage &frame); - -private: -#ifdef ANDROID - QVideoProbe m_Probe;//android下,目前只能用probe捕获视频 -#endif - - int m_Angle; -}; - -#endif // CAPTUREVIDEOFRAME_H +/* + * 作者:康林 (Email: kl222@126.com) + * + * 从摄像头(QCarmera)或者(Player)中捕获视频帧。 + * 注意:android后景摄像头捕获的视频翻转-90度,前景摄像头翻转90度。 + * 用法: + * QCamera m_Camera; + * m_Camera.setCaptureMode(QCamera::CaptureVideo); + * CCaptureVideoFrame videoFrame; + * videoFrame.setSource(&m_Camera); + * 注册SLOT: + * connect(&videoFrame, SIGNAL(sigCaptureFrame(const QVideoFrame&)), + * SLOT(CaptureVideoFrame(const QVideoFrame&))); + * 在SLOT 中 CaptureVideoFrame(const QVideoFrame&) 处理捕获到的视频帧。 + * + * 示例代码: + * QList device = QCamera::availableDevices(); + * QList::iterator it; + * for(it = device.begin(); it != device.end(); it++) + * { + * qDebug("Camera:%s", qPrintable(QCamera::deviceDescription(*it))); + * } + * + * QCamera camera(QCamera::availableDevices().at(1)); + * camera.setCaptureMode(QCamera::CaptureVideo); + * CFrmPlayer player; + * CCaptureVideoFrame captureVideoFrame; + * if(captureVideoFrame.setSource(&camera)) + * { + * qDebug("probe.setSource is ok"); + * player.connect(&captureVideoFrame, SIGNAL(CaptureFrame(QVideoFrame)), + * SLOT(present(QVideoFrame))); + * } + * + * player.show(); + * player.activateWindow(); + * camera.start(); + */ + +#ifndef CAPTUREVIDEOFRAME_H +#define CAPTUREVIDEOFRAME_H +#include + +#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0) + #include +#else + #include +#endif +#ifdef ANDROID + #include +#endif +#include +#include +#include + +#include "facerecognizer_export.h" + +/** + * @brief The CCameraQtCaptureVideoFrame class + * @ingroup RABBITIM_IMPLEMENT_CAMERA_QT + */ +class FACERECOGNIZER_EXPORT CCameraQtCaptureVideoFrame +#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0) + : public QVideoSink +#else + : public QAbstractVideoSurface +#endif +{ + Q_OBJECT + Q_CLASSINFO("Author", "Kang Lin ") + +public: + explicit CCameraQtCaptureVideoFrame(QObject *parent = nullptr); + virtual ~CCameraQtCaptureVideoFrame(); + +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + //设置支持的捕获格式 + virtual QList supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const; + + virtual bool present(const QVideoFrame &frame); +#else +public Q_SLOTS: + void present(const QVideoFrame &frame); +#endif + + int SetCameraAngle(int angle); + +signals: + //从摄像头捕获的原始帧 + void sigCaptureFrame(const QVideoFrame &frame); + void sigCaptureFrame(const QImage &frame); + +private: +#ifdef ANDROID + QVideoProbe m_Probe;//android下,目前只能用probe捕获视频 +#endif + + int m_Angle; +}; + +#endif // CAPTUREVIDEOFRAME_H