我试图用C ++学习openCV,而且我正在使用Windows 7(x64)上最新版本的openCV处理代码块13.12。作为一个开始,我测试了我的网络摄像头的简单输出,女巫工作没有麻烦。接下来,我尝试使用cvtColor(img, img_gray, CV_BGR2GRAY)
修改输出。如您所见,我收到2条错误消息。另外,为了澄清,我VisuWork vW
是为了在OOP
中作为练习正确编码而创建的一个类。班级没有做任何特别的事情。
请任何人帮我找到这个问题的问题?
请你帮忙和时间。
#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): 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*)
mingw32-g ++。exe -std = c ++ 11 -Wall -IC:\ RPS \ python \ edp32 \ opencv \ build \ include -c C:\ Users \ PTOSH \ Documents \ tries.cpp -o C: \用户\ PTOSH \文档\ tried.o mingw32-g ++。exe -LC:\ RPS \ python \ edp32 \ opencv \ build \ x86 \ vc12 \ lib -L&#34; C:\ Program Files(x86)\ CodeBlocks \ MinGW \ lib&#34; -LC:\ RPS \ python \ edp32 \ opencv \ sources \ 3rdparty -o C:\ Users \ PTOSH \ Documents \ tries.exe C:\ Users \ PTOSH \ Documents \ tries.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 \ vc1 2 \ 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 \ o pencv \ 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 \ tries.o:trying.cpp :(。text + 0x7b):未定义引用
cv::Mat::Mat(_IplImage const*, bool)' C:\Users\PTOSH\Documents\tried.o:tried.cpp:(.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]+0x2d): undefined reference to
cv :: fastFree(void )& #39 * c:/ program files(x86)/ codeblocks / mingw / bin /../ lib / gcc / mingw32 / 4.8.1 /../../../../ mingw32 / bin / ld.exe:C: \ Users \ PTOSH \ Documents \ tries.o:在`.text $ _ZN2cv3MatD1Ev [__ ZN2cv3MatD1Ev]&#39;部分中错误的重定位地址0x2d c:/ program files(x86)/ codeblocks / mingw / bin /../ lib / gcc / mingw32 / 4.8.1 /../../../../ mingw32 / bin / ld.exe:final link失败:操作无效 collect2.exe:错误:ld返回1退出状态 处理终止,状态为1(0分钟,1秒(秒)) 2个错误,0个警告(0分钟,1秒(s))
答案 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的代码片段几乎总是过时的,要警惕)
并阅读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;
}
答案 1 :(得分:0)
@berak:好的,我删除了#include <opencv/highgui.h>
。但仍然面临cvtColor()部分的问题。
C:\ Users \ PTOSH \ Documents \ tries.o:trying.cpp :(。text + 0x75):未定义引用
cv::Mat::Mat(_IplImage const*, bool)' C:\Users\PTOSH\Documents\tried.o:tried.cpp:(.text+0x9b): undefined reference to
cv :: _ OutputArray :: _ OutputArray(cv :: Mat&amp;)' C:\ Users \ PTOSH \ Documents \ tries.o:trying.cpp :(。text + 0xae):未定义引用cv::_InputArray::_InputArray(cv::Mat const&)' C:\Users\PTOSH\Documents\tried.o:tried.cpp:(.text+0xd3): undefined reference to
cv :: cvtColor(cv :: _ InputArray const&amp;,cv :: _ OutputArray const&amp; ,int,int)'
@ a-Jays:为什么不呢?无论如何,我删除了这个类,可能更容易开始测试openCV而没有。
请回复。
答案 2 :(得分:0)
@berak:
如果你真的想使用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; }
您的代码正在向我返回以下错误,是否可能在我的代码块设置中显示链接失败?:
C:\ Users \ PTOSH \ Documents \ tries.o:trying.cpp :(。text + 0x35):undefined 引用
cv::VideoCapture::VideoCapture(int)' C:\Users\PTOSH\Documents\tried.o:tried.cpp:(.text+0x57): undefined reference to
cv :: VideoCapture :: read(cv :: Mat&amp;)' C:\ Users \ PTOSH \ Documents \ tries.o:trying.cpp :(。text + 0x7b):undefined 引用cv::_InputArray::_InputArray(cv::Mat const&)' C:\Users\PTOSH\Documents\tried.o:tried.cpp:(.text+0xb5): undefined reference to
cv :: imshow(std :: string const&amp;,cv :: _ InputArray const&amp;)' C:\ Users \ PTOSH \ Documents \ tries.o:trying.cpp :(。text + 0xd5):undefined 引用cv::waitKey(int)' C:\Users\PTOSH\Documents\tried.o:tried.cpp:(.text+0x109): undefined reference to
cv :: VideoCapture :: isOpened()const' C:\ Users \ PTOSH \ Documents \ tries.o:trying.cpp :(。text + 0x120):undefined 引用cv::VideoCapture::~VideoCapture()' C:\Users\PTOSH\Documents\tried.o:tried.cpp:(.text+0x162): undefined reference to
cv :: VideoCapture :: ~VideoCapture()'
请求帮助。