From 2eec03b23f7ff301897f22c61dfda8b2ececb52f Mon Sep 17 00:00:00 2001 From: JFilipe Date: Mon, 25 Feb 2019 18:09:43 +0000 Subject: [PATCH] Enable OpenCV4 compability --- lib/StreamHandlerOpenCV.cpp | 8 ++++++++ modules/DisparityStereoSGBM.cpp | 4 ++-- modules/DisparityStereoSGBM.h | 2 +- modules/MeasureOpticalFlowDualTVL1.cpp | 7 +++++++ modules/OpticalFlow.cpp | 4 ++++ 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/StreamHandlerOpenCV.cpp b/lib/StreamHandlerOpenCV.cpp index 0779d45..6c1894f 100644 --- a/lib/StreamHandlerOpenCV.cpp +++ b/lib/StreamHandlerOpenCV.cpp @@ -29,6 +29,9 @@ #include #include +#if CV_MAJOR_VERSION >= 4 +#include +#endif using cv::Mat; using cv::VideoCapture; @@ -78,8 +81,13 @@ bool StreamHandlerOpenCV::openHandler( ClpString strFilename, bool bInput ) m_strFormatName = "DEV"; m_strCodecName = "Raw Video"; pcVideoCapture = new VideoCapture( iDeviceId ); + #if CV_MAJOR_VERSION >= 4 + m_uiWidth = pcVideoCapture->get( cv::CAP_PROP_FRAME_WIDTH ); + m_uiHeight = pcVideoCapture->get( cv::CAP_PROP_FRAME_HEIGHT ); + #else m_uiWidth = pcVideoCapture->get( CV_CAP_PROP_FRAME_WIDTH ); m_uiHeight = pcVideoCapture->get( CV_CAP_PROP_FRAME_HEIGHT ); + #endif m_dFrameRate = 25; } else diff --git a/modules/DisparityStereoSGBM.cpp b/modules/DisparityStereoSGBM.cpp index cfa7e4c..6158527 100644 --- a/modules/DisparityStereoSGBM.cpp +++ b/modules/DisparityStereoSGBM.cpp @@ -58,7 +58,7 @@ bool DisparityStereoSGBM::create( std::vector apcFrameList ) } m_uiNumberOfDisparities = ( ( apcFrameList[0]->getWidth() / 8 ) + 15 ) & -16; int cn = apcFrameList[0]->getNumberChannels(); -#if( CV_MAJOR_VERSION == 3 ) +#if( CV_MAJOR_VERSION >= 3 ) m_cStereoMatch = cv::StereoSGBM::create( 0, 16, m_uiBlockSize ); m_cStereoMatch->setPreFilterCap( 63 ); @@ -99,7 +99,7 @@ CalypFrame* DisparityStereoSGBM::process( std::vector apcFrameList return m_pcDisparityFrame; } cv::Mat disparityImage, disparityImage8; -#if( CV_MAJOR_VERSION == 3 ) +#if( CV_MAJOR_VERSION >= 3 ) m_cStereoMatch->compute( leftImage, rightImage, disparityImage ); #else m_cStereoMatch( leftImage, rightImage, disparityImage ); diff --git a/modules/DisparityStereoSGBM.h b/modules/DisparityStereoSGBM.h index 8fc9483..515e0ec 100644 --- a/modules/DisparityStereoSGBM.h +++ b/modules/DisparityStereoSGBM.h @@ -60,7 +60,7 @@ private: bool m_bUseHH; int m_uiNumberOfDisparities; unsigned int m_uiBlockSize; -#if( CV_MAJOR_VERSION == 3 ) +#if( CV_MAJOR_VERSION >= 3 ) cv::Ptr m_cStereoMatch; #else cv::StereoSGBM m_cStereoMatch; diff --git a/modules/MeasureOpticalFlowDualTVL1.cpp b/modules/MeasureOpticalFlowDualTVL1.cpp index ffba0a6..40ec989 100644 --- a/modules/MeasureOpticalFlowDualTVL1.cpp +++ b/modules/MeasureOpticalFlowDualTVL1.cpp @@ -23,6 +23,9 @@ */ #include "MeasureOpticalFlowDualTVL1.h" +#if CV_MAJOR_VERSION >= 4 +#include +#endif using cv::Mat; using cv::Mat_; @@ -61,7 +64,11 @@ bool MeasureOpticalFlowDualTVL1::create( std::vector apcFrameList ) return false; m_iStep = 16; + #if CV_MAJOR_VERSION >= 4 + m_cTvl1 = cv::optflow::createOptFlow_DualTVL1(); + #else m_cTvl1 = cv::createOptFlow_DualTVL1(); + #endif m_pcOutputFrame = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY ); return true; diff --git a/modules/OpticalFlow.cpp b/modules/OpticalFlow.cpp index cd4b464..b23e2c8 100644 --- a/modules/OpticalFlow.cpp +++ b/modules/OpticalFlow.cpp @@ -166,7 +166,11 @@ bool OpticalFlowDualTVL1::create( std::vector apcFrameList ) bool bRet = commonCreate( apcFrameList ); if( !bRet ) return bRet; + #if CV_MAJOR_VERSION >= 4 + m_cOpticalFlow = cv::optflow::createOptFlow_DualTVL1(); + #else m_cOpticalFlow = cv::createOptFlow_DualTVL1(); + #endif return bRet; }