Ok thanks.
I will try to put it into my script.
I also tried the following changes to display the confidence value instead of the class name above the bounding boxes but it did not work (I wanted to show only the confidence to test if it works at all):
Edit:
CONF=detect.Confidence
Comment line one and use line two
#item=net.GetClassDesc(ID) # RUNS
item_CONF=net.GetClassDesc(CONF) #does NOT RUN
(Edit: CONF=detect.Confidence)
AND
Comment line one and use line two
#cv2.putText(img,item, (left,top+20),font,.8,(0,0,255),1) #RUNS
cv2.putText(img,item_CONF, (left,top+20),font,.8,(0,0,255),1) #does NOT RUN
You can see the entire code and the error below:
ENTIRE CODE
import jetson.inference
import jetson.utils
import time
import cv2
import numpy as np
timeStamp=time.time()
fpsFilt=0
net=jetson.inference.detectNet('ssd-mobilenet-v2',threshold=.4)
dispW=640
dispH=480
flip=2
font=cv2.FONT_HERSHEY_SIMPLEX
cam=cv2.VideoCapture('/usr/share/visionworks/sources/data/pedestrians.mp4')
cam.set(cv2.CAP_PROP_FRAME_WIDTH, dispW)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, dispH)
while True:
_,img = cam.read()
height=img.shape[0]
width=img.shape[1]
frame=cv2.cvtColor(img,cv2.COLOR_BGR2RGBA).astype(np.float32)
frame=jetson.utils.cudaFromNumpy(frame)
detections=net.Detect(frame, width, height)
for detect in detections:
ID=detect.ClassID
CONF=detect.Confidence
top=int(detect.Top)
left=int(detect.Left)
bottom=int(detect.Bottom)
right=int(detect.Right)
CONF_2="%.2f" % CONF
#item=net.GetClassDesc(ID) # RUNS
item_CONF=net.GetClassDesc(CONF) #does NOT RUN
# create Bounding Box
cv2.rectangle(img,(left,top),(right,bottom),(0,255,0),1)
#cv2.putText(img,item, (left,top+20),font,.8,(0,0,255),1) #RUNS
cv2.putText(img,item_CONF, (left,top+20),font,.8,(0,0,255),1) #does NOT RUN
print(item,top,left,bottom,right, CONF_2)
dt=time.time()-timeStamp
timeStamp=time.time()
fps=1/dt
fpsFilt=.9*fpsFilt + .1*fps
cv2.putText(img,str(round(fpsFilt,1))+' fps',(0,30),font,.8,(0,255,0),2)
cv2.imshow('detCam',img)
cv2.moveWindow('detCam',0,0)
if cv2.waitKey(1)==ord('q'):
break
cam.release()
cv2.destroyAllWindows()
ERROR
File "failure.py", line 41, in <module>
item_CONF=net.GetClassDesc(CONF) #does NOT RUN
Exception: jetson.inference -- detectNet.GetClassDesc() failed to parse arguments
Any idea what is going wrong?
Best regards
chris
Edit:
I had a look into Python: package jetson.inference
And GetClassDesc() is not intended to display the confidence. Is that right?