简体   繁体   English

基本c ++程序上的UBUNTU LTS中的Opencv错误

[英]Opencv in UBUNTU LTS error on basic c++ program

I installed opencv on UBUNTU 18.04 for C++.我在 UBUNTU 18.04 上为 C++ 安装了 opencv。 I used cmake on github source code and build in opencv/release.我在 github 源代码上使用了 cmake 并在 opencv/release 中构建。 But writing even a hello world program containing ''' #include ''' is causing error on compiling with g++.但是,即使编写包含 ''' #include ''' 的 hello world 程序也会导致使用 g++ 编译时出错。 The error report is:错误报告是:

在此处输入图片说明

`
In file included from /usr/include/opencv2/highgui.hpp:51,
                 from main.cpp:1:
/usr/include/opencv2/videoio.hpp:928:83: error: invalid use of incomplete type ‘struct cv::DefaultDeleter<CvCapture>’
 template<> CV_EXPORTS void DefaultDeleter<CvCapture>::operator ()(CvCapture* obj) const;
                                                                                   ^~~~~
In file included from /usr/local/include/opencv2/core/cvstd.hpp:81,
                 from /usr/local/include/opencv2/core/base.hpp:58,
                 from /usr/local/include/opencv2/core.hpp:54,
                 from /usr/include/opencv2/highgui.hpp:46,
                 from main.cpp:1:
/usr/local/include/opencv2/core/cvstd_wrapper.hpp:32:29: note: declaration of ‘struct cv::DefaultDeleter<CvCapture>’
 template<typename Y> struct DefaultDeleter;
                             ^~~~~~~~~~~~~~
In file included from /usr/include/opencv2/highgui.hpp:51,
                 from main.cpp:1:
/usr/include/opencv2/videoio.hpp:929:91: error: invalid use of incomplete type ‘struct cv::DefaultDeleter<CvVideoWriter>’
 template<> CV_EXPORTS void DefaultDeleter<CvVideoWriter>::operator ()(CvVideoWriter* obj) const;
                                                                                           ^~~~~
In file included from /usr/local/include/opencv2/core/cvstd.hpp:81,
                 from /usr/local/include/opencv2/core/base.hpp:58,
                 from /usr/local/include/opencv2/core.hpp:54,
                 from /usr/include/opencv2/highgui.hpp:46,
                 from main.cpp:1:
/usr/local/include/opencv2/core/cvstd_wrapper.hpp:32:29: note: declaration of ‘struct cv::DefaultDeleter<CvVideoWriter>’
 template<typename Y> struct DefaultDeleter;
`

Edit: same output on编辑:相同的输出

g++ main.cpp `pkg-config --cflags --libs opencv` -o out 

My code main.cpp is:我的代码main.cpp是:

#include <opencv2/highgui.hpp>
#include <iostream>

int main( int argc, char** argv ) {

  cv::Mat image;
  image = cv::imread("sample.jpeg" , CV_LOAD_IMAGE_COLOR);

  if(! image.data ) {
      std::cout <<  "Could not open or find the image" << std::endl ;
      return -1;
    }

  cv::namedWindow( "Display window", cv::WINDOW_AUTOSIZE );
  cv::imshow( "Display window", image );

  cv::waitKey(0);
  return 0;
}

The bash output of bash 输出

pkg-config --cflags --libs opencv

is :是 :

-I/usr/include/opencv -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_datasets -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_line_descriptor -lopencv_optflow -lopencv_video -lopencv_plot -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_rgbd -lopencv_viz -lopencv_surface_matching -lopencv_text -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core

bash output bash 输出

System configuration:系统配置:

opencv : 3.2.0 opencv:3.2.0

compiler: g++编译器:g++

os : ubuntu操作系统:ubuntu

You will need to link OpneCV with your program.您需要将OpneCV与您的程序链接。

Try the following: g++ main.cpp pkg-config --cflags --libs opencv -o out尝试以下操作: g++ main.cpp pkg-config --cflags --libs opencv -o out

pkg-config --cflags --libs opencv will add include_dirs and link_directories . pkg-config --cflags --libs opencv将添加include_dirslink_directories

More explanation here .更多解释在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM