Jetson Nano Image Classification with OpenCV and Python
Introduction
This tutorial shows how to run Jetson Nano image classification with Python and OpenCV.
You will use the NVIDIA Jetson Inference library with GoogleNet to recognize objects in a single image.
The goal is to build a CUDA-accelerated pipeline that loads an image, classifies it on the GPU, and overlays the predicted class on the image.
You will learn how to convert an OpenCV image to a CUDA buffer using jetson.utils
, load a pretrained network with jetson.inference.imageNet
, and display results with OpenCV.
This workflow is optimized for Jetson Nano and focuses on speed, simplicity, and clarity for real projects.
The link for the video : https://youtu.be/x5kQAw0_fJc
You can find more similar tutorials in my blog posts page here : https://eranfeit.net/blog/
You can find more Nvidia Jetson Nano tutorials here : https://eranfeit.net/how-to-classify-objects-using-jetson-nano-inference-and-opencv/
You can find the full code here : https://ko-fi.com/s/7a72f61abe
Full code and step-by-step explanation for jetson nano python tutorial :
### Import OpenCV for image I/O and window display. import cv2 ### Import Jetson Inference high level APIs for classification. import jetson.inference ### Import Jetson Utils for CUDA image handling and conversions. import jetson.utils ### This code is tested with Python 3.6 on Jetson Nano for compatibility with Jetson packages. # Use Python 3.6 ### Load an input image from disk into a NumPy array in BGR format as used by OpenCV. img = cv2.imread('/home/feitdemo/github/Jetson-Nano-Python/dog-demo.jpg') ### Convert the BGR OpenCV image to RGBA because Jetson utilities expect RGBA when using cudaFromNumpy. frame_rgba = cv2.cvtColor(img,cv2.COLOR_BGR2RGBA) ### Upload the RGBA NumPy array to GPU memory as a CUDA image so it can be processed by the network. cude_frame = jetson.utils.cudaFromNumpy(frame_rgba) ### Create an image classification network using the pretrained GoogleNet model for fast inference on Jetson. net = jetson.inference.imageNet("googlenet") ### Run classification on the CUDA image and return the predicted class index and confidence score. class_id , confidence = net.Classify(cude_frame) ### Translate the numeric class ID into a human readable label for display or logging. class_desc = net.GetClassDesc(class_id) ### Draw the predicted class text onto the original OpenCV image so the result is visible. cv2.putText(img,class_desc,(30,80), cv2.FONT_HERSHEY_COMPLEX, 1, (255,0,0),4 ) ### Show the image in a window using OpenCV so you can verify the prediction visually. cv2.imshow('img',img) ### Move the window to the top left corner for consistent on-screen positioning during demos. cv2.moveWindow('img',0,0) # position of the windows and the left corner ### Block the script until a key is pressed so the window stays open to review results. cv2.waitKey()
You can find the full code here : https://ko-fi.com/s/7a72f61abe
Short summary.
You imported OpenCV and the Jetson libraries.
You loaded an image and converted it to RGBA.
You uploaded the frame to the GPU and classified it with GoogleNet.
You drew the label and displayed the window.
This pattern is the foundation for Jetson Nano image classification projects with Python and OpenCV.
Connect :
☕ Buy me a coffee — https://ko-fi.com/eranfeit
🖥️ Email : feitgemel@gmail.com
🤝 Fiverr : https://www.fiverr.com/s/mB3Pbb
Enjoy,
Eran