Ask Your Question

giuscri's profile - activity

2013-03-31 20:48:16 -0600 asked a question Problems with compiling the `displayImage`-example

Hi there!

I've installed OpenCV by this script - http://idmsj.wordpress.com/2012/11/23/script-for-opencv-installation-on-ubuntu-12-10/ - then I tried to compile the DisplayImage-example (see here: http://docs.opencv.org/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html) but that doen not work.

This is what happens -both by following instructions which are given in the above link, both by compiling by hand- :

$ g++ `pkg-config --cflags opencv` DisplayImage.cpp \
  `pkg-config --libs opencv` -o DisplayImage.x

/tmp/ccTXxKFT.o: In function `main':
DisplayImage.cpp:(.text+0x75): undefined reference to `cv::imread(std::string const&, int)'
DisplayImage.cpp:(.text+0x116): undefined reference to `cv::namedWindow(std::string const&, int)'
DisplayImage.cpp:(.text+0x187): undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
collect2: error: ld returned 1 exit status

How could I solve this problem?

Post scriptum: if I try to compile the following code

/////////////////////////////////////////////////////
// trialcam1a.cpp
// A Simple Camera Capture Framework
// This program will connect to a camera then
// show the frames in a window
/////////////////////////////////////////////////////
#include <stdio.h>
#include <cv.h>
#include <highgui.h>

int main()
{
  IplImage *frame = NULL; //Preparing frame pointer
  int key;

  //Allocates and initializes cvCapture structure
  // for reading a video stream from the camera.
  //Index of camera is -1 since only one camera
  // connected to the computer or it does not
  // matter what camera to use.
  CvCapture *input_camera = cvCaptureFromCAM(1);

  // Line added to test if the we're
  // getting something from the camera
  if (!input_camera)
    {
      std::cout << "Error at capture";
      return 1;
    }
  else
    {
      std::cout << "Camera grasped!"
                << std::endl;
    }

  cvWaitKey(10);
  //Grabs and returns a frame from camera
  frame = cvQueryFrame(input_camera);
  #ifdef DEBUG
  int frame_index = 0;
  std::cerr << "frame #"
            << frame_index
            << " == "
            << frame << std::endl;
  #endif

  //Creates window for displaying the frames
  //Flag is reset (0) --> change window size
  // manually
  cvNamedWindow("Capturing Image ...");

  //Change to the appropriate size. In GTK, the
  // inappropriate size will return a segmentation
  // fault. I don't know why ...
  //Gets the appropriate size using cvGetCaptureProperty
  // with CV_CAP_PROP_FRAME_HEIGHT and CV_CAP_PROP_FRAME_WIDTH
  // as property_id
  cvResizeWindow("Capturing Image ...",
         (int) cvGetCaptureProperty(input_camera, CV_CAP_PROP_FRAME_HEIGHT),
         (int) cvGetCaptureProperty(input_camera, CV_CAP_PROP_FRAME_WIDTH));

  cvSaveImage("first_frame.jpg", frame);

  while(frame != NULL)
    {
      // This function vertically
      // flips the `CvArr` called
      // `frame` -what's a `cvArr`?,
      // see reference guide.
      cvFlip(frame, NULL, -1);
      //Shows a frame
      cvShowImage("Capturing Image ...", frame);

      //Checks if ESC is pressed and gives a delay
      // so that the frame can be displayed properly
      key = cvWaitKey(10);
      if(key == 27)
      break;
      //Grabs and returns the next frame
      frame = cvQueryFrame(input_camera);
      #ifdef DEBUG
      ++frame_index;
      std::cerr << "frame #"
                << frame_index
                << " == "
                << frame << std::endl;
      #endif
    }

  //Release cvCapture structure
  cvReleaseCapture(&input_camera);

  //Destroy the window
  cvDestroyWindow("Capturing Image ...");

  return 0;
}

by typing

g++ trialcam1a.cpp -o trialcam1a.x `pkg-config --cflags --libs opencv`

I can produce a working executable.

Any idea of how could I solve that?

Thank you in advance,

Giuseppe

EDIT: I'm working on a 64bit machine, with Ubuntu 12.10.