Update opencv macros

This commit is contained in:
John Zhao 2018-11-05 11:27:28 +08:00
parent d6cb89bc04
commit 66ce5c8ad0
7 changed files with 38 additions and 16 deletions

View File

@ -15,14 +15,25 @@
include(${CMAKE_CURRENT_LIST_DIR}/IncludeGuard.cmake) include(${CMAKE_CURRENT_LIST_DIR}/IncludeGuard.cmake)
cmake_include_guard() cmake_include_guard()
find_package(OpenCV REQUIRED) if(OpenCV_FIND_QUIET)
message(STATUS "Found OpenCV: ${OpenCV_VERSION}") find_package(OpenCV QUIET)
if(OpenCV_VERSION VERSION_LESS 3.0)
add_definitions(-DUSE_OPENCV2)
elseif(OpenCV_VERSION VERSION_LESS 4.0)
add_definitions(-DUSE_OPENCV3)
else() else()
add_definitions(-DUSE_OPENCV4) find_package(OpenCV REQUIRED)
endif()
if(OpenCV_FOUND)
#message(STATUS "Found OpenCV: ${OpenCV_VERSION}")
set(WITH_OPENCV TRUE)
add_definitions(-DWITH_OPENCV)
if(OpenCV_VERSION VERSION_LESS 3.0)
add_definitions(-DWITH_OPENCV2)
elseif(OpenCV_VERSION VERSION_LESS 4.0)
add_definitions(-DWITH_OPENCV3)
else()
add_definitions(-DWITH_OPENCV4)
endif() endif()
list(FIND OpenCV_LIBS "opencv_world" __index) list(FIND OpenCV_LIBS "opencv_world" __index)
@ -35,3 +46,9 @@ if(MSVC OR MSYS OR MINGW)
else() else()
set(OpenCV_LIB_SEARCH_PATH "${OpenCV_LIB_PATH}") set(OpenCV_LIB_SEARCH_PATH "${OpenCV_LIB_PATH}")
endif() endif()
else()
set(WITH_OPENCV FALSE)
endif()

View File

@ -184,7 +184,7 @@ int main(int argc, char *argv[]) {
// Show disparity instead of depth, but show depth values in region. // Show disparity instead of depth, but show depth values in region.
auto &&depth_frame = disp_data.frame; auto &&depth_frame = disp_data.frame;
#ifdef USE_OPENCV3 #ifdef WITH_OPENCV3
// ColormapTypes // ColormapTypes
// http://docs.opencv.org/master/d3/d50/group__imgproc__colormap.html#ga9a805d8262bcbe273f16be9ea2055a65 // http://docs.opencv.org/master/d3/d50/group__imgproc__colormap.html#ga9a805d8262bcbe273f16be9ea2055a65
cv::applyColorMap(depth_frame, depth_frame, cv::COLORMAP_JET); cv::applyColorMap(depth_frame, depth_frame, cv::COLORMAP_JET);

View File

@ -196,7 +196,7 @@ int main(int argc, char *argv[]) {
// Show disparity instead of depth, but show depth values in region. // Show disparity instead of depth, but show depth values in region.
auto &&depth_frame = disp_data.frame; auto &&depth_frame = disp_data.frame;
#ifdef USE_OPENCV3 #ifdef WITH_OPENCV3
// ColormapTypes // ColormapTypes
// http://docs.opencv.org/master/d3/d50/group__imgproc__colormap.html#ga9a805d8262bcbe273f16be9ea2055a65 // http://docs.opencv.org/master/d3/d50/group__imgproc__colormap.html#ga9a805d8262bcbe273f16be9ea2055a65
cv::applyColorMap(depth_frame, depth_frame, cv::COLORMAP_JET); cv::applyColorMap(depth_frame, depth_frame, cv::COLORMAP_JET);

View File

@ -178,7 +178,7 @@ cv::Rect CVPainter::DrawText(
y += offset_y; y += offset_y;
cv::Point org(x, y); cv::Point org(x, y);
#ifdef USE_OPENCV2 #ifdef WITH_OPENCV2
cv::putText( cv::putText(
const_cast<cv::Mat &>(img), text, org, FONT_FACE, FONT_SCALE, FONT_COLOR, const_cast<cv::Mat &>(img), text, org, FONT_FACE, FONT_SCALE, FONT_COLOR,
THICKNESS); THICKNESS);

View File

@ -29,7 +29,7 @@ DisparityProcessor::DisparityProcessor(std::int32_t proc_period)
int sgbmWinSize = 3; int sgbmWinSize = 3;
int numberOfDisparities = 64; int numberOfDisparities = 64;
#ifdef USE_OPENCV2 #ifdef WITH_OPENCV2
// StereoSGBM // StereoSGBM
// http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html?#stereosgbm // http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html?#stereosgbm
sgbm_ = cv::Ptr<cv::StereoSGBM>( sgbm_ = cv::Ptr<cv::StereoSGBM>(
@ -79,7 +79,7 @@ bool DisparityProcessor::OnProcess(
ObjMat *output = Object::Cast<ObjMat>(out); ObjMat *output = Object::Cast<ObjMat>(out);
cv::Mat disparity; cv::Mat disparity;
#ifdef USE_OPENCV2 #ifdef WITH_OPENCV2
// StereoSGBM::operator() // StereoSGBM::operator()
// http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#stereosgbm-operator // http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#stereosgbm-operator
// Output disparity map. It is a 16-bit signed single-channel image of the // Output disparity map. It is a 16-bit signed single-channel image of the

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
#include "dataset/dataset.h" #include "dataset/dataset.h"
#ifdef USE_OPENCV2 #ifdef WITH_OPENCV2
#include <opencv2/highgui/highgui.hpp> #include <opencv2/highgui/highgui.hpp>
#else #else
#include <opencv2/imgcodecs/imgcodecs.hpp> #include <opencv2/imgcodecs/imgcodecs.hpp>

View File

@ -16,13 +16,18 @@ include(${CMAKE_CURRENT_LIST_DIR}/IncludeGuard.cmake)
cmake_include_guard() cmake_include_guard()
find_package(OpenCV REQUIRED) find_package(OpenCV REQUIRED)
message(STATUS "Found OpenCV: ${OpenCV_VERSION}") message(STATUS "Found OpenCV: ${OpenCV_VERSION}")
set(WITH_OPENCV TRUE)
add_definitions(-DWITH_OPENCV)
if(OpenCV_VERSION VERSION_LESS 3.0) if(OpenCV_VERSION VERSION_LESS 3.0)
add_definitions(-DUSE_OPENCV2) add_definitions(-DWITH_OPENCV2)
elseif(OpenCV_VERSION VERSION_LESS 4.0) elseif(OpenCV_VERSION VERSION_LESS 4.0)
add_definitions(-DUSE_OPENCV3) add_definitions(-DWITH_OPENCV3)
else() else()
add_definitions(-DUSE_OPENCV4) add_definitions(-DWITH_OPENCV4)
endif() endif()
list(FIND OpenCV_LIBS "opencv_world" __index) list(FIND OpenCV_LIBS "opencv_world" __index)