Sir,
I’m trying a python program for object detection using raspberry pi cam. But it is showing the following error. The python program is given below .
import time
import serial
import numpy as np
import jetson.inference
import jetson.utils
import cv2
#from adafruit_servokit import ServoKit
#myKit=ServoKit(channels=16)
#arm
pan=0
#tilt=90
#myKit.servo[1].angle=armq
#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/rice3/ssd-mobilenet.onnx”, “–labels=/home/manpreet/jetson-inference/python/training/detection/ssd/models/rice3/labels.txt”, “–input-blob=input_0”, “–output-cvg=scores”, “–output-bbox=boxes”],threshold=0.5)
cam = cv2.VideoCapture(‘csi://0’)
#camset= (‘gst-launch-1.0 nvarguscamerasrc ! video/x-raw(memory:NVMM),width=1920,height=1080,format=NV12 ! nvvidconv ! fpsdisplaysink video-sink=fakesink --verbose’)
#camset=(‘gst-launch-1.0 -v v4l2src device=csi://0 ! video/x-raw,framerate=30/1,width=1280,height=720 ! nvvidconv ! xvimagesink’)
#cam = cv2.VideoCapture(camset)
#cam = cv2.VideoCapture(“nvarguscamerasrc ! nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink”,)
width=cam.get(cv2.CAP_PROP_FRAME_WIDTH)
height=cam.get(cv2.CAP_PROP_FRAME_HEIGHT)
print(‘width:’,width,‘height:’,height)
#display = jetson.utils.videoOutput(“display://0”)
while True:
#while display.IsStreaming() :
_,img = cam.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”)
arduino = serial.Serial(‘/dev/ttyACM0’,115200)
#arduino = serial.Serial(‘/dev/ttyUSB0’,115200)
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-left)/2
errorPan=objX-width/2
print(pan)
print(objX)
print(errorPan)
arduino.write((str(errorPan)).encode(‘utf-8’))
if abs(errorPan)>15:
pan=pan-errorPan/75
print(“if loop 1 >15”)
print(pan)
#else:
#time.sleep(4)
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
print(“loop2”)
#time.sleep(4)
break
#time.sleep(3)
#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
cam.release()
cv2.destroyAllWindows()
And the error shown is…
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 33, 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 reply if anyone could find any solution.