Skip to content

Commit 5795d8d

Browse files
committed
disable NVIDIA Optical Flow SDK when CUDA < 10.0
1 parent ea1081c commit 5795d8d

File tree

6 files changed

+34
-636
lines changed

6 files changed

+34
-636
lines changed

modules/cudaoptflow/CMakeLists.txt

+19-17
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@ ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wmissing-d
88

99
ocv_define_module(cudaoptflow opencv_video opencv_optflow opencv_cudaarithm opencv_cudawarping opencv_cudaimgproc OPTIONAL opencv_cudalegacy WRAP python)
1010

11-
set(NVIDIA_OPTICAL_FLOW_2_0_HEADERS_COMMIT "edb50da3cf849840d680249aa6dbef248ebce2ca")
12-
set(NVIDIA_OPTICAL_FLOW_2_0_HEADERS_MD5 "a73cd48b18dcc0cc8933b30796074191")
13-
set(NVIDIA_OPTICAL_FLOW_2_0_HEADERS_PATH "${OpenCV_BINARY_DIR}/3rdparty/NVIDIAOpticalFlowSDK_2_0_Headers")
14-
ocv_download(FILENAME "${NVIDIA_OPTICAL_FLOW_2_0_HEADERS_COMMIT}.zip"
15-
HASH ${NVIDIA_OPTICAL_FLOW_2_0_HEADERS_MD5}
16-
URL
17-
"https://github.com/NVIDIA/NVIDIAOpticalFlowSDK/archive/"
18-
DESTINATION_DIR "${NVIDIA_OPTICAL_FLOW_2_0_HEADERS_PATH}"
19-
STATUS NVIDIA_OPTICAL_FLOW_2_0_HEADERS_DOWNLOAD_SUCCESS
20-
ID "NVIDIA_OPTICAL_FLOW"
21-
UNPACK RELATIVE_URL)
11+
if(NOT CUDA_VERSION VERSION_LESS "10.0")
12+
set(NVIDIA_OPTICAL_FLOW_2_0_HEADERS_COMMIT "edb50da3cf849840d680249aa6dbef248ebce2ca")
13+
set(NVIDIA_OPTICAL_FLOW_2_0_HEADERS_MD5 "a73cd48b18dcc0cc8933b30796074191")
14+
set(NVIDIA_OPTICAL_FLOW_2_0_HEADERS_PATH "${OpenCV_BINARY_DIR}/3rdparty/NVIDIAOpticalFlowSDK_2_0_Headers")
15+
ocv_download(FILENAME "${NVIDIA_OPTICAL_FLOW_2_0_HEADERS_COMMIT}.zip"
16+
HASH ${NVIDIA_OPTICAL_FLOW_2_0_HEADERS_MD5}
17+
URL "https://github.com/NVIDIA/NVIDIAOpticalFlowSDK/archive/"
18+
DESTINATION_DIR "${NVIDIA_OPTICAL_FLOW_2_0_HEADERS_PATH}"
19+
STATUS NVIDIA_OPTICAL_FLOW_2_0_HEADERS_DOWNLOAD_SUCCESS
20+
ID "NVIDIA_OPTICAL_FLOW"
21+
UNPACK RELATIVE_URL)
2222

23-
if(NOT NVIDIA_OPTICAL_FLOW_2_0_HEADERS_DOWNLOAD_SUCCESS)
24-
message(STATUS "Failed to download NVIDIA_Optical_Flow_2_0 Headers")
25-
else()
26-
add_definitions(-DHAVE_NVIDIA_OPTFLOW=1)
27-
ocv_include_directories(SYSTEM "${NVIDIA_OPTICAL_FLOW_2_0_HEADERS_PATH}/NVIDIAOpticalFlowSDK-${NVIDIA_OPTICAL_FLOW_2_0_HEADERS_COMMIT}")
28-
endif()
23+
if(NOT NVIDIA_OPTICAL_FLOW_2_0_HEADERS_DOWNLOAD_SUCCESS)
24+
message(STATUS "Failed to download NVIDIA_Optical_Flow_2_0 Headers")
25+
else()
26+
message(STATUS "Building with NVIDIA Optical Flow API 2.0")
27+
add_definitions(-DHAVE_NVIDIA_OPTFLOW=2)
28+
ocv_include_directories(SYSTEM "${NVIDIA_OPTICAL_FLOW_2_0_HEADERS_PATH}/NVIDIAOpticalFlowSDK-${NVIDIA_OPTICAL_FLOW_2_0_HEADERS_COMMIT}")
29+
endif()
30+
endif()

