How to change the camera pixel formate from V4L2_PIX_FMT_SRGGB8 to V4L2_PIX_FMT_YUYV

Hello :
now i am trying to make the camera work under the opencv3.2.0.but now is the problem : pixel formate is bayer not yuv or any other formate acceped by opencv (cap_v4l.cpp)
i still try to make the opencv work independed from gstreamer.

thanks

question :
1,exec : “gst-lunch-0.1” the command line like “formate=(String)I420” means 420 yuv formate and how could the gstream change the formate?
2,i tried to modifide code like this :
opencv-3.2/modules/videoio/src/cap_v4l.cpp

static int autosetup_capture_mode_v4l2(CvCaptureCAM_V4L* capture) {
//in case palette is already set and works, no need to setup.
if(capture->palette != 0 and try_palette_v4l2(capture)){
return 0;
}
__u32 try_order = {
V4L2_PIX_FMT_BGR24,
V4L2_PIX_FMT_YVU420,
V4L2_PIX_FMT_YUV411P,
#ifdef HAVE_JPEG
V4L2_PIX_FMT_MJPEG,
V4L2_PIX_FMT_JPEG,
#endif
V4L2_PIX_FMT_YUYV,
V4L2_PIX_FMT_UYVY,
V4L2_PIX_FMT_SN9C10X,
V4L2_PIX_FMT_SBGGR8,
V4L2_PIX_FMT_SGBRG8,
V4L2_PIX_FMT_RGB24,
V4L2_PIX_FMT_Y16,
/* Bayer formats - see http://www.siliconimaging.com/RGB%20Bayer.htm */
V4L2_PIX_FMT_SRGGB8
};


}
nothings seemed to happened to the display window.

Hi edwardlu

  1. There’s no way to change the nvcamerasrc output format, except have convertor to change it.
  2. If your sensor is bayer and you want to capture it by v4l2 them you need to postprocess the RAW data and convert to the format you want. The V4L2 won’t do any convert it only capture what sensor output.

hello shaneCCC:

I know it would be a huge effort to make the V4L-lib work in Opencv,but I still want to know:
First of all,my camera is the one Jetson-TX1 it takes,I did not change any other type of CCD sensor.

1,how gstream nvcamerasrc get the video data? by what kind of API the linux offers?
2,Bayer formate is what I get by ioctl :VIDIOC_G_FMT,if I tried to set the formate by VIDIOC_S_FMT :YUV(442).It failed-:(

Current TX1 support two pipeline to get data from sensor. One is based on gstreamer framework to implement nvcamerasrc, this pipeline go to ISP and the source code are not public. Another it the V4L2 framework’s v4l2src this pipeline only can get the raw data from the sensor. That means If your senosr is bayer you only can get bayer data, otherwise you need a YUV sensor instead of bayer sensor(TX1 default sensor d0v5693 is bayer sensor ).