rotating 90 degree image in python jetson inference


I need to use wider angle in vertical dimension, therefore, I need to rotate the captured image 90 degrees like a matrix transpose (swaping rows and columns) and then pass the image into mobilnet v2 object detection.

when I tried the jetson inference detectnet_camera c++ example, I managed to achieve this 90 degree rotation (matrix transposition) by modifying the cuda function RGBToRGBAf in by introducing a separate pixelT index where raster scan the target image vertically instead of horizontally:

template<bool isBGR>
__global__ void RGBToRGBAf(uchar3* srcImage,
                           float4* dstImage,
                           int width, int height)
	const int x = (blockIdx.x * blockDim.x) + threadIdx.x;
	const int y = (blockIdx.y * blockDim.y) + threadIdx.y;
	const int pixel = y * width + x;
        <u><i><b>const int pixelT = x * height + y;</b></i></u>

	if( x >= width )

	if( y >= height )

//	printf("cuda thread %i %i  %i %i pixel %i \n", x, y, width, height, pixel);
	const float  s  = 1.0f;
	const uchar3 px = srcImage[pixel];
	if( isBGR )
		dstImage[pixel] = make_float4(px.z * s, px.y * s, px.x * s, 255.0f * s);
		dstImage[<u><b><i>pixelT</i></b></u>] = make_float4(px.x * s, px.y * s, px.z * s, 255.0f * s);

I also swaped width and height in detectNet.cpp and detectnet_camera.cpp

I tried to acheive the same effect on python branch of jetson inference; however, changing the and swaping width and height in function captureRGBA in PyCamera module does not make any effect at all?

I even tried to set pixel values to fixed colour in function RGBToRGBAf by seting RGB values into make_float4() function, but it seems that it does not have any effect?

I did make clean and then make, but no effect? Any idea what might be the problem?


Hi am_merati, it seems you are using USB webcam, since that RGBtoRGBAf CUDA kernel is only used for USB webcams. Is that correct?

Before applying your changes to the python branch, are you able to view your camera feed from

See the command line arguments that it parses, if using USB camera you would need to launch with the --v4l2_device=N argument, where N is the index of your /dev/videoN device. You may also need to set the --width and --height arguments to a resolution supported by your camera.

Hi Dustin,

Thanks for the reply. at the moment I only need to do this for USB and that’s why I only made the change for USB part.

I can view the camera feed successfuly, using
$./ --vl42_device=0 --width=176 --height=144

I can view it with other width and height.
Images are normal and not 90 degree rotated as I needed for for

I guess this does not uses the RGB2RGBAf CUDA kernel? or it does and I am not see the effect of rotation?


Hmm yes, it should be using RGBToRGBAf CUDA kernel, otherwise you wouldn’t be seeing the video correctly.

Did you do a “sudo make install” after you made your modifications?
“sudo make install” is required for the Python bindings to work, and it causes the other apps to link to the installed version of the libraries.

Do you see your modification when you try running the non-Python camera-viewer app? (you will need to change the DEFAULT_CAMERA define to #define DEFAULT_CAMERA 0 in /utils/camera/camera-viewer/camera-viewer.cpp)

If you still have no luck, I would try inserting printf’s inside the RGBToRGBAf CUDA kernel and also the cudaRGB8ToRGBA32() function to make sure your build of them is being called.

The issue was caused by not doing $sudo make install.
it was resolved after $sudo make install

Many thanks for your help.

Ah gotcha, ok cool. I tend to just do “sudo make install” every time now, because it internally runs “make” first for you :)