Can not control camera fps in iMX board

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can not control camera fps in iMX board

707 Views
donjacobvellathottam
Contributor III

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;
}

 

0 Kudos
Reply
2 Replies

683 Views
joanxie
NXP TechSupport
NXP TechSupport

what imx processor do you use? and what decoder do you use? if you use VPU, you can set in the vpu api

0 Kudos
Reply

614 Views
donjacobvellathottam
Contributor III

Hi Joanxie,

thanks for the reply. I've already solved the issue.

I just edited the code where the video capture object is initialized and added the pipeline directly there. 

 

 

0 Kudos
Reply