VERY Slow Framerate Jetson TX1 and OpenCV

Hey guys. I am experiencing some problems with really slow framerate when using OpenCV to display a video stream. My code is as simple as it gets. But still, when I try to display HD the entire stream bogs down to ~ 1FPS. If I run tegrastats I can see that all four CPU’s are running at around 60% (average)

Why is this? This is the simplest task ever. Why is it so slow?
Thanks!

Code:

#include <opencv2/imgproc/imgproc.hpp>
#include <stdio.h>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
   

    Mat image1, image2;
    int k, i;

     const char* right_cam_gst = "nvcamerasrc sensor-id=0 ! video/x-raw(memory:NVMM),\
                                              width=(int)1280,\
                                              height=(int)720,\
                                              format=(string)I420,\
                                              framerate=(fraction)60/1 ! nvvidconv flip-method=2 ! video/x-raw,\
                                              format=(string)I420 ! videoconvert ! video/x-raw,\
                                              format=(string)BGR ! appsink";



    VideoCapture cap1 = VideoCapture(right_cam_gst);




namedWindow("window",WINDOW_NORMAL);

   for (;;)
   {
      const clock_t begin_time = clock();
       cap1 >> image1;

        imshow("window", image1);
  

        if(waitKey(1) == 27)
        break;
      cout << float( clock () - begin_time ) /  CLOCKS_PER_SEC << "\n" << std::flush;
     }

}

Please also use jetson_clock.sh to enhance the performance. This gst pipeline uses cpu to convert BGRA to BGR so that would have overhead.

I would suggest you to move to opencv tot to remove the videoconvert element.

Could you perhaps give me a link or reference to where I could find “OpenCV tot”?
Thanks!

Interesting… I’ve changed the gstreamer pipe to:

const char* right_cam_gst = "nvcamerasrc sensor-id=0 ! video/x-raw(memory:NVMM), format=UYVY, width=1280, height=720, framerate=30/1 ! nvvidconv flip-method=2 ! video/x-raw, format=GRAY8, width=1280, height=720 ! appsink";

And it still plays at the same FPS, but my time elapsed counter is now showing a time taken of 0.02 seconds. Instead of 0.75, as I was seeing before. How could this be?
Here is where I calculate the time taken:

for (;;)
   {
      const clock_t begin_time = clock();
       cap1 >> image1;

        imshow("window", image1);
  

        if(waitKey(1) == 27)
        break;
      cout << float( clock () - begin_time ) /  CLOCKS_PER_SEC << "\n" << std::flush;
     }

Just added the -C flag when logging in through ssh (adds compression to Xserver) and it increased the FPS by about double.

Just added the -C flag when logging in through ssh (adds compression to Xserver) and it increased the FPS by about double.

Just FYI, if you are doing remote display to a host display from a Jetson over ssh the GPU of the Jetson won’t be used…you’re offloading to the PC host for GPU function when you do that. You’d have to install a virtual desktop type X server on the Jetson and use the remote viewing software on the PC if the GPU of the Jetson is used for that case.

YAY! Full 60 FPS!

I disabled Xserver when using ssh, and plugged a monitor into the tx1 directly. Thank you both for your input!