2

I am using a NOIR Pi camera for my Raspberry Pi 3 module. I plan to run some high fps image processing algo using openCV in a C++ environment. However, I cant seem to obtain the video stream in a high enough fps. Setting CV_CAM_PROPS_FPS using openCV's VideoCapture class doesn't seem to do anything to the actual fps of the camera.

Is there a way I can adjust the FPS of the camera to 90fps within the cpp file or externally from the console? I don't mind reducing the resolution of the video.

[Edit]

Here is the code i am using

#include "stdio.h"
#include "opencv2/opencv.hpp"

using namespace cv;

int main(int, char**)
{

 std::cout << "Init Program 2\n";

 VideoCapture cap(0); // open the default camera

if(!cap.isOpened())  // check if we succeeded
 {        
std::cout << "Camera Init Fail\n";
return -1;
 }

std::cout << "Camera Init Successful\n";
std::cout << "Setting parameters..\n";

std::cout <<"\t[PARAM_FPS] ";
if(!cap.set(CV_CAP_PROP_FPS,15)){
     std::cout <<"SUCCESS\n";
}else{
     std::cout <<"FAIL\n";
}

std::cout <<"\t[PARAM_FRAME_WIDTH] ";
if(!cap.set(CV_CAP_PROP_FRAME_WIDTH,320)){
     std::cout <<"SUCCESS\n";
}else{
     std::cout <<"FAIL\n";
}

std::cout <<"\t[PARAM_FRAME_HEIGHT] ";
if(!cap.set(CV_CAP_PROP_FRAME_HEIGHT,240)){
     std::cout <<"SUCCESS\n";
}else{
     std::cout <<"FAIL\n";
}

int nFPS = cap.get(CV_CAP_PROP_FPS);
std::cout << "Loaded FPS : " << nFPS << "\n";


namedWindow("show",1);
for(;;)
{
    Mat frame;
    cap >> frame; // get a new frame from camera
    imshow("show", frame);
    if(waitKey(1) >= 0) break;

}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
 }

[Solved]

The setting the FPS after setting the width and height seems to do the trick. That makes sense because a higher resolution image will cause a significant drop in the FPS. Therefore every time you change the geometry feature, the FPS will reset by default.

5
  • Do you have some code? Commented Nov 12, 2017 at 21:16
  • And what output do you get from this code? Commented Nov 13, 2017 at 0:35
  • a window screen with the camera video frames. Setting the fps via the VideoCapture class has no effect as the output from the same class function(get function) indicates that the video is capturing at a 30 fps setting. Changes made to the width and height took effect but the fps is not...
    – yapws87
    Commented Nov 13, 2017 at 1:27
  • Maybe try setting the FPS after setting the geometry rather than before. Commented Nov 13, 2017 at 4:32
  • I have added it as an answer so other folks can find it without wading through all the comments. Please consider accepting it by clicking the hollow tick (checkmark) beside the vote count, Good luck with your project! Commented Nov 13, 2017 at 17:08

1 Answer 1

3

As suggested in the comments, I think you need to set the frame geometry first and then set the frame-rate afterwards.

std::cout <<"\t[PARAM_FRAME_WIDTH] ";
if(!cap.set(CV_CAP_PROP_FRAME_WIDTH,320)){
     std::cout <<"SUCCESS\n";
}else{
     std::cout <<"FAIL\n";
}

std::cout <<"\t[PARAM_FRAME_HEIGHT] ";
if(!cap.set(CV_CAP_PROP_FRAME_HEIGHT,240)){
     std::cout <<"SUCCESS\n";
}else{
     std::cout <<"FAIL\n";
}

std::cout <<"\t[PARAM_FPS] ";
if(!cap.set(CV_CAP_PROP_FPS,15)){
     std::cout <<"SUCCESS\n";
}else{
     std::cout <<"FAIL\n";
}

int nFPS = cap.get(CV_CAP_PROP_FPS);
std::cout << "Loaded FPS : " << nFPS << "\n";

I think the reason is that if you try and set the (high) frane-rate first, it realises it cannot achieve the desired 90fps with the current (default) geometry, so it fails - whereas if you set the smaller, less demanding geometry first, it is then happy to aim for the higher frane-rate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.