Why the image is gray in rtsp source 's opencv gstreamer?

I use gstreamer and nvv4l2decoder to read rtsp stream into opencv,and show it.my code like this:

std::string pipe = "rtspsrc location=rtsp://localhost:8554/001 ! rtph264depay ! h264parse ! nvv4l2decoder ! nvvideoconvert ! appsink";


    VideoCapture cap(pipe, CAP_GSTREAMER);

    if (!cap.isOpened()) {
        cerr <<"VideoCapture not opened!"<<endl;
        exit(-1);
    }

    while (true) {
        Mat frame;
        Mat out_frame;

        cap.read(frame);

        
        cv::imshow("demo test", frame);
        if (cv::waitKey(3) > 0)
                    break;
    }

but ,I got a gray image !

I try to modify code like this:

cap.read(frame);

        // cv::cvtColor (frame, out_frame, cv::COLOR_RGBA2BGR);
        //frame=cv::cvtColor(frame,cv::COLOR_RGBA2BGRA)
        #if (CV_MAJOR_VERSION >= 4)
        cv::cvtColor (frame, out_frame, cv::COLOR_RGBA2BGR);
        #else
        cv::cvtColor (frame, out_frame, cv::CV_RGBA2BGR);
        #endif
        //imwrite("receiver.png", frame);
        cv::imshow("demo test", out_frame);

but ,it still gray !(I try difference rtsp source also)

so ,how to change it to normal ?

May I know what’s your HW system environment and SW information?

@kayccc
Hi,my computer is:

  • 3090 gpu with cuda 11.4,Driver Version: 470.103.01
  • deepstream 6.0 with tensorrt 8.0.3.4
  • opencv 4.5.5

Hi,
Please check if you can run the string in gst-launch-1.0 command:

$ gst-launch-1.0 rtspsrc location=rtsp://localhost:8554/001 ! rtph264depay ! h264parse ! nvv4l2decoder ! nvvideoconvert ! video/x-raw,format=RGBA ! videoconvert ! video/x-raw,format=BGR ! fakesink

If yes, please try the string:

"rtspsrc location=rtsp://localhost:8554/001 ! rtph264depay ! h264parse ! nvv4l2decoder ! nvvideoconvert ! video/x-raw,format=RGBA ! videoconvert ! video/x-raw,format=BGR ! appsink"

@DaneLLL

It can work! that I wanted,thanks!

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