Skip to content

Commit

Permalink
CMake: Use std c++ 11 or 17
Browse files Browse the repository at this point in the history
  • Loading branch information
KangLin committed Aug 15, 2023
1 parent a31fa0e commit a423e71
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 144 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
31 changes: 15 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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}")
Expand All @@ -67,13 +69,10 @@ IF(MSVC)
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/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)
Expand Down Expand Up @@ -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()

Expand Down
50 changes: 24 additions & 26 deletions Src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_FILE:YUV>
# DESTINATION "libs/${ANDROID_ABI}")
# else()
# INSTALL(FILES $<TARGET_FILE:YUV>
# DESTINATION "${CMAKE_INSTALL_BINDIR}")
# endif()
endif()
endif(USE_YUV)

set(SOURCE_FILES
${SOURCE_FILES}
CameraQtCaptureVideoFrame.cpp
ImageTool.cpp
ConverFormat.cpp
Expand All @@ -49,7 +25,6 @@ set(SOURCE_FILES
database/Database.cpp
database/DataRegister.cpp
database/TableRegister.cpp
Performance.cpp
)

set(INSTALLHEADER_FILES
Expand All @@ -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 $<TARGET_FILE:YUV>
# DESTINATION "libs/${ANDROID_ABI}")
# else()
# INSTALL(FILES $<TARGET_FILE:YUV>
# 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)
Expand All @@ -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}
Expand Down
204 changes: 102 additions & 102 deletions Src/CameraQtCaptureVideoFrame.h
Original file line number Diff line number Diff line change
@@ -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<QByteArray> device = QCamera::availableDevices();
* QList<QByteArray>::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 <QtGlobal>

#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
#include <QVideoSink>
#else
#include <QAbstractVideoSurface>
#endif
#ifdef ANDROID
#include <QVideoProbe>
#endif
#include <QCamera>
#include <QImage>
#include <QMetaClassInfo>

#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 <kl222@126.com>")

public:
explicit CCameraQtCaptureVideoFrame(QObject *parent = nullptr);
virtual ~CCameraQtCaptureVideoFrame();

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
//设置支持的捕获格式
virtual QList<QVideoFrame::PixelFormat> 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<QByteArray> device = QCamera::availableDevices();
* QList<QByteArray>::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 <QtGlobal>

#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
#include <QVideoSink>
#else
#include <QAbstractVideoSurface>
#endif
#ifdef ANDROID
#include <QVideoProbe>
#endif
#include <QCamera>
#include <QImage>
#include <QMetaClassInfo>

#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 <kl222@126.com>")

public:
explicit CCameraQtCaptureVideoFrame(QObject *parent = nullptr);
virtual ~CCameraQtCaptureVideoFrame();

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
//设置支持的捕获格式
virtual QList<QVideoFrame::PixelFormat> 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

0 comments on commit a423e71

Please sign in to comment.