[英]Slow Framerate Capturing Video from Raspicam
I'm trying to use a Raspberry Pi camera to record a video. 我正在尝试使用Raspberry Pi相机录制视频。 I want to use openCV to do the recording, because when I have this working I will do some more processing.
我想使用openCV进行记录,因为当我进行这项工作时,我将进行更多处理。
I'm using the raspicam/raspicam_cv library from here . 我正在从这里使用raspicam / raspicam_cv库。 I am able to open the camera and read into a cv::Mat, and create a video, but the frame rate is between 1-2 Hz.
我能够打开相机并读入cv :: Mat,并创建视频,但是帧频在1-2 Hz之间。
My code is here: 我的代码在这里:
#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;
}
When I run the program raspivid
I can see videos which seem to run at 30 Hz which is what I would like to achieve. 当我运行
raspivid
程序raspivid
我看到的视频似乎以30 Hz的频率运行,这是我想要实现的。
I can also only get this code to work using size 1280x960 for some reason. 由于某种原因,我也只能使用1280x960大小来使此代码正常工作。
If anyone could give me some tips that would be great. 如果有人可以给我一些提示,那就太好了。
The default size of raspicam::RaspiCam_Cv
is 1280*960,you can use get
to get: raspicam::RaspiCam_Cv
的默认大小为1280 * 960,您可以使用get
获得:
double RaspiCam_Cv::get ( int propId );
for example: 例如:
Camera.get(CV_CAP_PROP_FRAME_WIDTH);
Camera.get(CV_CAP_PROP_FRAME_HEIGHT);
If you want other size,you can use set
to set: 如果需要其他尺寸,可以使用
set
进行设置:
bool RaspiCam_Cv::set ( int propId, double value );
for example: 例如:
Camera.set(CV_CAP_PROP_FRAME_WIDTH,640);
Camera.set(CV_CAP_PROP_FRAME_HEIGHT,480);
The other properties can get/set include: 可以获取/设置的其他属性包括:
* CV_CAP_PROP_FRAME_WIDTH,CV_CAP_PROP_FRAME_HEIGHT,
* CV_CAP_PROP_FORMAT: CV_8UC1 or CV_8UC3
* CV_CAP_PROP_BRIGHTNESS: [0,100]
* CV_CAP_PROP_CONTRAST: [0,100]
* CV_CAP_PROP_SATURATION: [0,100]
* CV_CAP_PROP_GAIN: (iso): [0,100]
* CV_CAP_PROP_EXPOSURE: -1 auto. [1,100] shutter speed from 0 to 33ms
* CV_CAP_PROP_WHITE_BALANCE_RED_V : [1,100] -1 auto whitebalance
* CV_CAP_PROP_WHITE_BALANCE_BLUE_U : [1,100] -1 auto whitebalance
* CV_CAP_PROP_MODE : [1,7] 0 auto mode
PS:The FPS and size of cv::VideoWriter
must be same with raspicam::RaspiCam_Cv
,otherwise, cv::VideoWriter
will never work. PS:
cv::VideoWriter
的FPS和大小必须与raspicam::RaspiCam_Cv
相同,否则cv::VideoWriter
将永远无法工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.