From 478eb70c07ea54688b30242a76fb349e3c172dcf Mon Sep 17 00:00:00 2001 From: Daniel Bermond Date: Fri, 7 Dec 2018 16:37:30 -0800 Subject: [PATCH] Fix build with OpenCV 4.0 (#14356) Summary: Fixes #14355 Pull Request resolved: https://github.com/pytorch/pytorch/pull/14356 Differential Revision: D13356237 Pulled By: bddppq fbshipit-source-id: 2bf6ee21995c2c7b617c4e78ea7341f975f1b937 --- caffe2/video/optical_flow.cc | 4 ++++ cmake/Dependencies.cmake | 12 ++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/caffe2/video/optical_flow.cc b/caffe2/video/optical_flow.cc index 4855b2c..8d34304 100644 --- a/caffe2/video/optical_flow.cc +++ b/caffe2/video/optical_flow.cc @@ -7,7 +7,11 @@ void OpticalFlowExtractor( const cv::Mat& curr_gray, const int flow_alg_type, cv::Mat& flow) { +#if CV_MAJOR_VERSION >= 4 + cv::Ptr tvl1 = cv::DISOpticalFlow::create(); +#else cv::Ptr tvl1 = cv::DualTVL1OpticalFlow::create(); +#endif switch (flow_alg_type) { case FLowAlgType::FarnebackOpticalFlow: cv::calcOpticalFlowFarneback( diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 156e7b9..07cab96 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -431,11 +431,15 @@ endif() # ---[ OpenCV if(USE_OPENCV) - # OpenCV 3 - find_package(OpenCV 3 QUIET COMPONENTS core highgui imgproc imgcodecs videoio video) + # OpenCV 4 + find_package(OpenCV 4 QUIET COMPONENTS core highgui imgproc imgcodecs optflow videoio video) if(NOT OpenCV_FOUND) - # OpenCV 2 - find_package(OpenCV QUIET COMPONENTS core highgui imgproc) + # OpenCV 3 + find_package(OpenCV 3 QUIET COMPONENTS core highgui imgproc imgcodecs videoio video) + if(NOT OpenCV_FOUND) + # OpenCV 2 + find_package(OpenCV QUIET COMPONENTS core highgui imgproc) + endif() endif() if(OpenCV_FOUND) include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS}) -- 2.7.4