Video-viewer does not flip camera image

When I run video-viewer with:

video-viewer --input-width=640 --input-height=480 --input-flip=rotate-180 /dev/video0

the image does not flip. i tried two different USB cameras and other flip modes but it never does anything with the orientation of the image.

This is what it spits out before capturing:

gstCamera video options:

– URI: v4l2:///dev/video0
- protocol: v4l2
- location: /dev/video0
– deviceType: v4l2
– ioType: input
– codec: raw
– width: 640
– height: 480
– frameRate: 30.000000
– bitRate: 0
– numBuffers: 4
– zeroCopy: true
– flipMethod: rotate-180
– loop: 0
– rtspLatency 2000

[OpenGL] glDisplay – X screen 0 resolution: 1920x1080
[OpenGL] glDisplay – X window resolution: 1920x1080
[OpenGL] glDisplay – display device initialized (1920x1080)
[video] created glDisplay from display://0

glDisplay video options:

– URI: display://0
- protocol: display
- location: 0
– deviceType: display
– ioType: output
– codec: raw
– width: 1920
– height: 1080
– frameRate: 0.000000
– bitRate: 0
– numBuffers: 4
– zeroCopy: true
– flipMethod: none
– loop: 0
– rtspLatency 2000

[gstreamer] opening gstCamera for streaming, transitioning pipeline to GST_STATE_PLAYING
[gstreamer] gstreamer changed state from NULL to READY ==> mysink
[gstreamer] gstreamer changed state from NULL to READY ==> capsfilter0
[gstreamer] gstreamer changed state from NULL to READY ==> v4l2src0
[gstreamer] gstreamer changed state from NULL to READY ==> pipeline0
[gstreamer] gstreamer changed state from READY to PAUSED ==> capsfilter0
[gstreamer] gstreamer stream status CREATE ==> src
[gstreamer] gstreamer changed state from READY to PAUSED ==> v4l2src0
[gstreamer] gstreamer changed state from READY to PAUSED ==> pipeline0
[gstreamer] gstreamer stream status ENTER ==> src
[gstreamer] gstreamer message new-clock ==> pipeline0
[gstreamer] gstreamer changed state from PAUSED to PLAYING ==> capsfilter0
[gstreamer] gstreamer message stream-start ==> pipeline0
[gstreamer] gstreamer changed state from PAUSED to PLAYING ==> v4l2src0
video-viewer: failed to capture video frame
[gstreamer] gstCamera – onPreroll
[gstreamer] gstCamera recieve caps: video/x-raw, format=(string)YUY2, width=(int)640, height=(int)480, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1, colorimetry=(string)2:4:5:1, interlace-mode=(string)progressive
[gstreamer] gstCamera – recieved first frame, codec=raw format=yuyv width=640 height=480 size=614400
video-viewer: failed to capture video frame
RingBuffer – allocated 4 buffers (614400 bytes each, 2457600 bytes total)
[gstreamer] gstreamer changed state from READY to PAUSED ==> mysink
[gstreamer] gstreamer message async-done ==> pipeline0
[gstreamer] gstreamer changed state from PAUSED to PLAYING ==> mysink
[gstreamer] gstreamer changed state from PAUSED to PLAYING ==> pipeline0
RingBuffer – allocated 4 buffers (921600 bytes each, 3686400 bytes total)
video-viewer: captured 1 frames (640 x 480)
[OpenGL] glDisplay – set the window size to 640x480
[OpenGL] creating 640x480 texture (GL_RGB8 format, 921600 bytes)
[cuda] registered openGL texture for interop access (640x480, GL_RGB8, 921600 bytes)

I can’t figure out why it doesn’t work
, it seems to parse the parameter but then ignores it?

I’m running the latest image and have built jetson-inference from source a few days back.

Any ideas why it doesn’t work?

Oh snap, i just noticed an important detail in the docs:

–input-flip=FLIP flip method to apply to input (excludes V4L2):

So i guess i should ask a different question then. How do I flip an image coming from a USB camera from python?

You may want to try cv2.flip() - Python OpenCV – cv2.flip() method - GeeksforGeeks

You can use cudaToNumpy() and cudaFromNumpy() to get the image into numpy array and back again after done flipping.

Thank you.

In the end I modified the jetson-inference/utils/camera/gstCamera.cpp
Changed:
ss << “appsink name=mysink”;
to:
ss << “videoflip video-direction=180 ! appsink name=mysink”;

then went to jetson-inference/utils
and ran:
make
sudo make install

(for future reference) :)

Its not python, but it feels like its less overhead this way. I think im going to stick with it. Would be nice if we could just pass extra gstreamer stuff as an argument for V4L2 cameras.

OK cool, yes that is probably less overhead. Perhaps I could implement the --input-flip argument this way for V4L2 cameras too - thanks.