imagenet-camera gets reverse orientation image on TX2 with TR2.1

Hi,

imagenet-camera (detectnet-camera) gets 180 degree reverse orientation image on TX2 after the TX2 is installed the newest TR2.1 and jetpack3.1.

Is there a way to change back the image orientation?

Thanks

Hellow HuiW, can you try changing the nvvidconv flip-method=2 parameter from gstCamera.cpp:313 and recompiling? This is the line:

ss << "nvcamerasrc fpsRange=\"30.0 30.0\" ! video/x-raw(memory:NVMM), width=(int)" << mWidth << ", height=(int)" << mHeight << ", format=(string)NV12 ! nvvidconv flip-method=2 ! ";

Can you report if flip-method=0 aligns the image correctly for you, or if not, which value is correct in your case?

Hi dusty_nv,

Thank you for your prompt support.
Yes. flip-method=0 aligns the image correctly.
May we know what causes the different?
Due to Tx2 R27.1 with JP 3.0, flip-method=2 aligns the image correctly.

Thanks

It appears the flip-method parameter value causes different alignments between R27 and R28. I’ve checked in a fix to master here, an #ifdef based on if JetPack 3.1 is detected or not:

https://github.com/dusty-nv/jetson-inference/blob/29b7c6828f8ca6d6a81e5b1e23b3b5847e1a9877/util/camera/gstCamera.cpp#L314

If the onboard camera image is still incorrectly flipped or aligned for you, please let me know.

Wouldn’t it be better to fix whatever the underlying cause of the flipping is?
Patching it up only in gstreamer doesn’t seem like the right place to fix it to me.

In fact it has been fixed in the right place in R28.1. Now nvcamerasrc sends the camera image upside up, while previously it was upside down. Thus it was previously requiring to rotate 180 degrees, and this was done by nvvidconv flip-method=2.
From R28.1, it is no longer required, and using flip-method=2 would make the image upside down again. So, flip-method=0 (no image transform) is now correct.

[EDIT: Sorry I misunderstoood your question. I don’t know yet about image orientation on R28.1 with other way than gstreamer, but having this is fine for gstreamer at least. I agree however fixing the root cause is usually better.]

Yes, technically the flip-method enumeration is now ‘correct’ in L4T/gstreamer, in that flip-method=0 aligns the image in the natural way and doesn’t need further specification. It was in older releases that flip-method=2 was required to get the correct alignment. So technically it is fixed in L4T now…

Gotcha! Appreciate the answer.

Hi,
Just wanted to update that for me the below setting made my camera upright.

