learnopencv icon indicating copy to clipboard operation
learnopencv copied to clipboard

demo.cpp:13:10: fatal error: opencv2/cudaarithm.hpp: No such file or directory

Open antortjim opened this issue 3 years ago • 0 comments

Dear learnopencv community

Thank you so much for making such great tutorials!! :-)

I wanted to report an issue I am encountering when compiling your example under Getting-Started-OpenCV-CUDA-Module/

Although the python version of the code works both with gpu and cpu, I cannot compile the C++ version

Python results

python demo.py  --video video/boat.mp4 --device gpu
Configuration
- device :  gpu
- video file :  video/boat.mp4
Number of frames :  320.0
Elapsed time
- full pipeline : 8.060 seconds
- reading : 4.995 seconds
- pre-process : 0.148 seconds
- optical flow : 2.076 seconds
- post-process : 0.839 seconds
Default video FPS : 29.970
Optical flow FPS : 153.677
Full pipeline FPS : 39.578
python demo.py  --video video/boat.mp4 --device cpu
Configuration
- device :  cpu
- video file :  video/boat.mp4
Number of frames :  320.0
Elapsed time
- full pipeline : 39.659 seconds
- reading : 3.766 seconds
- pre-process : 0.489 seconds
- optical flow : 33.567 seconds
- post-process : 1.833 seconds
Default video FPS : 29.970
Optical flow FPS : 9.503
Full pipeline FPS : 8.044

which clearly shows how the GPU speeds up things! :) The pipeline FPS gets 5x speed!!

However, when compiling with C++ I get the following

g++ `pkg-config --cflags --libs opencv4`   demo.cpp -o demo.out -lopencv_core -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_videoio -lopencv_video -lopencv_cudaarithm -lopencv_cudaoptflow -lopencv_cudaimgproc -lopencv_cudawarping -std=c++11
demo.cpp:13:10: fatal error: opencv2/cudaarithm.hpp: No such file or directory
   13 | #include <opencv2/cudaarithm.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

I compiled Opencv with CUDA support (as shown by the Python version)

OpenCV 4.5.2 CUDA 11.3 I installed OpenCV with prefix /usr/local following this guide https://gist.github.com/raulqf/f42c718a658cddc16f9df07ecc627be7

and I know I have the cudaarithm.hpp file here /usr/local/include/opencv4/opencv2/cudaarithm.hpp however, if I add /usr/local/include/opencv4/ as an include dir by adding -I/usr/local/include/opencv4/ to the g++ call, it still does not work, I get another error.

demo.cpp: In function ‘void calculate_optical_flow(std::string, std::string)’:
demo.cpp:316:78: error: invalid initialization of reference of type ‘cv::InputArray’ {aka ‘const cv::_InputArray&’} from expression of type ‘std::vector<double, std::allocator<double> >::const_iterator’ {aka ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double, std::allocator<double> > >’}
  316 |         cout << "- " << timer.first << " : " << accumulate(timer.second.begin(), timer.second.end(), 0.0) << " seconds"<< endl;
      |                                                            ~~~~~~~~~~~~~~~~~~^~
