Fixed build with OpenCV4

This commit is contained in:
matlabbe 2019-06-17 11:43:26 -04:00
parent 5047163c09
commit 413cb6820d
5 changed files with 46 additions and 6 deletions

View File

@ -55,6 +55,21 @@ ADD_DEFINITIONS(-DPROJECT_NAME="${PROJECT_NAME}")
####### DEPENDENCIES #######
FIND_PACKAGE(OpenCV REQUIRED) # tested on 2.3.1
IF(OpenCV_VERSION_MAJOR EQUAL 4)
IF(NOT MSVC)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
IF(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
ELSEIF(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
ELSE()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
ENDIF()
ENDIF(NOT MSVC)
ENDIF(OpenCV_VERSION_MAJOR EQUAL 4)
# look for Qt5 before Qt4
FIND_PACKAGE(Qt5 COMPONENTS Widgets Core Gui Network QUIET)
IF(NOT Qt5_FOUND)
@ -66,10 +81,19 @@ FIND_PACKAGE(Tcmalloc QUIET)
FIND_PACKAGE(ZLIB REQUIRED QUIET)
SET(NONFREE 0)
IF(OPENCV_NONFREE_FOUND OR OPENCV_XFEATURES2D_FOUND)
SET(NONFREE 1)
ENDIF(OPENCV_NONFREE_FOUND OR OPENCV_XFEATURES2D_FOUND)
SET(NONFREE 1)
IF(NOT (OPENCV_NONFREE_FOUND OR OPENCV_XFEATURES2D_FOUND))
SET(NONFREE 0)
ELSEIF(OpenCV_VERSION VERSION_GREATER "3.4.2")
FIND_FILE(OpenCV_MODULES_HPP opencv2/opencv_modules.hpp
PATHS ${OpenCV_INCLUDE_DIRS}
NO_DEFAULT_PATH)
FILE(READ ${OpenCV_MODULES_HPP} TMPTXT)
STRING(FIND "${TMPTXT}" "#define OPENCV_ENABLE_NONFREE" matchres)
IF(${matchres} EQUAL -1)
SET(NONFREE 0)
ENDIF(${matchres} EQUAL -1)
ENDIF()
CONFIGURE_FILE(Version.h.in ${PROJECT_SOURCE_DIR}/include/${PROJECT_PREFIX}/Version.h)
@ -257,9 +281,9 @@ IF(NOT CATKIN_BUILD)
ENDIF()
ELSE()
IF(OPENCV_XFEATURES2D_FOUND)
MESSAGE(STATUS " With OpenCV 3 xfeatures2d module (SIFT/SURF/BRIEF/FREAK) = YES")
MESSAGE(STATUS " With OpenCV ${OpenCV_VERSION_MAJOR} xfeatures2d module (SIFT/SURF/BRIEF/FREAK) = YES")
ELSE()
MESSAGE(STATUS " With OpenCV 3 xfeatures2d module (SIFT/SURF/BRIEF/FREAK) = NO (not found)")
MESSAGE(STATUS " With OpenCV ${OpenCV_VERSION_MAJOR} xfeatures2d module (SIFT/SURF/BRIEF/FREAK) = NO (not found)")
ENDIF()
ENDIF()

View File

@ -44,6 +44,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc_c.h>
namespace find_object {

View File

@ -32,6 +32,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdio.h>
#include <opencv2/imgproc/imgproc.hpp>
#if CV_MAJOR_VERSION > 3
#include <opencv2/videoio/videoio_c.h>
#endif
#include <QtCore/QFile>
#include "utilite/UDirectory.h"
#include "CameraTcpServer.h"

View File

@ -42,6 +42,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QGraphicsRectItem>
#include <stdio.h>
#if CV_MAJOR_VERSION > 3
#include <opencv2/core/types_c.h>
#endif
namespace find_object {
FindObject::FindObject(bool keepImagesInRAM, QObject * parent) :

View File

@ -817,7 +817,11 @@ Feature2D * Settings::createKeypointDetector()
getFeature2D_ORB_edgeThreshold(),
getFeature2D_ORB_firstLevel(),
getFeature2D_ORB_WTA_K(),
#if CV_MAJOR_VERSION > 3
(cv::ORB::ScoreType)getFeature2D_ORB_scoreType(),
#else
getFeature2D_ORB_scoreType(),
#endif
getFeature2D_ORB_patchSize(),
getFeature2D_Fast_threshold()));
#endif
@ -1061,7 +1065,11 @@ Feature2D * Settings::createDescriptorExtractor()
getFeature2D_ORB_edgeThreshold(),
getFeature2D_ORB_firstLevel(),
getFeature2D_ORB_WTA_K(),
#if CV_MAJOR_VERSION > 3
(cv::ORB::ScoreType)getFeature2D_ORB_scoreType(),
#else
getFeature2D_ORB_scoreType(),
#endif
getFeature2D_ORB_patchSize(),
getFeature2D_Fast_threshold()));
#endif