Sir,
I created a new model and want to use it for detection using a csi cam . but it shows following error. The program is given below
import time
import numpy as np
import jetson.inference
import jetson.utils
import cv2
#from adafruit_servokit import ServoKit
#myKit=ServoKit(channels=16)
arm=0
pan=90
#tilt=90
#myKit.servo[1].angle=arm
#myKit.servo[0].angle=pan
#myKit.servo[2].angle=tilt
dispW=640
dispH=480
flip=2
net = jetson.inference.detectNet(argv=[“–model=/home/manpreet/jetson-inference/python/training/detection/ssd/models/ricearducam/ssd-mobilenet.onnx”, “–labels=/home/manpreet/jetson-inference/python/training/detection/ssd/models/ricearducam/labels.txt”, “–input-blob=input_0”, “–output-cvg=scores”, “–output-bbox=boxes”],threshold=0.5)
#cam = cv2.VideoCapture(‘/dev/video0’)
cap= cv2.VideoCapture(‘csi://0’)
width=cap.get(cv2.CAP_PROP_FRAME_WIDTH)
height=cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
print(‘width:’,width,‘height:’,height)
#display = jetson.utils.videoOutput(“display://0”)
while True:
#while display.IsStreaming() :
_,img = cap.read()
print(img)
frame=cv2.cvtColor(img,cv2.COLOR_BGR2RGBA).astype(np.float32)
frame=jetson.utils.cudaFromNumpy(frame)
detections = net.Detect(frame)
print("detected {:d} objects in image".format(len(detections)))
myKit.servo[1].angle=90
print("loop1")
for detection in detections:
#print(detection)
top=int(detection.Top)
left=int(detection.Left)
bottom=int(detection.Bottom)
right=int(detection.Right)
center=detection.Center
#item=net.GetClassDesc(ID)
print(top,left,bottom,right,center)
cv2.rectangle(img,(left,top),(right,bottom),(0,255,0),2)
objX=left+right/2
errorPan=objX-width/2
print(pan)
print(objX)
print(errorPan)
if abs(errorPan)>15:
pan=pan-errorPan/75
print("if loop 1 >15")
print(pan)
if pan>180:
pan=180
print("pan out of range")
if pan<0:
pan=0
print("pan out of range")
myKit.servo[0].angle=pan
#time.sleep(10)
print("loop2")
break
#time.sleep(2)
#display.Render(frame)
#display.SetStatus("Object Detection | Network {:.0f} FPS" .format(net.GetNetworkFPS()))
cv2.imshow('detCam',img)
cv2.moveWindow('detCam',0,0)
if cv2.waitKey(1)==ord('q'):
break
cap.release()
cv2.destroyAllWindows()
and the errors are
width: 0.0 height: 0.0
None
Traceback (most recent call last):
File “/home/manpreet/jetson-inference/python/training/detection/ssd/contour and detection2.py”, line 30, in
frame=cv2.cvtColor(img,cv2.COLOR_BGR2RGBA).astype(np.float32)
cv2.error: OpenCV(4.6.0) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function ‘cvtColor’
please kindly tel an appropriate solution as soon as possible.