My Environment Info
- OpenCV 4.3.0
- Ubuntu 18.04
- CUDA-10.2
- NVIDIA Video Codec SDK downloaded and headers and libs included the usr/local/cuda
I installed OpenCV with the cmake:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D WITH_TBB=ON \
-D WITH_CUDA=ON \
-D CUDA_ARCH_BIN="7.5" \
-D BUILD_opencv_cudacodec=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D WITH_CUBLAS=1 \
-D BUILD_opencv_java=OFF \
-D BUILD_ZLIB=ON \
-D BUILD_TIFF=ON \
-D WITH_GTK=ON \
-D WITH_NVCUVID=ON \
-D CUDA_nvcuvid_LIBRARY=/usr/lib/x86_64-linux-gnu/libnvcuvid.so \
-D WITH_FFMPEG=ON \
-D WITH_1394=ON \
-D CUDNN_INCLUDE_DIR=/usr/local/cuda/include \
-D CUDNN_LIBRARY=/usr/local/cuda/lib64/libcudnn.so.7.6.5 \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_PC_FILE_NAME=opencv.pc \
-D OPENCV_PC_FILE_NAME=opencv4.pc \
-D OPENCV_ENABLE_NONFREE=ON \
-D WITH_GSTREAMER=ON \
-D WITH_V4L=ON \
-D OPENCV_PYTHON3_INSTALL_PATH=$cwd/OpenCV-4.3.0-py3/lib/python3.5/site-packages \
-D WITH_QT=ON \
-D WITH_CUDNN=ON \ON \
-D CUDA_ARCH_BIN=7.5 \
-D WITH_OPENGL=ON \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..ON \
-D CUDA_ARCH_BIN=7.5 \
-D WITH_OPENGL=ON \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
output of cuda part:
-- NVIDIA CUDA: YES (ver 10.2, CUFFT CUBLAS NVCUVID FAST_MATH)
-- NVIDIA GPU arch: 75
-- NVIDIA PTX archs:
--
-- cuDNN: YES (ver 7.6.5)
I installed OpenCV and tried a simple example like below and worked fine:
#include <iostream>
#include <ctime>
#include <cmath>
#include "bits/time.h"
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/core/cuda.hpp>
#include <opencv2/cudaarithm.hpp>
#include <opencv2/cudaimgproc.hpp>
#define TestCUDA true
int main() {
std::clock_t begin = std::clock();
try {
cv::String filename = "/img/dir/1.png";
cv::Mat srcHost = cv::imread(filename, cv::IMREAD_GRAYSCALE);
for(int i=0; i<1000; i++) {
if(TestCUDA) {
cv::cuda::GpuMat dst, src;
src.upload(srcHost);
//cv::cuda::threshold(src,dst,128.0,255.0, CV_THRESH_BINARY);
cv::cuda::bilateralFilter(src,dst,3,1,1);
cv::Mat resultHost;
dst.download(resultHost);
} else {
cv::Mat dst;
cv::bilateralFilter(srcHost,dst,3,1,1);
}
}
cv::imshow("Result",srcHost);
cv::waitKey();
} catch(const cv::Exception& ex) {
std::cout << "Error: " << ex.what() << std::endl;
}
std::clock_t end = std::clock();
std::cout << double(end-begin) / CLOCKS_PER_SEC << std::endl;
}
But when I tried to compile the code below:
#include <opencv2/opencv_modules.hpp>
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/cudacodec.hpp>
#include <opencv2/highgui.hpp>
int main(int argc, const char* argv[])
{
const std::string fname = "/video/directory/video.mp4";
cv::namedWindow("GPU", cv::WINDOW_NORMAL);
cv::cuda::GpuMat d_frame;
cv::Ptr<cv::cudacodec::VideoReader> d_reader = cv::cudacodec::createVideoReader(fname);
for (;;)
{
if (!d_reader->nextFrame(d_frame))
break;
cv::Mat frame;
d_frame.download(frame);
cv::imshow("GPU", frame);
if (cv::waitKey(3) > 0)
break;
}
return 0;
}
It gives error on the VideoReader
class of cudacodec
:
.../main.cpp:14: error: undefined reference to `cv::cudacodec::createVideoReader(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)'
What I am missing here ?