听起来这是一个如此受欢迎的问题,所以请原谅我,但我搜索了解决方案,但我还没有找到。
所以......我已经通过这个脚本安装了 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
我该如何解决这个问题?
发布脚本:如果我尝试编译以下代码
/////////////////////////////////////////////////////
// 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 位机器。