Saving single frame from USB camera stream?

Hi, I right now have a python program that detects objects from live video stream, following Hello AI world and NVIDIA’s youtube channel. I have modified it so that on key “q” press, the class it is currently detecting is printed out to the terminal. However, I would like to modify it so that on button press, the current frame which is being streamed in should be captured and saved in some directory. Furthermore, I would like it so that on detecting a “person” it should save the frame and save it in a directory. I am struggling now with how to capture the frame. I just need to substitute the printing of the class with the “snapshot” and I will have the first step done. Any suggestions on how I can just take the current frame and save it as an image?

(I am a intern, still learning the basics of the nano and AI in general)


Suppose you are using jetson-utils as the camera interface.
If yes, you can save the image with OpenCV.

Below is an example for your reference:


import jetson.inference
import jetson.utils
import keyboard

net = jetson.inference.detectNet("ssd-mobilenet-v2", threshold=0.5)
camera = jetson.utils.videoSource("/dev/video0")      # '/dev/video0' for V4L2
display = jetson.utils.videoOutput("display://0") # 'my_video.mp4' for file

while display.IsStreaming():
	img = camera.Capture()
	detections = net.Detect(img)
	for detection in detections:
		if keyboard.is_pressed('q'):
	display.SetStatus("Object Detection | Network {:.0f} FPS".format(net.GetNetworkFPS()))

This is my current python script. Like in the example you showed, can i load the frame (from img = camera.Capture() ) into CUDA memory like line 39? Then convert it to BGR?

When trying to pass img from camera.Capture() to jetson.loadImage(img) this error pops up:

File “”, line 15, in
rgb_img = jetson.utils.loadImage(img)
Exception: jetson.utils – loadImage() failed to parse filename argument

It seems that you have already filed a new topic for the following.
Please check the topic directly.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.