【发布时间】:2018-07-16 04:56:10
【问题描述】:
我花了几个小时尝试使用同一类的成员函数从成员 Thread 中读取 cv::VideoCapture 帧。所有常用的创建、读取和 imshow() 代码都在这个成员函数中。
我以为问题出在 Thread 中,但我编写了一些测试代码并在成员函数中找到了它。
那个测试代码:
main.cpp:
#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();
};
myclass.cpp
#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();
}
编译正常,但不能正常工作。它显示空的“测试”窗口。
为什么 cv::VideoCapture::read(cv::Mat) 在 bember 函数中不起作用?
PS:opencv v3.4.2
【问题讨论】: