Program crash when try to do cvtcolor in Xavier AGX

Hi,
I want to convert an image obtained by gstreamer with a program in c++.
My problem is that when I get the frame by:

gst_pad_add_probe (src_pad, GST_PAD_PROBE_TYPE_BUFFER, frame_processing, NULL, NULL);

I get the gpuMat, this works fine, but when I try to convert to gray with cuda, I receive an aborted (core dumped) and the program crash.

To further complete this issue, my pipeline is:

rtspsrc location=rtsp://192.168.1.162/z3-1.mp4 ! application/x-rtp,encoding-name=H265,payload=96,framerate=25/1 ! queue max-size-time=500 ! rtph265depay ! video/x-h265, stream-format=byte-stream,framerate=25/1 ! nvv4l2decoder enable-max-performance=true ! queue max-size-bytes=0 max-size-time=500 ! nvvidconv output-buffers=5 name=myconv ! video/x-raw(memory:NVMM), format=RGBA ! nvvidconv output-buffers=5 ! video/x-raw(memory:NVMM), format=NV12 ! queue max-size-bytes=0 max-size-time=500 ! nvv4l2vp9enc maxperf-enable=true bitrate=2000000 ! video/x-vp9 ! queue max-size-bytes=0 max-size-time=500 ! rtpvp9pay ! udpsink host=224.0.0.0 port=5000 max-lateness=500 sync=false qos=false auto-multicast=true

And the code that throws the error is:

cv::cuda::cvtColor(d_mat, d_mat,cv::COLOR_RGBA2BGR);

where d_mat is the gpuMat extracted of CUeglFrame.

I don’t understand what is wrong here because with the same code in the jetson TX2 it works fine and in the Xavier it is failing.
Any ideas?

Thanks

After catching the error and printing it, I see the following error:

OpenCV(4.4.0) /tmp/build_opencv/opencv_contrib/modules/cudev/include/opencv2/cudev/grid/detail/transform.hpp:264: error: (-217:Gpu API call) no kernel image is available for execution on the device in function ‘call’

Ok, I do other example more simple:

include
include <opencv2/videoio.hpp>
include <opencv2/core.hpp>
include <opencv2/videoio.hpp>
include <opencv2/highgui.hpp>
include <opencv2/core/cuda.hpp>
include <opencv2/cudaimgproc.hpp>

using namespace std;
using namespace cv;

int main() {
Mat frame;
cout << “hola” << endl;
VideoCapture cap;

cap.open(0, cv::CAP_ANY);

if (!cap.isOpened()) {
    cerr << "ERROR! Unable to open camera\n";
    return -1;
}


cv::cuda::GpuMat gpu_mat;
for (;;)
{
    // wait for a new frame from camera and store it into 'frame'
    cap.read(frame);

    gpu_mat.upload(frame);
    cuda::cvtColor(gpu_mat, gpu_mat, cv::COLOR_BGR2GRAY);
    gpu_mat.download(frame);
    // check if we succeeded
    if (frame.empty()) {
        cerr << "ERROR! blank frame grabbed\n";
        break;
    }
    // show live and wait for a key with timeout long enough to show images
    imshow("Live", frame);
    if (waitKey(30) >= 0)
        break;
}
return 0;

}

And I get the same result:

what(): OpenCV(4.1.1) /home/nvidia/opencv_contrib-4.1.1/modules/cudev/include/opencv2/cudev/grid/detail/transform.hpp:264: error: (-217:Gpu API call) no kernel image is available for execution on the device in function 'call

The opencv version 4.1.1 shipped with JetPack doesn’t have CUDA support. You would have to build and install your own.

Also note that you can convert to GRAY8 with nvvidconv, such as:

gst-launch-1.0 nvarguscamerasrc ! 'video/x-raw(memory:NVMM), format=NV12' ! nvvidconv ! 'video/x-raw(memory:NVMM), format=I420' ! nvvidconv ! video/x-raw, format=GRAY8 ! videoconvert ! xvimagesink

Or for opencv:

cv::VideoCapture cap("nvarguscamerasrc ! video/x-raw(memory:NVMM), format=NV12 ! nvvidconv ! video/x-raw(memory:NVMM), format=I420 ! nvvidconv ! video/x-raw, format=GRAY8 ! appsink", cv::CAP_GSTREAMER);

Your code also lacks waitKey(1) after imshow. It won’t work fine without.

After reinstalling opencv with option -D CUDA_ARCH_BIN = “5.3,6.2,7.2” everything works