modules/cudaoptflow/perf/perf_optflow.cpp

+2-50
Original file line numberDiff line numberDiff line change
@@ -326,56 +326,7 @@ PERF_TEST_P(ImagePair, OpticalFlowDual_TVL1,
326326
}
327327
}
328328

329-
//////////////////////////////////////////////////////
330-
// NvidiaOpticalFlow_1_0
331-
332-
PERF_TEST_P(ImagePair, NvidiaOpticalFlow_1_0,
333-
Values<pair_string>(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png")))
334-
{
335-
declare.time(10);
336-
337-
const cv::Mat frame0 = readImage(GetParam().first, cv::IMREAD_GRAYSCALE);
338-
ASSERT_FALSE(frame0.empty());
339-
340-
const cv::Mat frame1 = readImage(GetParam().second, cv::IMREAD_GRAYSCALE);
341-
ASSERT_FALSE(frame1.empty());
342-
Stream inputStream;
343-
Stream outputStream;
344-
345-
if (PERF_RUN_CUDA())
346-
{
347-
const cv::cuda::GpuMat d_frame0(frame0);
348-
const cv::cuda::GpuMat d_frame1(frame1);
349-
cv::cuda::GpuMat d_flow;
350-
cv::Ptr<cv::cuda::NvidiaOpticalFlow_1_0> d_nvof;
351-
try
352-
{
353-
d_nvof = cv::cuda::NvidiaOpticalFlow_1_0::create(frame0.size(),
354-
cv::cuda::NvidiaOpticalFlow_1_0::NVIDIA_OF_PERF_LEVEL::NV_OF_PERF_LEVEL_FAST,
355-
false, false, false, 0, inputStream, outputStream);
356-
}
357-
catch (const cv::Exception& e)
358-
{
359-
if(e.code == Error::StsBadFunc || e.code == Error::StsBadArg || e.code == Error::StsNullPtr)
360-
throw SkipTestException("Current configuration is not supported");
361-
throw;
362-
}
363-
364-
TEST_CYCLE() d_nvof->calc(d_frame0, d_frame1, d_flow);
365-
366-
cv::cuda::GpuMat flow[2];
367-
cv::cuda::split(d_flow, flow);
368-
369-
cv::cuda::GpuMat u = flow[0];
370-
cv::cuda::GpuMat v = flow[1];
371-
372-
CUDA_SANITY_CHECK(u, 1e-10);
373-
CUDA_SANITY_CHECK(v, 1e-10);
374-
375-
d_nvof->collectGarbage();
376-
}
377-
}
378-
329+
#if defined HAVE_NVIDIA_OPTFLOW
379330
//////////////////////////////////////////////////////
380331
// NvidiaOpticalFlow_2_0
381332

@@ -430,5 +381,6 @@ PERF_TEST_P(ImagePair, NvidiaOpticalFlow_2_0,
430381
d_nvof->collectGarbage();
431382
}
432383
}
384+
#endif //defined HAVE_NVIDIA_OPTFLOW
433385

434386
}} // namespace

modules/cudaoptflow/samples/nvidia_optical_flow.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ bool parseROI(std::string ROIFileName, std::vector<Rect>& roiData)
198198

