Opencv 无法编译“DisplayImage”-示例
听起来这是一个很受欢迎的问题,所以请原谅我,我一直在寻找解决方案,但我还没有找到 所以。。。我通过这个脚本安装了OpenCV——然后我尝试编译DisplayImage示例(请参见此处:),但这不起作用 这就是所发生的事情——都是通过遵循上面链接中给出的说明,都是通过手工编译实现的:Opencv 无法编译“DisplayImage”-示例,opencv,Opencv,听起来这是一个很受欢迎的问题,所以请原谅我,我一直在寻找解决方案,但我还没有找到 所以。。。我通过这个脚本安装了OpenCV——然后我尝试编译DisplayImage示例(请参见此处:),但这不起作用 这就是所发生的事情——都是通过遵循上面链接中给出的说明,都是通过手工编译实现的: $ g++ `pkg-config --cflags opencv` DisplayImage.cpp \ `pkg-config --libs opencv` -o DisplayImage.x /tmp/c
$ 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;
}
我可以生成一个工作的可执行文件
你知道我该怎么解决吗
提前谢谢大家,
朱塞佩
编辑:我在一台64位的机器上工作,使用Ubuntu 12.10
g++ trialcam1a.cpp -o trialcam1a.x `pkg-config --cflags --libs opencv`