为什么视频捕获在成员函数中不起作用?
Why VideoCapture doesn't work in member functions?
我花了几个小时试图用同一类的成员函数从成员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();
}
编译正常,但工作不正常。它显示空的"TEST"(测试(窗口。
为什么不能在bember函数中使用cv::VideoCapture::read(cv::Mat(?
PS:opencv v3.4.2
根据关于imshow 的参考
此函数后面应该跟cv::waitKey函数,该函数在指定的毫秒内显示图像否则,它将不会显示图像。
只需添加对waitKey()
函数的调用
capture.read(frame);
cv::imshow("TEST", frame);
cv::waitKey(25);
相关文章:
- 仅包含可移动 std::map 的类的移动构造函数不起作用
- 为什么我的数组双精度函数不起作用?
- std::函数不起作用,但普通的旧函数指针可以 - 为什么?
- C++ Arduino - 随机函数不起作用
- 为什么我的数组或函数不起作用?
- 从类中的另一个文件请求函数不起作用
- 双链表堆栈删除函数不起作用
- 将 cmake 代码段转换为函数 - 不起作用
- 为什么我的从base64解码的函数不起作用?
- 为什么当我们使用等于'='符号比较器函数时,c ++的内置排序函数不起作用?
- swap(int&, int&) 函数不起作用,当交换不使用临时变量时?
- 子类化 STL 容器:范围构造函数不起作用
- 带有此指针的模板类多重继承构造函数不起作用?
- 以下打印树函数不起作用为什么?
- 为什么内存集函数不起作用?
- 调用填充我的主体数组的函数不起作用
- 带有自定义数字的阶乘函数不起作用
- 如何QDialog raise()函数不起作用
- Lambda 表达式闭包函数不起作用
- C++:在没有 lvalue 的情况下调用时复制构造函数不起作用