Image damage if capture by v4l2

Hi bros,

I’m using jetson nano with csi port (adv7280m).
I can capture with opencv with index: 0, image verry well but FPS too low (~20fps)
But if i capture by opencv with device name: /dev/video0, have green damage image (~50fps)

I need higher fps.
Tested with cheese and gst-launch, everything work with 50fps

Please give me any suggest!

Hi hoanganhv1svm,

Thanks for reaching out!

You mentioned that when using gst-launch everything is working at 50fps. It’s actually possible to use GStreamer pipelines as an input to OpenCV. I’m happy to help with this.

Do you mind sharing the command you provided to gst-launch with success?

Best,
John

Hi jeybdub,

I tried some params with VideoCapture by opencv, element 1, 3 work but fps to low, element 2 (Capture UYVY data then convert to BGR) will capture but image damage with green screen:

1: cap = cv2.VideoCapture(0)
2: cap = cv2.VideoCapture("/dev/video0")
3: cap = cv2.VideoCapture(“v4l2src device=/dev/video0 ! videoscale ! videorate ! video/x-raw, width=640, height=480, framerate=50/1 ! videoconvert ! appsink”)

this is my gst command:

gst-launch-1.0 -v v4l2src device=/dev/video0 ! timeoverlay ! video/x-raw, framerate=50/1,width=720,height=576 ! xvimagesink

capture by v4l2 have image wrong like cap = cv2.VideoCapture("/dev/video0")

v4l2-ctl --set-fmt-video=width=720,height=576,pixelformat=UYVY --stream-mmap --stream-count=10 -d /dev/video0 --stream-to=frame.raw

Thanks.

In an attempt to replicate your gst-launch command in OpenCV, does the following work for you?

cap = cv2.VideoCapture('v4l2src device=/dev/video0 ! timeoverlay ! video/x-raw, framerate=50/1,width=720,height=576 ! videoconvert ! video/x-raw, format=BGR, width=720, height=576 ! appsink', cv2.CAP_GSTREAMER)

Apologies, I’m not set up to test this command. Please let me know if you run into any issues.

Best,
John

Hi jaybdud,

This is my code, every thing work. Only problem is fps to low, i’m capturing with gst and cheese have 50fps,. but on opencv only 17fps

The openCV pipeline have involve videoscale and videoconvert cold you confirm the gst-launch-1.0 with these two element to confirm the fps still able to 50.

Hi ShaneCCC,

I’m fixed, problem is Opencv Capture with YUYV but adv7280m output UYVY.

I need convert by my self. Now i can capture pretty image with 50fps

This is code:

`static void v4lconvert_uyvy_to_rgb24(const unsigned char *src,
unsigned char *dest,
int width, int height,
int stride)
{
int j;

while (--height >= 0) {
    for (j = 0; j + 1 < width; j += 2) {
        //must be reverse u-y because opencv process pixel with BGR, not RGB
        int u = src[2];
        int v = src[0];

        int u1 = (((u - 128) << 7) +  (u - 128)) >> 6;
        int rg = (((u - 128) << 1) +  (u - 128) +
                 ((v - 128) << 2) + ((v - 128) << 1)) >> 3;
        int v1 = (((v - 128) << 1) +  (v - 128)) >> 1;

        *dest++ = CLIP(src[1] + v1);
        *dest++ = CLIP(src[1] - rg);
        *dest++ = CLIP(src[1] + u1);

        *dest++ = CLIP(src[3] + v1);
        *dest++ = CLIP(src[3] - rg);
        *dest++ = CLIP(src[3] + u1); 
        
        src += 4;
    }
    src += stride - (width * 2);
}

}`

Good to know it.

Thanks.