No FPS change when using MJPEG format

asked 2020-09-21 07:14:06 -0600

Sanju gravatar image

Hi, I'm using See3CAM_130 camera and it's rated for capturing 3840x2160 @15 fps as UYVY format and @30 fps as MJPEG format.

Initially I was using the default format(UYVY) for capturing frames and I could get average 15 FPS. Later on I tried to capture as MJPEG format because of higher FPS. So I've added the line

 capture.set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('M', 'J', 'P', 'G'));

But the FPS is still averages about 15 FPS for 3840x2160. Do I need to add anything else to increase my FPS using MJPEG?

My code:

#include <iostream>
#include <ctime>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <stdio.h>
#include <cstdlib>
#include "opencv2/opencv.hpp"

int main(int argc, char** argv)
{
    cv::VideoCapture capture(0 + cv::CAP_DSHOW);

    if (!capture.isOpened())
    {
        std::cout << "Problem connecting to cam " << std::endl;
        return -1;
    }
    else
        if (argc == 1)
        {
            std::cout << "Successfuly connected to camera " << std::endl;

            capture.set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('M', 'J', 'P', 'G'));

            int ex = (int)capture.get(cv::CAP_PROP_FOURCC);
            char EXT[] = { (char)(ex & 0XFF),(char)((ex & 0XFF00) >> 8),(char)((ex & 0XFF0000) >> 16),(char)((ex & 0XFF000000) >> 24),0 };
            std::cout << "CAP_PROP_FOURCC: " << EXT << std::endl;

            capture.set(cv::CAP_PROP_FRAME_WIDTH, 3840);
            capture.set(cv::CAP_PROP_FRAME_HEIGHT, 2160);

        }

        int frameCounter = 0;
        int tick = 0;
        int fps;
        std::time_t timeBegin = std::time(0);

        cv::Mat frame;

        while (1)
        {
        capture.read(frame);

        if (frame.empty())
        {
            break;
        }

        frameCounter++;

        std::time_t timeNow = std::time(0) - timeBegin;

        if (timeNow - tick >= 1)
        {
            tick++;
            fps = frameCounter;
            frameCounter = 0;
        }

        cv::putText(frame, cv::format("Average FPS=%d", fps), cv::Point(30, 30), cv::FONT_HERSHEY_SIMPLEX, 0.8, cv::Scalar(0, 0, 255));
        cv::imshow("FPS test", frame);
        cv::waitKey(1);
        }

        return 0;

}
edit retag flag offensive close merge delete

Comments

please check the return value from capture.set() setting the fourcc is probably not supported

berak gravatar imageberak ( 2020-09-21 07:31:20 -0600 )edit

For capture.set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('M', 'J', 'P', 'G')); it retuned 1 and I also verified whether MJPG is set or not by using capture.get(cv::CAP_PROP_FOURCC);

Sanju gravatar imageSanju ( 2020-09-22 00:33:36 -0600 )edit