Why opencv capture from gstreamer always get Grayscale images not RGB color?

I am a gstreamer new learner,maybe this question is very simple.but I can not solve it, I just want capture RGB color images but always grays . please…

#include <opencv2/opencv.hpp>
#include <opencv2/videoio.hpp>
using namespace cv;

#include
using namespace std;

int main()
{
std::string pipe = “rtspsrc location=rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4 ! rtph264depay ! h264parse ! nvv4l2decoder ! nvvideoconvert ! appsink”;

VideoCapture cap(pipe, CAP_GSTREAMER);

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

int count = 0;
while (true) {
    Mat frame;
    cap.read(frame);

    char tmp[16];
    sprintf(tmp, "pic/%d.jpg", ++count);

    imwrite(tmp, frame);
    printf("-----------------%d\n", count);
}

return 0;

}

OK,I solve it myself. by the way, how to transform NV12 to BGR format in gstreamer pipeline? someone help…

#include <opencv2/opencv.hpp>
#include <opencv2/videoio.hpp>
using namespace cv;

#include
using namespace std;

int main()
{
std::string pipe = “rtspsrc location=rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4 ! rtph264depay ! h264parse ! nvv4l2decoder ! nvvideoconvert ! video/x-raw, format=NV12 ! appsink”;

VideoCapture cap(pipe, CAP_GSTREAMER);

if (!cap.isOpened()) {
    cerr <<"VideoCapture not opened"<<endl;
    exit(-1);
}
int count = 0;
while (true) {
    Mat frame;
    cap.read(frame);
    cv::Mat dst(frame.rows * 2 / 3, frame.cols, CV_8UC3);
    cvtColor(frame, dst, cv::COLOR_YUV2BGR_NV12);
    char tmp[16];
    sprintf(tmp, "pic/%d.jpg", ++count);

    imwrite(tmp, dst);
    printf("-----------------%d\n", count);
}

return 0;

}