Boost / OpenCVエラー: '(boost :: _ mfi :: dm <void(cv :: Mat *、cv :: VideoCapture *)、Recorder>)の呼び出しに一致しません

isADon

OpenCVとBoostライブラリを使用して「スムーズな」ビデオ録画を実現したいと思います。そのために、ここ見つけたコードをプログラムに実装しようとしています。私はまだBoostに精通しておらず、エラー\ bind.hpp:313:error:no match to call to '(boost :: _ mfi :: dm)(cv :: Mat *&、cv :: VideoCapture *&) 'unwrapper :: unwrap(f、0)(a [base_type :: a1 _]、a [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);

いくつかの一般的な提案:

  1. スレッドのブーストはもう必要ありません。C++11標準ライブラリにあります。できれば使うことをお勧めします。
  2. 作成したスレッドは次のようになりますdetached-実行を継続しますが、制御することはできません。おそらくどこかに保存したいので、join後で保存できます

スレッドをインスタンス変数として使用するには:

  1. クラス定義でスレッドを宣言しますstd::thread captureThread;
  2. 現在の関数で初期化し、インスタンス変数に移動します。

    std :: thread localCaptureThread(&Recorder :: captureFunc、this、&matRecorder、&webcamRecorder); fetchThread = std :: move(localCaptureThread);

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