c++ - 为什么 VideoCapture 在成员函数中不起作用?
问题描述
我花了几个小时试图从具有同一类的成员函数的成员线程中读取 cv::VideoCapture 帧。创建、读取和 imshow() 的所有常用代码都在此成员函数中。
我认为问题出在线程中,但我制作了一些测试代码并在成员函数中找到了它。
该测试代码:
主.cpp:
#include "myclass.hpp"
int main(int argc, char *argv[])
{
myclass m;
m.run();
return 0;
}
我的类.hpp
class myclass
{
public:
myclass();
virtual ~myclass();
void run();
};
我的类.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
解决方案
根据有关imshow的参考资料
这个函数后面应该是 cv::waitKey 函数,它显示指定毫秒的图像。否则,它不会显示图像。
只需添加waitKey()
函数调用
capture.read(frame);
cv::imshow("TEST", frame);
cv::waitKey(25);
推荐阅读
- r - 为每组匹配对创建一个差异变量,mutate_at() 两组
- selenium - Python 无法识别使用 Selenium 单击的按钮
- google-cloud-data-fusion - 云数据融合:数据存储不一致的数据类型问题
- assembly - 汇编程序在返回控制之前不显示或循环
- azure-devops - 带有烧瓶应用程序的 Azure CI/CD 管道无法通过 ZIP 部署进行部署
- database - 如何根据数据库状态添加 Codeigniter 数据表操作按钮?
- sql - 选择以返回 postgres 查询
- javascript - 是否有任何玩笑匹配器来比较数组
? - assembly - 了解这个 x86 汇编函数的作用,递归
- python - JSON 导航