In file included from demo.cpp:9:
/usr/include/opencv4/opencv2/imgproc.hpp:2762:42: note: in passing argument 1 of ‘void cv::accumulate(cv::InputArray, cv::InputOutputArray, cv::InputArray)’
 2762 | CV_EXPORTS_W void accumulate( InputArray src, InputOutputArray dst,
      |                               ~~~~~~~~~~~^~~
demo.cpp:321:89: error: invalid initializatiodemo.cpp: In function ‘void calculate_optical_flow(std::string, std::string)’:
demo.cpp:316:78: error: invalid initialization of reference of type ‘cv::InputArray’ {aka ‘const cv::_InputArray&’} from expression of type ‘std::vector<double, std::allocator<double> >::const_iterator’ {aka ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double, std::allocator<double> > >’}
  316 |         cout << "- " << timer.first << " : " << accumulate(timer.second.begin(), timer.second.end(), 0.0) << " seconds"<< endl;
      |                                                            ~~~~~~~~~~~~~~~~~~^~
In file included from demo.cpp:9:
/usr/include/opencv4/opencv2/imgproc.hpp:2762:42: note: in passing argument 1 of ‘void cv::accumulate(cv::InputArray, cv::InputOutputArray, cv::InputArray)’
 2762 | CV_EXPORTS_W void accumulate( InputArray src, InputOutputArray dst,
      |                               ~~~~~~~~~~~^~~
demo.cpp:321:89: error: invalid initialization of reference of type ‘cv::InputArray’ {aka ‘const cv::_InputArray&’} from expression of type ‘std::vector<double, std::allocator<double> >::iterator’ {aka ‘__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >’}
  321 | at optical_flow_fps  = (num_frames - 1) / accumulate(timers["optical flow"].begin(),  timers["optical flow"].end(),  0.0);
      |                                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~

In file included from demo.cpp:9:
/usr/include/opencv4/opencv2/imgproc.hpp:2762:42: note: in passing argument 1 of ‘void cv::accumulate(cv::InputArray, cv::InputOutputArray, cv::InputArray)’
 2762 | CV_EXPORTS_W void accumulate( InputArray src, InputOutputArray dst,
      |                               ~~~~~~~~~~~^~~
demo.cpp:324:90: error: invalid initialization of reference of type ‘cv::InputArray’ {aka ‘const cv::_InputArray&’} from expression of type ‘std::vector<double, std::allocator<double> >::iterator’ {aka ‘__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >’}
  324 | t full_pipeline_fps = (num_frames - 1) / accumulate(timers["full pipeline"].begin(), timers["full pipeline"].end(), 0.0);
      |                                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~

In file included from demo.cpp:9:
/usr/include/opencv4/opencv2/imgproc.hpp:2762:42: note: in passing argument 1 of ‘void cv::accumulate(cv::InputArray, cv::InputOutputArray, cv::InputArray)’
 2762 | CV_EXPORTS_W void accumulate( InputArray src, InputOutputArray dst,
      |                               ~~~~~~~~~~~^~~
n of reference of type ‘cv::InputArray’ {aka ‘const cv::_InputArray&’} from expression of type ‘std::vector<double, std::allocator<double> >::iterator’ {aka ‘__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >’}
  321 | at optical_flow_fps  = (num_frames - 1) / accumulate(timers["optical flow"].begin(),  timers["optical flow"].end(),  0.0);
      |                                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~

In file included from demo.cpp:9:
/usr/include/opencv4/opencv2/imgproc.hpp:2762:42: note: in passing argument 1 of ‘void cv::accumulate(cv::InputArray, cv::InputOutputArray, cv::InputArray)’
 2762 | CV_EXPORTS_W void accumulate( InputArray src, InputOutputArray dst,
      |                               ~~~~~~~~~~~^~~
demo.cpp:324:90: error: invalid initialization of reference of type ‘cv::InputArray’ {aka ‘const cv::_InputArray&’} from expression of type ‘std::vector<double, std::allocator<double> >::iterator’ {aka ‘__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >’}
  324 | t full_pipeline_fps = (num_frames - 1) / accumulate(timers["full pipeline"].begin(), timers["full pipeline"].end(), 0.0);
      |                                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~

In file included from demo.cpp:9:
/usr/include/opencv4/opencv2/imgproc.hpp:2762:42: note: in passing argument 1 of ‘void cv::accumulate(cv::InputArray, cv::InputOutputArray, cv::InputArray)’
 2762 | CV_EXPORTS_W void accumulate( InputArray src, InputOutputArray dst,
      |                               ~~~~~~~~~~~^~~

Can you tell me how to correct my opencv installation or at least make g++ aware of where the cudaarithm.hpp file is?

Once again, thank you very much! Best regards, Antonio

antortjim avatar Feb 21 '22 17:02 antortjim