Hello! How can I modify detectnet.py to save the detected image to my local drive?
Hi,
detectnet.py by default supports using images as input.
For example:
https://github.com/dusty-nv/jetson-inference/blob/master/docs/detectnet-console-2.md#detecting-objects-from-images
$ ./detectnet.py --network=ssd-mobilenet-v2 images/peds_0.jpg images/test/output.jpg
You can change the images/peds_0.jpg
to the path of your images on the local drive.
Thanks.
1 Like
Hi AastaLL,
Thank you for the response. But what I mean is that I am running my model on a live camera stream, and I want to save an image every time something is detected and save it to my local drive.
I saw from another topic that I can use detectnet-snap.py
. I tried running the code, and it worked, but when I view the directory where the images should be stored, no file is saved.
Reference topic: Snap Image when detection (without bounding box) and save into a folder
#!/usr/bin/env python3
#
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
This file has been truncated. show original
Hi,
Is there any error message output when saving the image?
Could you also try to use the absolute path in the below link to see if it works?
print("detected {:d} objects in image".format(len(detections)))
timestamp = datetime.datetime.now().strftime(args.timestamp)
for idx, detection in enumerate(detections):
print(detection)
roi = (int(detection.Left), int(detection.Top), int(detection.Right), int(detection.Bottom))
snapshot = cudaAllocMapped(width=roi[2]-roi[0], height=roi[3]-roi[1], format=img.format)
cudaCrop(img, snapshot, roi)
cudaDeviceSynchronize()
saveImage(os.path.join(args.snapshots, f"{timestamp}-{idx}.jpg"), snapshot)
del snapshot
# render the image
output.Render(img)
# update the title bar
output.SetStatus("{:s} | Network {:.0f} FPS".format(args.network, net.GetNetworkFPS()))
# print out performance info
net.PrintProfilerTimes()
Thanks.
Hello,
I have already tried running the code without specifying my own directory or using the --snapshots
option.
Below is the output when running the code with the default path:
And here is the result when I attempted to locate the default path:
Thank you for your assistance!
Hi
Could you search the file to see where it is stored?
$ sudo find / -iname 20250102-155717-532264-0.jpg
It should be under the build folder or beside the binary location.
Thanks.
system
Closed
February 26, 2025, 12:52am
10
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.