Hello,
I’m trying to write a program where on pressing the pushbutton once the detectnet.py program starts running and pressing the pushbutton once more the program should stop working.
I have attached the program below:
import sys
import argparse
import RPi.GPIO as GPIO
import jetson_inference
import jetson_utils
from jetson_inference import detectNet
from jetson_utils import videoSource, videoOutput, logUsage
GPIO.setmode(GPIO.BOARD)
inputPin=15
buttonStateOld=True
GPIO.setup(inputPin,GPIO.IN)
# parse the command line
parser = argparse.ArgumentParser(description="Locate objects in a live camera stream using an object detection DNN.",
formatter_class=argparse.RawTextHelpFormatter,
epilog=detectNet.Usage() + videoSource.Usage() + videoOutput.Usage() + logUsage())
parser.add_argument("input_URI", type=str, default="", nargs='?', help="URI of the input stream")
parser.add_argument("output_URI", type=str, default="", nargs='?', help="URI of the output stream")
parser.add_argument("--network", type=str, default="ssd-mobilenet-v2", help="pre-trained model to load (see below for options)")
parser.add_argument("--overlay", type=str, default="box,labels,conf", help="detection overlay flags (e.g. --overlay=box,labels,conf)\nvalid combinations are: 'box', 'labels', 'conf', 'none'")
parser.add_argument("--threshold", type=float, default=0.5, help="minimum detection threshold to use")
is_headless = ["--headless"] if sys.argv[0].find('console.py') != -1 else [""]
try:
args = parser.parse_known_args()[0]
except:
print("")
parser.print_help()
sys.exit(0)
# create video sources and outputs
input = videoSource(args.input_URI, argv=sys.argv)
output = videoOutput(args.output_URI, argv=sys.argv+is_headless)
net = detectNet(model="/home/jetson/jetson-inference/python/training/detection/ssd/models/One_Label/ssd-mobilenet.onnx", labels="/home/jetson/jetson-inference/python/training/detection/ssd/models/One_Label/labels.txt", input_blob="input_0", output_cvg="scores", output_bbox="boxes", threshold=0.5)
# process frames until the user exits
while (1==1):
buttonStateNew=GPIO.input(inputPin)
if buttonStateOld==True and buttonStateNew==False:
img = input.Capture()
# detect objects in the image (with overlay)
detections = net.Detect(img, overlay=args.overlay)
# print the detections
print("detected {:d} objects in image".format(len(detections)))
for detection in detections:
print(detection)
# 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()
# exit on input/output EOS
if not input.IsStreaming() or not output.IsStreaming():
break
x=GPIO.input(inputPin)
print(x)
buttonStateOld=buttonStateNew
My Output:
The program stops working by showing the following statement:
[TRT] didn’t load expected number of class colors (0 of 2)
[TRT] filling in remaining 2 class colors with default colors
Is there anyway this program can be modified so that on pressing the pushbutton once the detectnet.py program starts running and pressing the pushbutton once more the program should stop working?