199199
int main(int argc, char **argv)
200200
{
201+
#if defined HAVE_NVIDIA_OPTFLOW
201202
std::unordered_map<std::string, NvidiaOpticalFlow_2_0::NVIDIA_OF_PERF_LEVEL> presetMap = {
202203
{ "slow", NvidiaOpticalFlow_2_0::NVIDIA_OF_PERF_LEVEL::NV_OF_PERF_LEVEL_SLOW },
203204
{ "medium", NvidiaOpticalFlow_2_0::NVIDIA_OF_PERF_LEVEL::NV_OF_PERF_LEVEL_MEDIUM },
@@ -333,5 +334,6 @@ int main(int argc, char **argv)
333334
std::cout << ex.what() << std::endl;
334335
return 1;
335336
}
337+
#endif //defined HAVE_NVIDIA_OPTFLOW
336338
return 0;
337-
}
339+
}

modules/cudaoptflow/samples/optical_flow.cpp

+4-19
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ int main(int argc, const char* argv[])
183183
Ptr<cuda::DensePyrLKOpticalFlow> lk = cuda::DensePyrLKOpticalFlow::create(Size(7, 7));
184184
Ptr<cuda::FarnebackOpticalFlow> farn = cuda::FarnebackOpticalFlow::create();
185185
Ptr<cuda::OpticalFlowDual_TVL1> tvl1 = cuda::OpticalFlowDual_TVL1::create();
186-
Ptr<cuda::NvidiaOpticalFlow_1_0> nvof_1_0 = cuda::NvidiaOpticalFlow_1_0::create(frame0.size(),
187-
NvidiaOpticalFlow_1_0::NVIDIA_OF_PERF_LEVEL::NV_OF_PERF_LEVEL_FAST, false, false, false, 0, inputStream, outputStream);
186+
#ifdef HAVE_NVIDIA_OPTFLOW
188187
Ptr<cuda::NvidiaOpticalFlow_2_0> nvof_2_0 = cuda::NvidiaOpticalFlow_2_0::create(frame0.size(),
189188
NvidiaOpticalFlow_2_0::NVIDIA_OF_PERF_LEVEL::NV_OF_PERF_LEVEL_FAST, NvidiaOpticalFlow_2_0::NVIDIA_OF_OUTPUT_VECTOR_GRID_SIZE::NV_OF_OUTPUT_VECTOR_GRID_SIZE_1,
190189
NvidiaOpticalFlow_2_0::NVIDIA_OF_HINT_VECTOR_GRID_SIZE::NV_OF_HINT_VECTOR_GRID_SIZE_UNDEFINED, false, false, false, 0, inputStream, outputStream);
190+
#endif
191191

192192
{
193193
GpuMat d_frame0f;
@@ -239,23 +239,7 @@ int main(int argc, const char* argv[])
239239
showFlow("TVL1", d_flow);
240240
}
241241

242-
{
243-
//The timing displayed below includes the time taken to copy the input buffers to the OF CUDA input buffers
244-
//and to copy the output buffers from the OF CUDA output buffer to the output buffer.
245-
//Hence it is expected to be more than what is displayed in the NVIDIA Optical Flow SDK documentation.
246-
const int64 start = getTickCount();
247-
248-
nvof_1_0->calc(d_frame0, d_frame1, d_flowxy);
249-
250-
const double timeSec = (getTickCount() - start) / getTickFrequency();
251-
cout << "NVIDIAOpticalFlow_1_0 : " << timeSec << " sec" << endl;
252-
253-
nvof_1_0->upSampler(d_flowxy, frame0.size(), nvof_1_0->getGridSize(), d_flow);
254-
255-
showFlow("NVIDIAOpticalFlow_1_0", d_flow);
256-
nvof_1_0->collectGarbage();
257-
}
258-
242+
#ifdef HAVE_NVIDIA_OPTFLOW
259243
{
260244
//The timing displayed below includes the time taken to copy the input buffers to the OF CUDA input buffers
261245
//and to copy the output buffers from the OF CUDA output buffer to the output buffer.
@@ -272,6 +256,7 @@ int main(int argc, const char* argv[])
272256
showFlow("NVIDIAOpticalFlow_2_0", d_flow);
273257
nvof_2_0->collectGarbage();
274258
}
259+
#endif
275260

276261
imshow("Frame 0", frame0);
277262
imshow("Frame 1", frame1);

0 commit comments

Comments
 (0)