BackgroundSubtractorMOG2 & OpenCV

ぃ、小莉子 提交于 2019-12-04 03:56:36

问题


I'm trying to compile the simple example at http://mateuszstankiewicz.eu/?p=189 I'm running Ubuntu 12.10 64 bits.I use OpenCV 2.4.4a

I compile using a makefile that does this :

g++ background_subtraction.cpp -o background_subtraction -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L /usr/local/lib -lm -lopencv_core -lopencv_highgui -lopencv_imgproc -lcvblob

The errors :

/tmp/cc0ZWnll.o: dans la fonction « main »:
background_subtraction.cpp:(.text+0x96): référence indéfinie vers « cv::BackgroundSubtractorMOG2::BackgroundSubtractorMOG2() »
background_subtraction.cpp:(.text+0x1f0): référence indéfinie vers « cv::BackgroundSubtractorMOG2::operator()(cv::_InputArray const&, cv::_OutputArray const&, double) »
background_subtraction.cpp:(.text+0x222): référence indéfinie vers « cv::BackgroundSubtractorMOG2::getBackgroundImage(cv::_OutputArray const&) const »
background_subtraction.cpp:(.text+0x61a): référence indéfinie vers « cv::BackgroundSubtractorMOG2::~BackgroundSubtractorMOG2() »
background_subtraction.cpp:(.text+0x7a6): référence indéfinie vers « cv::BackgroundSubtractorMOG2::~BackgroundSubtractorMOG2() »
collect2: erreur: ld a retourné 1 code d'état d'exécution

Means : undefined reference to ...

The background_subtraction.cpp file :

#include <opencv2/opencv.hpp>

#include <iostream>
#include <vector>

int
main (int argc, char *argv[])
{
  cv::Mat frame;
  cv::Mat back;
  cv::Mat fore;
  cv::VideoCapture cap (0);
  cv::BackgroundSubtractorMOG2 bg;
  bg.set ("nmixtures", 3);
  //bg.bShadowDetection = false;
  std::vector < std::vector < cv::Point > >contours;

  cv::namedWindow ("Frame");
  cv::namedWindow ("Background");

  for (;;)
    {
      cap >> frame;
      bg.operator()(frame, fore);
      bg.getBackgroundImage (back);
      cv::erode (fore, fore, cv::Mat ());
      cv::dilate (fore, fore, cv::Mat ());
      cv::findContours (fore, contours, CV_RETR_EXTERNAL,
            CV_CHAIN_APPROX_NONE);
      cv::drawContours (frame, contours, -1, cv::Scalar (0, 0, 255), 2);
      cv::imshow ("Frame", frame);
      cv::imshow ("Background", back);
      if (cv::waitKey (30) >= 0)
    break;
    }
  return 0;
}

What am I missing to compile this program succesfully ? Thanks :)


回答1:


You also need to link opencv_video




回答2:


Add these lines of code. then it will work./

int const mixture = 2;
    const bool bShadowDetection = false;
    cv::BackgroundSubtractorMOG2 bg(mixture, bShadowDetection);



回答3:


if you are using Microsoft Visual just add "opencv_video244.lib" in

properties->linker->input->additional dependencies



来源:https://stackoverflow.com/questions/15866794/backgroundsubtractormog2-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!