C++ 为什么VideoCapture没有';你不能在成员函数中工作吗?
我花了几个小时试图从具有同一类的成员函数的成员线程中读取cv::VideoCapture帧。创建、读取和imshow()的所有常用代码都在这个成员函数中 我以为问题出在线程中,但我编写了一些测试代码,并在成员函数中找到了它 该测试代码: main.cpp:C++ 为什么VideoCapture没有';你不能在成员函数中工作吗?,c++,opencv,pthreads,C++,Opencv,Pthreads,我花了几个小时试图从具有同一类的成员函数的成员线程中读取cv::VideoCapture帧。创建、读取和imshow()的所有常用代码都在这个成员函数中 我以为问题出在线程中,但我编写了一些测试代码,并在成员函数中找到了它 该测试代码: main.cpp: #include "myclass.hpp" int main(int argc, char *argv[]) { myclass m; m.run(); return 0; } myclass.hpp clas
#include "myclass.hpp"
int main(int argc, char *argv[])
{
myclass m;
m.run();
return 0;
}
myclass.hpp
class myclass
{
public:
myclass();
virtual ~myclass();
void run();
};
#include <opencv/cv.h>
#include <opencv2/opencv.hpp>
#include "myclass.hpp"
myclass::myclass()
{
}
myclass::~myclass()
{
}
void myclass::run()
{
cv::VideoCapture capture(0);
cv::Mat frame;
while(true)
{
capture.read(frame);
cv::imshow("TEST", frame);
}
capture.release();
}
myclass.cpp
class myclass
{
public:
myclass();
virtual ~myclass();
void run();
};
#include <opencv/cv.h>
#include <opencv2/opencv.hpp>
#include "myclass.hpp"
myclass::myclass()
{
}
myclass::~myclass()
{
}
void myclass::run()
{
cv::VideoCapture capture(0);
cv::Mat frame;
while(true)
{
capture.read(frame);
cv::imshow("TEST", frame);
}
capture.release();
}
#包括
#包括
#包括“myclass.hpp”
myclass::myclass()
{
}
myclass::~myclass()
{
}
void myclass::run()
{
cv::视频捕获(0);
cv::垫架;
while(true)
{
捕获。读取(帧);
cv::imshow(“测试”,框架);
}
捕获。释放();
}
编译正常,但工作不正常。它显示空的“测试”窗口
为什么不能在bember函数中使用cv::VideoCapture::read(cv::Mat)
PS:opencv v3.4.2根据有关 该函数后面应该跟有cv::waitKey函数,该函数显示指定毫秒的图像否则,它将不显示图像 只需添加调用
waitKey()
函数即可
capture.read(frame);
cv::imshow("TEST", frame);
cv::waitKey(25);
我认为waitKey()属于imshow(),可以将它放在一个类的线程函数中,也可以将VideoCapture::read(Mat)放在没有waitKey()的另一个类的成员函数中。我只是在读取(Mat)之后,将waitKey()从线程类函数移到读取器类函数。现在它可以工作了。