Operate a PTZ cam using Jetson Nano

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.

Did you integrate the CSI sensor driver to your system?
Also did you verify the driver and HW by v4l2-ctl?

v4l2-ctl --list-devices
v4l2-ctl --stream-mmap --stream-count=100 --set-ctrl bypass_mode=0

The result was given like this
v4l2-ctl --list-devices
vi-output, imx219 7-0010 (platform:54080000.vi:0):
/dev/video0

manpreet@manpreet-desktop:~$ v4l2-ctl --stream-mmap --stream-count=100 --set-ctrl bypass_mode=0
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 60.39 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

If below command working well then you need to check the CV source to figure it out.

gst-launch-1.0 nvarguscamerasrc ! 'video/x-raw(memory:NVMM),width=1920,height=1080,format=NV12' ! nvvidconv ! fpsdisplaysink video-sink=fakesink --verbose

sir
I,m doing a project . I want to create my own detection models for rice seedlings. as a part of the project one of the independent parameter is pretrained model. so while during training how can I give various pretrained models . I searched a lot to get the pth files but only ssd mobilenet v1 and ssd mb2 lite is available. vgg16 ssd is available but it is giving result nan.pth

Hi,

Based on the output log, the image value is None.

width: 0.0 height: 0.0
None

This indicates that OpenCV cannot read your camera correctly.
Could you try to replace the below function with this pipeline and try it again?

cap= cv2.VideoCapture(‘csi://0’)

Thanks.

ok sir

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