C++ OpenCV, very slow read() FPS, after moving to OpenCV4

Viewed 221

So currently all I am doing is just rewriting old methods that were using C OpenCV (not even2). It was nicely running at 1920x1080 with 30fps. But as I am refactoring it want to move to latest libraries.

So Hardware is the same, and so far logic and everything is the same too. except previously to capture the frame I was using cvQueryFrame and cvCaptureFromCAM and currently it's:

CameraController::CameraController(Config& config) : _config(config)
{

    _cam = VideoCapture(0);
    _cam.set(CAP_PROP_FRAME_WIDTH, _config.get<int>("camWidth"));
    _cam.set(CAP_PROP_FRAME_HEIGHT, _config.get<int>("camHeight"));
    _cam.set(CAP_PROP_FPS, _config.get<int>("camFPS"));  //30 FPS, tried without it
    _cam.set(CAP_PROP_BUFFERSIZE, 2);  // tried without it 
}

void CameraController::capture()
{
    _cam.read(_frame);
}

I have thread running like:

ptime currentTime = microsec_clock::local_time();
        float deltaTime = (currentTime - m_prevTime).total_microseconds() / 1000000.0f; // to seconds
        if (deltaTime > 1)
            deltaTime = 0;

        //Capture frame
        _cam.capture();

// Reset timer match desired FPS
        m_loopTimer.expires_from_now(milliseconds((1/_config.get<int>("camFPS"))) * 1000); //to match desired fps (previously was 16ms and no difference)
        m_loopTimer.async_wait(boost::bind(&UpdateController::UpdateLoop, this));
        m_prevTime = currentTime;

And with 1920x1080 I get 5-7 fps. With lowest resolution I am able to get 30fps, but that's not what I want. Why is this happening ?

0 Answers
Related