Flip/rotate camera picture (Raspi Cam) with Python


I’m building my own RC car with Jetson Nano and the Raspberry Pi cam. I’m doing some experiments with the Jetbot examples to understand what I’ve to do (many thanks for the examples :-)).

But I’ve the problem, that I’ve to install the Raspberry Pi camera in “the wrong direction” because of the flat cable that I can’t fold, so that the videos and pictures are upside down.

I’m using the code snippet below to display the camera output in the Jupyter Notebook:

import traitlets
import ipywidgets.widgets as widgets
from IPython.display import display
from jetbot import Camera, bgr8_to_jpeg

camera = Camera.instance(width=224, height=224)
image = widgets.Image(format='jpeg', width=224, height=224)  # this width and height doesn't necessarily have to match the camera

camera_link = traitlets.dlink((camera, 'value'), (image, 'value'), transform=bgr8_to_jpeg)


I searched online and in this community, but I can’t find the solution to flip the camera output for that Python code.

I would be very pleased, if someone could help me.


Hi Orandus, what you can do is modify the camera code in JetBot to supply a flip-method parameter to the nvvidconv gstreamer element that it uses here:


What you want to do is change nvvidconv to nvvidconv flip-method=2

where flip-method=2 can be changed to different values depending on the transformation you desire. These are the values to flip-method parameter that you can try setting:

flip-method         : video flip methods
                        flags: readable, writable, controllable
                        Enum "GstNvVideoFlipMethod" Default: 0, "none"
                           (0): none             - Identity (no rotation)
                           (1): counterclockwise - Rotate counter-clockwise 90 degrees
                           (2): rotate-180       - Rotate 180 degrees
                           (3): clockwise        - Rotate clockwise 90 degrees
                           (4): horizontal-flip  - Flip horizontally
                           (5): upper-right-diagonal - Flip across upper right/lower left diagonal
                           (6): vertical-flip    - Flip vertically
                           (7): upper-left-diagonal - Flip across upper left/lower right diagonal
1 Like

Hi dusty,

thanks for your help again!

I changed it in the sources, made a

sudo python3 setup.py install

restarted the Jupyter kernel and the video output was flipped.


Hi both,

I would also like to do this but have a silly question.how do I actually open camera.py to modify Camera? I looked in the Jupyter notebook and plugged it back into a monitor but can’t find it anywhere.