我不明白为什么我会收到这个错误。任何人都可以伸出援手吗?
我需要在头文件中声明VideoCapture捕获并在Video.cpp中调用它
Video.h
class Video
{
public:
static VideoCapture capture;
//Default constructor
Video();
//Declare a virtual destructor:
virtual ~Video();
//Method
void Start();
private:
};
视频.cpp
#include "StdAfx.h"
#include "Video.h"
#include "UserInfo.h"
#include "Common.h"
void Video::Start()
{
while(1)
{
Mat img;
bool bSuccess = capture.read(img); // read a new frame from video
if (!bSuccess) //if not success, break loop
{
cout << "End of video" << endl;
break;
}
imshow("original video", img); //show the frame in "Original Video" window
if(waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
{
cout << "esc key is pressed by user" << endl;
break;
}
}
}
任何帮助将不胜感激
在类定义中,static
变量只是一个宣言。你只是声明了这一点capture
将会存在某处.
您需要添加定义。使变量存在。
在任何版本的 C++ 中
您可以在 cpp 文件中单独定义变量。
const VideoCapture Video::capture;
在 C++ 17 或更高版本中
您可以声明变量inline
在你的标题中使其成为一个定义。
static inline VideoCapture capture;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)