gpt4 book ai didi

c++ - OpenCV 未定义对 Mat 的引用

转载 作者:行者123 更新时间:2023-11-28 06:53:56 26 4
gpt4 key购买 nike

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


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:\Users\PTOSH\Documents\tried.o:tried.cpp:(.text+0x7b): 未定义对 cv::Mat::Mat(_IplImage const* , bool )
C:\Users\PTOSH\Documents\tried.o:tried.cpp:(.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]+0x2d): 未定义对 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.o mingw32-g++.exe -LC:\RPS\python\edp32\opencv\build\x86\vc12\lib -L"C:\Program Files (x86)\CodeBlocks\MinGW\lib" -LC:\RPS\python\edp32\opencv\sources\3rdparty -o C:\Users\PTOSH\Documents\tried.exe C:\Users\PTOSH\Documents\tried.o C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_calib3d248.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_calib3d248d.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_contrib248.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_contrib248d.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_core248.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_core248d.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_features2d248.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_features2d248d.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_flann248.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_flann248d.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_gpu248.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_gpu248d.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_highgui248.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_highgui248d.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_imgproc248.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_imgproc248d.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_legacy248.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_legacy248d.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_ml248.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_ml248d.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_nonfree248.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_nonfree248d.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_objdetect248.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_objdetect248d.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_ocl248.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_ocl248d.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_photo248.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_photo248d.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_stitching248.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_stitching248d.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_superres248.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_superres248d.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_ts248.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_ts248d.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_video248.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_video248d.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_videostab248.lib C:\RPS\python\edp32\opencv\build\x86\vc12\lib\opencv_videostab248d.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_calib3d248.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_calib3d248d.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_contrib248.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_contrib248d.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_core248.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_core248d.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_features2d248.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_features2d248d.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_flann248.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_flann248d.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_gpu248.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_gpu248d.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_highgui248.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_highgui248d.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_imgproc248.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_imgproc248d.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_legacy248.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_legacy248d.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_ml248.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_ml248d.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_nonfree248.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_nonfree248d.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_objdetect248.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_objdetect248d.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_ocl248.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_ocl248d.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_photo248.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_photo248d.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_stitching248.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_stitching248d.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_superres248.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_superres248d.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_ts248.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_ts248d.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_video248.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_video248d.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_videostab248.lib C:\RPS\python\edp32\opencv\build\x64\vc12\lib\opencv_videostab248d.lib C:\Users\PTOSH\Documents\tried.o:tried.cpp:(.text+0x7b): undefined reference to cv::Mat::Mat(_IplImage const*, bool)'
C:\Users\PTOSH\Documents\tried.o:tried.cpp:(.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]+0x2d): undefined reference to
cv::fastFree(void
)'*
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\PTOSH\Documents\tried.o: bad reloc address 0x2d in section `.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]' c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation collect2.exe: error: ld returned 1 exit status Process terminated with status 1 (0 minute(s), 1 second(s)) 2 error(s), 0 warning(s) (0 minute(s), 1 second(s))

最佳答案

如果你真的想使用 c++ api(你应该,因为旧的 c-one dead),

CvCapture* capture; 
// no, use: cv::VideoCapture

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

等扔掉所有 cv* 函数并用它们的 cv::对应物替换它们(也许最好从头开始)

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

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


整个相机捕获归结为 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;
}

关于c++ - OpenCV 未定义对 Mat 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23414535/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com