opencv cudacodec VideoReader 报错

2020-09-19 17:11:01 浏览数 (1)

代码语言:javascript复制
#include <opencv2cudacodec.hpp>

这篇文章 https://blog.csdn.net/zijin0802034/article/details/83825081 提供了一个办法,复用例子里的代码,可以运行,但是测的性能还比不上cpu版本的!!

找了可能原因 : https://github.com/opencv/opencv/issues/10201

Hello, I've just walked through all the same issues and can share my experience. Here is how I've successfully compiled my project with cv::cudacodec::VideoReader

My setup:

  • Ubuntu 16.04
  • OpenCV 3.4.1
  • CUDA 9.1
  • CMake 3.5.1
  1. Copy dynlink_nvcuvid.cpp somewhere inside your project. File itself located in /usr/local/cuda/samples/3_Imaging/cudaDecodeGL/dynlink_nvcuvid.cpp if you've properly installed CUDA Toolkit
  2. Link CUDA library to your project
    • CMake

    include_directories(${CUDA_INCLUDE_DIRS}) target_link_libraries(project_name cuda)

    • gcc

    -lcuda

  3. Include CUDA headers in your project
代码语言:javascript复制
#include <dynlink_nvcuvid.h>
#include <dynlink_cuviddec.h>
  1. Init the device before using cv::cuda stuff
代码语言:javascript复制
// Init CUDA
void* hHandleDriver = nullptr;
CUresult cuda_res = cuInit(0, __CUDA_API_VERSION, hHandleDriver);
if (cuda_res != CUDA_SUCCESS) {
    throw exception();
}
cuda_res = cuvidInit(0);
if (cuda_res != CUDA_SUCCESS) {
    throw exception();
}
std::cout << "CUDA init: SUCCESS" << endl;
cv::cuda::printCudaDeviceInfo(cv::cuda::getDevice());

但是去源码里搜一下,并没有 dynlink_nvcuvid 相关的文件。

看来需要重编一下?

NVCUVID was enabled in opencv cmake with-D WITH_NVCUVID=ON -D CUDA_nvcuvid_LIBRARY=/usr/lib/nvidia-384/libnvcuvid.so

但是cmake里没有 WITH_NVCUVID选项。。。。。

我用的CUDA11和opencv4.4,,,,

原来,新版本的去掉了这个功能。。。。https://github.com/opencv/opencv_contrib/issues/1786

Seems like cuda video decoder is deprecated.

https://docs.nvidia.com/cuda/video-decoder/index.html

That's why -DBUILD_opencv_cudacodec=OFF fixes the issue.

转到了 NVIDIA Video Codec SDK.

0 人点赞