私はビデオを録画するためにRaspberry Piカメラを使用しようとしています。私は録音を行うためにopenCVを使用したいと思います。スローフレームレートRaspicamからのビデオのキャプチャ
hereのraspicam/raspicam_cvライブラリを使用しています。私はカメラを開いてcv :: Matに読み込んでビデオを作成することができますが、フレームレートは1〜2Hzです。
私のコードはここにある:
#include <ctime>
#include <iostream>
#include <raspicam/raspicam_cv.h>
#include <cstdio>
using namespace std;
int main (int argc,char **argv) {
time_t timer_begin,timer_end;
raspicam::RaspiCam_Cv Camera;
cv::Mat image;
int nCount=100;
cout<<"Opening Camera..."<<endl;
if (!Camera.open()) {cerr<<"Error opening the camera"<<endl;return -1;}
cout<<"Capturing "<<nCount<<" frames ...."<<endl;
time (&timer_begin);
cv::VideoWriter writer("Avideo.avi", CV_FOURCC('M', 'J', 'P', 'G'), 30, cv::Size(1280,960), true);
for (int i=0; i<nCount; i++) {
char name[32] = {0};
Camera.grab();
Camera.retrieve (image);
writer.write(image);
}
cout<<"Stop camera..."<<endl;
Camera.release();
time (&timer_end); /* get current time; same as: timer = time(NULL) */
double secondsElapsed = difftime (timer_end,timer_begin);
cout<< secondsElapsed<<" seconds for "<< nCount<<" frames : FPS = "<< (float) ((float) (nCount) /secondsElapsed) <<endl;
}
私は私が達成したいものです30Hzで実行するように見える動画を見ることができるraspivid
プログラムを実行すると。
何らかの理由で、このコードを1280x960のサイズでしか使用できない場合があります。
誰かが私にすばらしいことになるヒントを教えていただけたら。あなたが他のサイズが必要な場合
Camera.get(CV_CAP_PROP_FRAME_WIDTH);
Camera.get(CV_CAP_PROP_FRAME_HEIGHT);
、あなたが設定しset
を使用することができます。たとえば
double RaspiCam_Cv::get (int propId);
:
まず、スローダウンを引き起こす行を特定してください。例えば、私はビデオライター 'writer.write(image);をコメントアウトし、これがどのように速度に影響を与えるかを見ていきます。 – aybassiouny
'writer.write(image)'をコメントアウトすると、ビデオは正確に10Hzになります – James
比較するraspividのcppコードのリンクを提供してください。 – aybassiouny