Optimizing opencv gstreamer with mipi camera and show image in application

Hi, I followed Optimizing opencv gstreamer with mipi and usb uvc cameras - Jetson & Embedded Systems / Jetson Nano - NVIDIA Developer Forums and it worked fine. And I want to show video frame in Qt application, so i call cv::cvtColor() to convert frame to RGB. But I found this method runs on CPU, and it takes up too much CPU resources. Is there a way to optimize it?

Hi, I was the author of that post. I don’t know if it was clear but that solution worked well only for my use case. I didn’t do a video feed but I did need quick captures from multiple cameras. Since it wasn’t a live feed, I only called cv::cvtColor when speed was not important. Your best choice is probably to use the nvargus api if you want a live video feed.

Hi, I read your post and I benefit a lot .
My Gstreamer And Opencv code as follows:

std::string gstreamer_pipeline = "nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)3820 , height=(int)
           2464, format=(string)NV12, framerate=(fraction) 21/1 ! nvvidconv flip-method=0 ! video/x-raw, width=(int)1920,height=(int)1080 ,format=(string)I420 ! appsink  drop=true";

cv::VideoCapture video_capture (gstreamer_pipeline, CAP_GSTREAMER);

It worked fine for me. But I wanted to show video frames in Qt Qlabel, So I have to do the follow convertions:

//1-Convert I420  To RGB
cv::cvtColor(frame, show, cv::COLOR_YUV2BGR_I420);
cv::cvtColor(show, show, cv::COLOR_BGR2RGB);

//2-Convet Opencv Mat to Qimage
Qimage image = QImage((const unsigned char*)show.data, show.cols, show.rows, QImage::Format_RGB888);

//3-Convert Qimage to QpPxmap
QPixmap pixmap = QPixmap::fromImage(image);

//4-Show Qpixmap in QPixmap

I found that the firtst step: Convert I420 To RGB takes up too much CPU resources, about 70% to 80%.
I want to optimize it.

There isn’t a way to optimize that. If you want live video feed, then you can’t use my solution. You’ll have to go with the nvargus api for the best results.

You may find some better results with OpenCV’s GraphAPI, but I haven’t tried that. I also don’t work on this project anymore so I haven’t been up to date with any changes to the APIs. I don’t know if GraphAPI can integrate with Qt well.

Thanks, I will try to go with the nvargus api , and I noticed that Opencv has cv::cuda::Mat and some camera cases in jetson nano which may help me.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.