What does detectNet return when NOTHING is being detected?

Hello, I am trying to make a program that as soon as it detects a human, a snapshot of the current frame is taken. In order to do this, I need to know what is being returned from net.Detect(img) when NOTHING is being detected and no boxes are being drawn. Here is the code I have so far:

import jetson.inference
import jetson.utils
#import keyboard
import time

def take_picture(img):
	jetson.utils.cudaDeviceSynchronize()
	timestr = time.strftime("%Y%m%d-%H%M%S")
	jetson.utils.saveImageRGBA("outputs/"+timestr+".JPG",img, img.width, img.height)
	


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


p_flag = 0

while display.IsStreaming():
	img = camera.Capture()
	detections = net.Detect(img)
	display.Render(img)
	display.SetStatus("Object Detection | Network {:.0f} FPS".format(net.GetNetworkFPS()))
	if detections is None:
		print("None")

	for detection in detections:
		#if detection is a person and flag is 0, print person and take picture. Then set 			flag to 1 (to avoid continous picture taking)
		if net.GetClassDesc(detection.ClassID) == "person":
			
			if p_flag == 0:
				print(net.GetClassDesc(detection.ClassID))
				take_picture(img)
				p_flag=1

		#If detection is not a person, meaning the detection has changed, set flag back to 			0, making it ready to take a snapshot once human is detected again.	
		elif net.GetClassDesc(detection.ClassID) is None:
			print("Nothing")
		else:
			print(net.GetClassDesc(detection.ClassID))
			p_flag=0
	
	

If I know what is stored in detection.ClassID or net.Detect(img) when nothing is being detected, I think this would be possible. Any help?

Hi,

The output returns a list object.
So you can find if there is nothing detected via checking the list length.

Ex.

detections = net.Detect(img)
if len(detections) == 0:
    print("Nothing is detected!")

Thanks.

okay, thank you! that works.

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