Capturing images using jetson. inference library

Sir,
I want to make a python program for capturing images using a raspberry pi camera with jetson inference library. The camera is connected with Jetson Nano developer kit. The camera should capture image in every 5 seconds when it is displaying video. Also the images need to be saved. Is there any way ?
Please respond as soon as possible.

Hi @jino.joy.m, yes, just save the image with jetson_utils.saveImage() function every 5 seconds. For example, modifying the video-viewer.py sample:

import sys
import time
import argparse

from jetson_utils import videoSource, videoOutput, saveImage, Log

# parse command line
parser = argparse.ArgumentParser(description="View various types of video streams", 
                                 formatter_class=argparse.RawTextHelpFormatter, 
                                 epilog=videoSource.Usage() + videoOutput.Usage() + Log.Usage())

parser.add_argument("input", type=str, help="URI of the input stream")
parser.add_argument("output", type=str, default="", nargs='?', help="URI of the output stream")

try:
	args = parser.parse_known_args()[0]
except:
	print("")
	parser.print_help()
	sys.exit(0)

# create video sources & outputs
input = videoSource(args.input, argv=sys.argv)    # default:  options={'width': 1280, 'height': 720, 'framerate': 30}
output = videoOutput(args.output, argv=sys.argv)  # default:  options={'width': 1280, 'height': 720, 'framerate': 30}

# capture frames until EOS or user exits
numFrames = 0
lastSaveTime = time.perf_counter()

while True:
    # capture the next image
    img = input.Capture()

    if img is None: # timeout
        continue  
    
    # added this code to save image every 5 seconds
    currentTime = time.perf_counter()

    if (currentTime - lastSaveTime) >= 5.0:
        saveImage(f"my_image_{numFrames}.jpg", img)
        lastSaveTime = currentTime

    if numFrames % 25 == 0 or numFrames < 15:
        Log.Verbose(f"video-viewer:  captured {numFrames} frames ({img.width} x {img.height})")
	
    numFrames += 1
	
    # render the image
    output.Render(img)
    
    # update the title bar
    output.SetStatus("Video Viewer | {:d}x{:d} | {:.1f} FPS".format(img.width, img.height, output.GetFrameRate()))
	
    # exit on input/output EOS
    if not input.IsStreaming() or not output.IsStreaming():
        break

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