if( onboardCamera() && src != GST_SOURCE_V4L2 )
{
mSource = src; // store camera source method

#if NV_TENSORRT_MAJOR > 1 && NV_TENSORRT_MAJOR < 5	// if JetPack 3.1-3.3 (different flip-method)
	const int flipMethod = 0;					// Xavier (w/TRT5) camera is mounted inverted
#else
	const int flipMethod = 0;

Hello,

the camera feed on my TX2 comes in flipped upside-down when I run:

./imagenet-camera googlenet

I checked gstCamera.cpp lines 314-317 which read:

#if NV_TENSORRT_MAJOR > 1 && NV_TENSORRT_MAJOR < 5	// if JetPack 3.1-3.3 (different flip-method)
	const int flipMethod = 0;					// Xavier (w/TRT5) camera is mounted inverted
#else
	const int flipMethod = 2;
#endif	

I tried to change the flipMethod from “= 2” to “= 0” but no luck. Attempted change read:

#if NV_TENSORRT_MAJOR > 1 && NV_TENSORRT_MAJOR < 5	// if JetPack 3.1-3.3 (different flip-method)
	const int flipMethod = 0;					// Xavier (w/TRT5) camera is mounted inverted
#else
	const int flipMethod = 0;
#endif	

Appreciate your help.
Thanks.

Hi Kraggle, if you are using JetPack 4.2, please try changing both flipMethod to =2 to see if that helps please.

The camera module is mounted upright on TX2 devkit and upside down on Xavier Xavier devkit.

Hi Dusty, thanks. I tried, but no luck.

Are you using MIPI CSI camera or a USB webcam (V4L2)? The flip-method parameter is only relevant to MIPI CSI camera.

If you’re using MIPI CSI, are you sure you tried changing both flipMethod variables between lines 314-317 and recompiled? You need to compile from the build directory because the camera stuff is in a utility library:

$ cd jetson-inference/build
$ make

Or if no joy, make clean and then make.

You can try different values of flipMethod until you see a change.

Thanks…yeah, using the on board MIPI CSI camera.

I went to build and compile gstCamera.cpp in jetson-inference/utils/camera after making the “flipMethod = 2” on lines 345 and 347

get the error:

In file included from gstCamer.cpp:23:0:
gstCamera.h:26:10: fatal error: gst/gst.h: No such file or directory
#include <gst/gst.h>
^~~~~~~~~~~
compilation terminated.
Compilation failed.

Since you were able to build the repo before, that is strange that you are getting this error about finding GStreamer header now. Were you trying to just build gstCamera.cpp, or the top-level jetson-inference project? You should build from jetson-inference, because it’s CMakeLists sets up the compiler with the correct include directories:

cd jetson-inference/build
cmake ../
make
1 Like

Thanks Dusty…I built the top-level jetson-inference project, using:

cd jetson-inference/build
cmake../
make

Then, working through the tutorial: https://github.com/dusty-nv/jetson-inference/blob/master/docs/imagenet-camera.md
while in:

/jetson-inference/build/aarch64/bin

ran:

./imagenet-camera googlenet

Video feed comes in upside down.

Then, used Geany to change the “flipMethod = 2” on lines 345 and 347 in gstCamera.cpp located in:

/jetson-inference/utils/camera

When attempting to build and compile gstCamera.cpp in Geany, get the error:

In file included from gstCamer.cpp:23:0:
gstCamera.h:26:10: fatal error: gst/gst.h: No such file or directory
#include <gst/gst.h>
^~~~~~~~~~~
compilation terminated.
Compilation failed.

Thanks Dusty…I built the top-level jetson-inference project, using:

cd jetson-inference/build
cmake../
make

Then, working through the tutorial: https://github.com/dusty-nv/jetson-inference/blob/master/docs/imagenet-camera.md
while in:

/jetson-inference/build/aarch64/bin

ran:

./imagenet-camera googlenet

Video feed comes in upside down.

Then, used Geany to change the “flipMethod = 2” on lines 345 and 347 in gstCamera.cpp located in:

/jetson-inference/utils/camera

When attempting to build and compile gstCamera.cpp in Geany, get the error:

In file included from gstCamer.cpp:23:0:
gstCamera.h:26:10: fatal error: gst/gst.h: No such file or directory
#include <gst/gst.h>
^~~~~~~~~~~
compilation terminated.
Compilation failed.

@Kraggle its working fine for me with Jetpack 4.2 installed on a Jetson TX2.

  1. set flipMethod to 0 in the file utils/camera/gstCamera.cpp:
#if NV_TENSORRT_MAJOR > 1 && NV_TENSORRT_MAJOR < 5      // if JetPack 3.1-3.3 (different flip-method)
                const int flipMethod = 0;                                       // Xavier (w/TRT5) camera is mounted inverted
        #else
                const int flipMethod = 0;
        #endif
  1. go to:
cd jetson-inference/build
make clean
make
sudo make install
  1. run imagenet-camera and you should see the video feed in the right orientation.

I had similar issues of inverted images with the CSI camera on-board my jetson TX2 while working with jetson-inference using JetPack 4.2.1. Definitely my TensorRT version is >= 5.1. To fix it I went to loc 413-417 file (jetson-inference/utils/camera/gstCamera.cpp

409         if( csiCamera() && src != GST_SOURCE_V4L2 )
410         {
411                 mSource = src;   // store camera source method
412 
413         #if NV_TENSORRT_MAJOR > 1 && NV_TENSORRT_MAJOR < 5      // if JetPack 3.1-3.3 (different flip-method)
414                 const int flipMethod = 0;                                       // Xavier (w/TRT5) camera is mounted inverted
415         #else
416                <b> const int flipMethod = 2;</b>
417         #endif

And changed line 416
from

const int flipMethod = 2;

to

const int flipMethod = 0;

After that I recompiled and installed
[i]

  1. cd jetson-inference/build
  2. cd cmake ..
  3. cd make
  4. cd sudo make install #Update the programs like imagenet-camera to be available from anywhere

[/i]

Voila!! my Camera images were upright and expected. No need for turning my head round again.

It seems flipMethod needs to be “0” for TX2.

@dusty-nv In feature can we have a FLIP_METHOD or FLIP_ORIENTATION macro (or something like that) in the gstCamera.h for flexibility. or probabaly an enum for most of the boards e.g {FLIP_METHOD_TX2 , FLIP_METHOD_TX1,…}

Hope this helps someone

Hi Dusty_NV

Embarrassed to admit but I have this same issue (my onboard camera image is upside down when trying things like ( ./imagenet-camera.py) using my TX2 dev kit.

I am so new and clueless even reading your instructions on how to address the issue I am still at a loss. Just trying to make my way through Hello AI World.

Can you please direct me on how to change the nvvidcon flip-method=2 parameter from gst.Camera.cpp:313 and recompile?

No clue. Thanks to anyone to can assist or even point me <in right direction.