Ask Your Question

Revision history [back]

OpenCV on Mac and Raspberry Pi performance comparison

Hi, guys.

What I am working on is to use OpenCV + Raspberry Pi 3 Model B + Raspberry Cam V2 + Gstreamer to capture video frames, process them and save them into a video file.

My goal is to capture the frames at frame rate of at least 30fps for 1280x720 resolutions.

My code is also here:

cv::VideoCapture cap("v4l2src device=/dev/video0 ! video/x-raw, framerate=30/1, width=1280, height=720, format=RGB ! videoconvert ! appsink");
if (!cap.isOpened()) {
    printf("=ERR= can't create video capture\n");
    return -1;
}

cv::VideoWriter writer;
writer.open("appsrc ! videoconvert ! omxh264enc ! h264parse ! mpegtsmux ! filesink location=test.mp4", 0, (double)30, cv::Size(640, 480), true);
if (!writer.isOpened()) {
    printf("=ERR= can't create video writer\n");
    return -1;
}

On raspberry pi, write is not writing fast enough: a single frame write uses 50ms~60ms, which is less than what I am desiring.

However, a strange thing I find is, CAP >> FRAME costs from 20ms to 60ms on my Mac, however, it costs 10ms on RPi. However, VIDEOWRITER << FRAME costs 60ms on RPi, but it costs 10ms on my Mac.

This is my code to measure the time:

auto start = std::chrono::high_resolution_clock::now();
cap >> frame;
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end-start;
std::cout << diff.count() << " s\n";

I am looking for any solution to reduce the CAP >> FRAME time on Mac and reduce the VIDEOWRITER << CAP time on RPi.

Thank you in advance!