Boost/OpenCV 错误:与调用 '(boost::_mfi::d m<void(cv::Mat*, cv::VideoCapture*), Recorder>)
Boost/OpenCV error: no match for call to '(boost::_mfi::dm<void(cv::Mat*, cv::VideoCapture*), Recorder>)
我想使用OpenCV和Boost库实现"平滑"的视频录制。为此,我试图实现我在我的程序中发现的代码。我还不太熟悉Boost,我一直得到错误bind.hpp:313:错误:不匹配调用'(Boost::_mfi::dm) (cv::Mat*&, cv:: videoccapture *&)'打开:打开(f, 0) ([base_type:: a1_]、[base_type:: a2_]);
我的代码如下:#include "recorder.h"
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "boost/thread.hpp"
using namespace cv;
using namespace std;
using namespace boost::posix_time;
Recorder::Recorder(){
webcamRecorder.open(1);
webcamRecorder.set(CV_CAP_PROP_FRAME_WIDTH, 1920);
webcamRecorder.set(CV_CAP_PROP_FRAME_HEIGHT, 1080);
recordingCount=0;
filename = "F:/MyVideo";
ext=".avi";
hasStarted=false;
}
void Recorder::captureFunc(Mat *matRecorder, VideoCapture *webcamRecorder){
for(;;){
//capture from webcame to Mat frame
(*webcamRecorder) >> (*matRecorder);
resize(*matRecorder,matOut,Size(1280,720),0,0,INTER_LINEAR);
}
}
void Recorder::setup(){
if (!hasStarted){
this->start();
boost::thread captureThread(&Recorder::captureFunc, &matRecorder, &webcamRecorder);
}
}
void Recorder::run(){
cout << "++++++++recorder thread called+++" << endl;
theVideoWriter.open(filename+countAsString+ext,CV_FOURCC('L','A','G','S'), 30, Size(1280,720), true);
nextFrameTimestamp = microsec_clock::local_time();
currentFrameTimestamp = nextFrameTimestamp;
td = (currentFrameTimestamp - nextFrameTimestamp);
if ( theVideoWriter.isOpened() == false ){
cout << "ERROR: Failed to write the video" << endl;
}
if (recording){
while(recording){
hasStarted=true;
while(td.total_microseconds() < 1000000/30){
//determine current elapsed time
currentFrameTimestamp = microsec_clock::local_time();
td = (currentFrameTimestamp - nextFrameTimestamp);
}
// determine time at start of write
initialLoopTimestamp = microsec_clock::local_time();
theVideoWriter << matOut; // write video file
nextFrameTimestamp = nextFrameTimestamp + microsec(1000000/30);
td = (currentFrameTimestamp - nextFrameTimestamp);
finalLoopTimestamp = microsec_clock::local_time();
td1 = (finalLoopTimestamp - initialLoopTimestamp);
delayFound = td1.total_milliseconds();
cout << delayFound << endl;
}
}
hasStarted=false;
cout << "finished recording" << endl;
theVideoWriter.release();
recordingCount++;
countAsString = static_cast<ostringstream*>( &(ostringstream() << recordingCount) )->str();
}
void Recorder::setRecording(bool x){ recording = x;}
我的实现出了什么问题?同样,原始代码片段来自这里
问题,以及您的案例与您提供的链接之间的区别在于,您为线程函数使用了对象方法。具体来说:
boost::thread captureThread(&Recorder::captureFunc, &matRecorder, &webcamRecorder);
对象方法需要一个指向this
的指针。由于在对象方法中创建线程,因此可以使用它的this
指针:
boost::thread captureThread(&Recorder::captureFunc, this, &matRecorder, &webcamRecorder);
一般性建议:
- 你不再需要线程的boost了。
C++11
在其标准库中有它。如果可以的话,我建议你使用它。你创建的线程变成了detached
——它继续执行,但是你不能控制它。你可能想把它保存在某个地方,这样你可以以后join
它。将线程作为实例变量:
- 在类定义中声明线程:
std::thread captureThread;
. 在当前函数中初始化,并且将移动到实例变量
std::thread localCaptureThread(&Recorder::captureFunc, this, &matRecorder, &webcamRecorder);captureThread = std::move(localCaptureThread);
相关文章:
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- 在c++类上调用void函数
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- 在派生函数中指定void*参数
- C++为什么尽管我调用了void函数,它却不起作用
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 如何从void函数输出字符串
- 我应该使用什么来代替void作为变体中的替代类型之一
- 奇怪的结构&GCC&clang(void*返回类型)
- Arduino:for/while/if在void setup()或void loop()之前?——错误:之前需要不合格
- 为什么这个函数将"const char*"转换为"void* const"而不是"const void*"
- 引用一个已擦除类型(void*)的指针
- 概念中的cv限定符需要表达式参数列表
- SWIG链接器:未定义符号:_ZN2cv8fastFreeEPv(cv::fastFree(void*))
- 断言失败(scn == 3 || scn == 4)void cv :: cvtcolor(cv :: inputArr
- 键入对"cv::fastFree(void*)"的未定义引用
- 对 'cv::fastFree(void*)' 的未定义引用
- opencvsharp Cv.Threshold即使对于ThresholdType.Otsu也返回void
- Boost/OpenCV 错误:与调用 '(boost::_mfi::d m<void(cv::Mat*, cv::VideoCapture*), Recorder>)
- OpenCV C++/C 编译错误:未定义对 'cv::fastFree(void*)' 的引用