I've written a C++ program using OpenCV to receive input from a USB web cam and save it into a video file for later playback. But the playback speed is very high.
To avoid this problem i added an extra line of code:
vid.set(CAP_PROP_FPS,24);
then it shows error messages, and the program can't be executed. Without this line it works fine. But I need to control the cam input FPS in order to avoid the problem of higher playback speed.
The code works perfectly on my test pc, but not on the board.
Is there any way I can control the input FPS rate of the cam in the iMX board
this is my code:
#include <opencv2/highgui.hpp>
#include <iostream>
#include <opencv2/imgproc.hpp>
using namespace cv;
using namespace std;
int main()
{
VideoCapture vid(3);
Mat Frame;
if(!vid.isOpened())
{
cout<<"Error occured while trying to open camera.\n";
return -1;
}
vid.set(CAP_PROP_FPS,24);
namedWindow("Cam Feed",WINDOW_AUTOSIZE);
VideoWriter writer;
writer.open("myvideo.avi",VideoWriter::fourcc('X','V','I','D'),24.0,Size(cap.get(CAP_PROP_FRAME_WIDTH), cap.get(CAP_PROP_FRAME_HEIGHT)));
while(1)
{
if(!vid.read(frame))
{
cout<<"error reading file\n";
break;
}
imshow("Cam Feed",frame);
writer.write(frame);
if(waitKey(30)==113)
{
break;
}
}
vid.release();
writer.release();
destroyAllWindows();
return 0;
}