OpenCV未定义对材质的引用



我正在尝试在C++中学习openCV,并在Windows 7(x64)上使用最新版本的openCV开发代码块13.12。作为一个开始,我测试了我的网络摄像头的一个简单输出,女巫工作没有遇到任何麻烦。接下来,我尝试用cvtColor(img, img_gray, CV_BGR2GRAY)修改输出。正如你在下面看到的,我收到了2条错误消息。同样需要澄清的是,VisuWork vW是我为了在OOP中正确编码而创建的一个类,作为练习。这个班没有做什么特别的事。请有人帮我找到这个问题的问题吗?谢谢你的帮助和时间。


main.cpp:

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui_c.h>
#include <opencv/highgui.h>
using namespace cv;
using namespace std;
class VisuWork
{
CvCapture* capture;
public:
VisuWork()
{
capture=cvCaptureFromCAM(CV_CAP_ANY);
};
template<typename Type> void sHow(Type frame)
{
//        IplImage* frame = cvQueryFrame(capture); //Create image frames from capture
cvShowImage("Camera_Output", frame); //Show image frames on created window
}
//    void imHSV(IplImage* frame){
//        Mat im(frame);
//        Mat hsv;
//        cvtColor(im, hsv, CV_BGR2HSV);
//    }
~VisuWork()
{
cvReleaseCapture(&capture); //Release capture.
cvDestroyWindow("Camera_Output"); //Destroy Window
}
};
int main( int argc, const char** argv )
{
CvCapture* capture = 0;
capture = cvCaptureFromCAM(CV_CAP_ANY);
if (!capture)
{
// print error, quit application
}
else
{
VisuWork vW;
while(1)  //Create infinte loop for live streaming
{
IplImage* im = cvQueryFrame(capture);
if(!im){}
else{
//        vW.imHSV(frame);
Mat img_gray(im);
vW.sHow(im);
cvtColor(img, img_gray, CV_BGR2GRAY);
}
int key = cvWaitKey(10); //Capture Keyboard stroke
if (char(key) == 27)
{
break; //If you hit ESC key loop will break.
}
}
cvReleaseCapture(&capture); //Release capture.
cvDestroyWindow("Camera_Output"); //Destroy Window
}
}

错误消息:

C:UsersPTOSHDocumentstried.o:tried.cpp:(.text+0x7b): undefined reference to cv::Mat::Mat(_IplImage const*, bool) C:UsersPTOSHDocumentstried.o:tried.cpp:(.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]+0x2d): undefined reference to cv::fastFree(void*)


这是完整的构建日志:


