Apalis TK1 OpenCV vs Gstreamer framerate


I’ve been benchmarking camera framerate performance on TK1 using OV5640 camera module.
Using Gstream with the following pipeline:

time -v gst-launch-0.10 v4l2src device=/dev/video0 num-buffers=100 ! 'video/x-raw-yuv,format=(fourcc)UYVY,width=1920,height=1080' ! fakesink

I achieve about 28fps for 1080p resolution which corresponds to the camera specifications. However, with OpenCV camera achieves only 15fps.

I use OpenCV built through Yocto with:

IMAGE_INSTALL_append = " opencv"

and use the following code to measure framerate:

// Open and config camera
cv::VideoCapture cap;
cap.set(cv::CAP_PROP_FRAME_WIDTH, 1920);
cap.set(cv::CAP_PROP_FRAME_HEIGHT, 1080);

// Discard first 10 images to stabilize capture
cv::Mat frame;
for(int i=0; i<10; ++i) {
	cap >> frame;

// Measure FPS
const int count = 20;
for(int i=0; i<count; ++i) {
	start = std::chrono::high_resolution_clock::now();
	finish_capture = std::chrono::high_resolution_clock::now();
	std::chrono::duration<double> elapsed_capture = finish_capture - start;
	std::cout << elapsed_capture.count() << " s. Fps (capture): " << (1.0/elapsed_capture.count()) << "\n";

Do you have any idea, why OpenCV performs worse than Gstreamer and how could framerate in OpenCV be improved?

I guess you are just comparing apples with pears. Of course running 100 frames through Gstreamer not actually doing anything with them is much faster per frame then measuring the time one frame takes to process through OpenCV.

Sure it won’t be a 1-to-1 comparison as there’s always some extra overhead coming from OpenCV. But in this example I measure only VideoCapture::grab() function that shouldn’t be performing any processing on the frames (i.e. decoding is initialized by VideoCapture::retrieve() that would be called afterwards). So I would expect it be more or less equivalent to pure Gstreamer also doing nothing with the frames.

Hi @AdamS

I tested your code with checking also the cpu usage. The CPU usage is about 100%, so this means only one CPU is working. It seems that this is the bottleneck. So you can maybe multi thread your application or do a different optimization to get a better fps number.

Best regards,