听起来这是一个非常受欢迎的问题,请原谅我,但我搜索了解决方案,但我还没有找到。
所以...我已经通过这个脚本安装了OpenCV - http://idmsj.wordpress.com/2012/11/23/script-for-opencv-installation-on-ubuntu-12-10/ - 然后我尝试编译DisplayImage示例(参见这里:http://docs.opencv.org/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html)但是这样做不起作用。
这是发生的事情 - 通过以下指令给出,通过手工编译:
$ 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
我怎么能解决这个问题?
Post scriptum:如果我尝试编译以下代码
/////////////////////////////////////////////////////
// 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;
}
输入
g++ trialcam1a.cpp -o trialcam1a.x `pkg-config --cflags --libs opencv`
我可以制作一个可行的可执行文件。
我怎么能解决这个问题?
提前谢谢你,
朱塞佩
编辑:我正在使用Ubuntu 12.10在64位计算机上工作。