Ask Your Question
0

Help me pls to compile

asked 2014-11-22 05:40:29 -0500

updated 2014-11-26 09:27:37 -0500

Doombot gravatar image

While i was comppiling this code using makefile, terminal shows me errors(after the code). Could you explain me, how to compile it correctly pls.

#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"

using namespace cv;

void readme();

/** @function main */
int main( int argc, char** argv )
{
  if( argc != 3 )
  { readme(); return -1; }

  Mat img_1 = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
  Mat img_2 = imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );

  if( !img_1.data || !img_2.data )
  { std::cout<< " --(!) Error reading images " << std::endl; return -1; }

  //-- Step 1: Detect the keypoints using SURF Detector
  int minHessian = 400;

  SurfFeatureDetector detector( minHessian );

  std::vector<KeyPoint> keypoints_1, keypoints_2;

  detector.detect( img_1, keypoints_1 );
  detector.detect( img_2, keypoints_2 );

  //-- Draw keypoints
  Mat img_keypoints_1; Mat img_keypoints_2;

  drawKeypoints( img_1, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
  drawKeypoints( img_2, keypoints_2, img_keypoints_2, Scalar::all(-1), DrawMatchesFlags::DEFAULT );

  //-- Show detected (drawn) keypoints
  imshow("Keypoints 1", img_keypoints_1 );
  imshow("Keypoints 2", img_keypoints_2 );

  waitKey(0);

  return 0;
  }

  /** @function readme */
  void readme()
  { std::cout << " Usage: ./SURF_detector <img1> <img2>" << std::endl; }

anvar@anvar-SVF15N1Z2RB:~/OCV$ make
g++ -I/usr/local/include/opencv -L/usr/local/lib -o test homo.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui
/tmp/ccLX2PIA.o: In function `main':
homo.cpp:(.text+0x173): undefined reference to `cv::SURF::SURF(double, int, int, bool, bool)'
homo.cpp:(.text+0x1c4): undefined reference to `cv::FeatureDetector::detect(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::Mat const&) const'
homo.cpp:(.text+0x206): undefined reference to `cv::FeatureDetector::detect(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::Mat const&) const'
homo.cpp:(.text+0x271): undefined reference to `cv::drawKeypoints(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> > const&, cv::Mat&, cv::Scalar_<double> const&, int)'
homo.cpp:(.text+0x2af): undefined reference to `cv::drawKeypoints(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> > const&, cv::Mat&, cv::Scalar_<double> const&, int)'
/tmp/ccLX2PIA.o: In function `cv::Feature2D::~Feature2D()':
homo.cpp:(.text._ZN2cv9Feature2DD2Ev[_ZN2cv9Feature2DD2Ev]+0x69): undefined reference to `cv::DescriptorExtractor::~DescriptorExtractor()'
homo.cpp:(.text._ZN2cv9Feature2DD2Ev[_ZN2cv9Feature2DD2Ev]+0x80): undefined reference to `cv::FeatureDetector::~FeatureDetector()'
homo.cpp:(.text._ZN2cv9Feature2DD2Ev[_ZN2cv9Feature2DD2Ev]+0xc6): undefined reference to `cv::FeatureDetector::~FeatureDetector()'
/tmp/ccLX2PIA.o: In function `cv::SURF::~SURF()':
homo.cpp:(.text._ZN2cv4SURFD1Ev[_ZN2cv4SURFD1Ev]+0xe): undefined reference to `vtable for cv::SURF'
homo.cpp:(.text._ZN2cv4SURFD1Ev[_ZN2cv4SURFD1Ev]+0x26): undefined reference to `vtable for cv::SURF'
homo.cpp:(.text._ZN2cv4SURFD1Ev[_ZN2cv4SURFD1Ev]+0x2e): undefined reference to `vtable for cv::SURF'
homo.cpp:(.text._ZN2cv4SURFD1Ev[_ZN2cv4SURFD1Ev]+0x3b): undefined reference to `VTT for cv::SURF'
collect2: error: ld returned 1 exit status
make: *** [test] Ошибка 1
edit retag flag offensive close merge delete

Comments

Since you do not provide the Makefile itself. I tell you what the problem is. The line 'g++ -I/usr/local/include/opencv -L/usr/local/lib -o test homo.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui' is telling you it is linking to the following libraries: opencv_core, opencv_imgproc and opencv_highgui. But the linker could not find any of the SURF or FeatureDetector stuff in those libraries. Add those libraries (with -l) and you should be good.

boaz001 gravatar imageboaz001 ( 2014-11-27 03:23:58 -0500 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2014-11-26 16:18:14 -0500

Just compare your includes with the libraries you linked against... There could be a missing library that contains your features.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-11-22 05:40:29 -0500

Seen: 591 times

Last updated: Nov 26 '14