mingw32-g++.exe-std=c++11-Wall-IC:\RPS\python\edp32\opencv\build\include-c c:\Users\PTOSH\Documents\tried.cpp-o c:\Users\ PTOSH\Documents \tried.omingw32-g++.exe-LC:\RPS\python\edp32\opencv\build\x86\vc12\lib-L"C:\Program Files(x86)\CodeBlocks\MinGW\lib"-LC:\RPS\pathon\edp32\opencv\sources\3rdparty-o C:\Users\PTOSH\Documents\tried.exe C:\Users\ PTOSH\Documents\teried.o C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_calib3d248.lib C:\RPS\ pytho\edp32\open v\build \x86\vc12\lib\opencv_calib3d248d.libC: \RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_controb248.lib C:\RPS\pathon\edp32\opencv\puild\x86/vc12\lib\opencv-controb248d.lib C:\RPS \python\\edp32\opencv\build\x86\vc12\lib\openv_core248.lib C:\RPS\python\edp32\opencv\bbuild\x86\vc12\lib\ opencv_core248d.lib C:\ libC: \RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_features2d248d.lib C:\RPS\pthon\edp32\open cv\build\x86\vc12\lib\opencv-frann248.lib C:\RPS \python\\edp32\ opencv\bbuild\x86\vc12\lib\ opencv_frann248d.lib C:\RPS\python\edp32\opencv\puild\x86\ vc12\lib \opencv_gpu248.lib C:\RPS\python \edp32\opencv\bilt\x86\ vc12\lib u248d.libC: \RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_highbui248.lib C:\RPS\pathon\edp32\opencv\build\x86\vc12\lib\ opencv_heigbui248d.lib C:\RPS\python\edp32\opencv\build\x86\vc12\opencv_imgproc248.lib C:\RPS\python \edp32\opencv\bbuild\x86/vc12\lib\opencv[imgproc248d.lib C:v_legacy248.libC: \RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_legacy248d.lib C:\RPS\pathon\edp32\opencv.build\x86/vc12\opencv_ml248.lib C:\RPS \python\\edp32\opencv\build\x86\vc12\opencv_ml248d.lib C:\RPS\python\edp32\opencv\bbuild\x86\vc12\lib\opencv_nofree248.lib C:\RPS\ python\edp32\open v\build\x68\vc12\plib\openiv_nofree248 d.libC: \RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_objectdetect248.lib C:\RPS\pthon\edp32\open cv\build\x86\vc12\opencv.objectdetect248 d.lib C:\RPS\ python\edp32\opencv\build\x86\vc12\lib\ opencv_occ248.lib C:\RPS\python\ edp32\ opencv\bbuild\x86\ vc12\lib \opencv_Occ248d.lib C:\RPS \python\\edp32\opencv\build\ x86\vc12\lib\opencv_photol248.lib ibC: \RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_photo248d.lib C:\RPS\pthon\edp32\open cv\build\x86\vc12\lib\opencv_stitching248.lib C:\RPS\python\edp32\opencc\build\x86 \vc12\ lib\openv_stitching248.lib C:\RPS \python\\edp32\ opencv\bbuild\x86\vc12\lib\ opencv_superres248.lib C:superres248d.libC: \RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_ts248.lib C:\RPS\pthon\edp32\open cv\build\x86\vc12\opencv.ts248d.lib C:\RPS \python\\edp32\ opencv\bbuild\x86\ vc12\lib \opencv_video248.lib C:\ RPS\pathon\edp32\opencv\puild\x86\ vc12\lib\opencv-video2248d.lib C:\C: \RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_videostab248d.lib C:\RPS\pathon\edp32\opencv\build\x64\vc12\lib\opencv_calib3d248.lib C:\RPS \python\\edp32\opencv\build\x64\vc12\ lib\openv_calib3d248d.lib C:\RPS\python\edp32\opencv\bbuild\x64\vc12\lib\ opencv_controb248.lib C:48d.libC: \RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_core248.lib C:\RPS\pathon\edp32\opencv\puild\x64/vc12\lib\opencv-core248d.lib C:\RPS\ pytho\edp32\open cv\build\x64\vc12\lib\openc_features2d248.lib C:\RPS \python\\edp32\opencv\bbuild\x64\vc12\lib\ opencv_features2d248d.lib C:\ RPS\ python \edp32\opencv\pbuild\x64\ vc12\lib opencv_frann2 48.libC: \RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_frann248d.lib C:\RPS\pathon\edp32\opencv\puild\x64/vc12\lib\opencv_gpu248.lib C:\RPS\python\edp32\open cv\build\x64\vc12\lib\openv_gpu248d.lib C:\ RPS\python \edp32\opencv\bbuild\x64\vc12\lib\ opencv_higigui248.lib C:\RPS\python \edp32\ opencv\bilt\x64\vc guid248d.libC: \RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_imgproc248.lib C:\RPS\pthon\edp32\open cv\build\x64\vc12\lib\opencv_imgproc248d.lib C:\RPS\pytho\edp32\opencv\bbuild\x64\vc12\lib\ opencv_legacy248.lib C:\RPS\Pytho\edp22\opencv\puild\x64\ vc12\lib \opencv-legacy248d.lib C:v_ml248.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_ml248d.libC: \RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_offree248.lib C:\RPS\pthon\edp32\open cv\build\x64\vc12\lib\opencv_nofree248d.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\ opencv_objectdetect248.lib C:\RPS\python\edp22\opencv\puild\x64\ vc12\lib opencv_obsdetect248d.lib C:\RPS 248.libC: \RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_ocl248d.lib C:\RPS\pathon\edp32\opencv\puild\x64/vc12\lib\opencv_photo248.lib C:\RPS \python\\edp32\opencv\build\x64\vc12\lib\openv_photo248d.lib C:\RPS\pyth\edp32\opencv\bbuild\x64\vc12\lib\ opencv_stitching248.lib C:\RPS\python\edp32\open cv\build\ x64\vc12\lib\ opencv-stitching 248d.libC: \RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_superres248.lib C:\RPS\pathon\edp32\opencv\build\x64\vc12\lib\ opencv_supperres248d.lib C:\RPS\ python \edp32\opencv\bbuild\x6C:\Users\PTOSH\Documents\tryd.o:tryed.cpp:(.text+0x7b):对cv::Mat::Mat(_IplImage const*, bool)' C:UsersPTOSHDocumentstried.o:tried.cpp:(.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]+0x2d): undefined reference tocv::fastFree(void)'*C:/program files(x86)/codeblocks/mingw/bin/..的未定义引用/lib/gcc/mingw32/4.8.1/../../../mingw32/bin/ld.exe:C:\Users\PTOSH\Documents\tryd.o:节`.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]'中的错误重新定位地址0x2dc:/program files(x86)/codeblocks/mingw/bin//lib/gcc/mingw32/4.8.1/../../../mingw32/bin/ld.exe:最终链接失败:操作无效collect2.exe:错误:ld返回1退出状态进程已终止,状态为1(0分钟1秒)2个错误,0个警告(0分钟,1秒)

如果你真的想使用c++api(你应该这样做,因为旧的c-one已经死了),

CvCapture* capture; 
// no, use: cv::VideoCapture
IplImage* frame = cvQueryFrame(capture); 
// no, use: cv::Mat frame; capture.read(frame)

等等。抛出所有cv*函数,并将其替换为cv::对应函数(也许最好从头开始)

(顺便说一句,SO的代码片段几乎总是过时的,要小心)

并阅读文档(底部的教程链接)


整个相机捕捉可以归结为c++中的极少数行:

#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
int main()
{
VideoCapture cap(0); // get first cam
while( cap.isOpened() )
{
Mat frame;
if ( ! cap.read(frame) ) // cam might need some warmup
continue;
// your processing goes here
imshow("lalala",frame);
if ( waitKey(10)==27 )
break;
}
return 0;
}

相关内容

  • 没有找到相关文章

最新更新