nvgstcapture-1.0
参考链接
IMX219相机型号和jetson的测试
nvgstcapture-1.0帮助文件
查看命令行微雪的帮助文档
我的相机型号
IMX219CSI摄像头,77°视角
查看相机的属性
查看相机
ls /dev/video*
使用v4l2-utils工具
#下载
sudo apt install v4l-utils
#查看设备信息
v4l2-ctl --list-devices
如果有多个摄像头,可以看到多个。
查看指定的摄像机的参数
v4l2-ctl --device=/dev/video0 --list-formats-ext
#查看设备0
RG10代表摄像头的数据格式
Name : 10-bit Bayer RGRG/GBGB
说明格式使用的算法与通道对应的参数。
import cv2
import numpy as np
camera=cv2.VideoCapture("nvarguscamerasrc \
! video/x-raw(memory:NVMM), width=640, height=480, framerate=30/1,format=NV12 \
! nvvidconv flip-method=0 !videoconvert\
! video/x-raw, format=BGR !appsink")
#指定输出文件名,这里指定为MPEG
# 这里等效'M','P','E','G'
fourccc=cv2.VideoWriter_fourcc(*'MPEG')
videoOut =cv2.VideoWriter('recorder.mp4',fourcc,30.0,(640,480))
# 预读第一帧
isRead,frame=camera.read()
while isRead:
# 逐帧写入
videoOut.write(frame)
# 将摄像头读入的图形显示在屏幕上
cv2.imshow('show',frame)
if cv2.waitKey()
在python中opencv的调用,查看视频流
这个是toptechboy的代码
B站视频有中文版jetson nano
import cv2
import numpy as np
import time
from adafruit_servokit import ServoKit
print(cv2.__version__)
timeMark=time.time()
dtFIL=0
kit=ServoKit(channels=16)
tilt=90
pan=90
dTilt=10
dPan=1
kit.servo[0].angle=pan
kit.servo[1].angle=tilt
kit.servo[2].angle=pan
kit.servo[3].angle=tilt
width=720
height=480
flip=2
font=cv2.FONT_HERSHEY_SIMPLEX
#相机的配置文件
camSet1='nvarguscamerasrc sensor-id=0 ee-mode=1 ee-strength=0 tnr-mode=2 tnr-strength=1 wbmode=3 ! video/x-raw(memory:NVMM), width=3264, height=2464, framerate=21/1,format=NV12 ! nvvidconv flip-method='+str(flip)+' ! video/x-raw, width='+str(width)+', height='+str(height)+', format=BGRx ! videoconvert ! video/x-raw, format=BGR ! videobalance contrast=1.3 brightness=-.2 saturation=1.2 ! appsink drop=True'
camSet2='nvarguscamerasrc sensor-id=1 ee-mode=1 ee-strength=0 tnr-mode=2 tnr-strength=1 wbmode=3 ! video/x-raw(memory:NVMM), width=3264, height=2464, framerate=21/1,format=NV12 ! nvvidconv flip-method='+str(flip)+' ! video/x-raw, width='+str(width)+', height='+str(height)+', format=BGRx ! videoconvert ! video/x-raw, format=BGR ! videobalance contrast=1.3 brightness=-.2 saturation=1.2 ! appsink drop=True'
#camSet='nvarguscamerasrc sensor-id=0 ! video/x-raw(memory:NVMM), width=3264, height=2464, framerate=21/1,format=NV12 ! nvvidconv flip-method='+str(flip)+' ! video/x-raw, width='+str(width)+', height='+str(height)+', format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink'
#camSet ='v4l2src device=/dev/video1 ! video/x-raw,width='+str(width)+',height='+str(height)+',framerate=20/1 ! videoconvert ! appsink'
cam1=cv2.VideoCapture(camSet1)
cam2=cv2.VideoCapture(camSet2)
while True:
_, frame1 = cam1.read()
_, frame2 = cam2.read()
frame3=np.hstack((frame1,frame2))
dt=time.time()-timeMark
timeMark=time.time()
dtFIL=.9*dtFIL + .1*dt
fps=1/dtFIL
cv2.rectangle(frame3,(0,0),(150,40),(0,0,255),-1)
cv2.putText(frame3,'fps: '+str(round(fps,1)),(0,30),font,1,(0,255,255),2)
print('fps: ',fps)
#cv2.imshow('myCam1',frame1)
#cv2.imshow('myCam2',frame2)
cv2.imshow('comboCam',frame3)
cv2.moveWindow('comboCam',0,450)
kit.servo[0].angle=pan
kit.servo[2].angle=pan
pan=pan+dPan
if pan>=179 or pan<=1:
dPan=dPan*(-1)
tilt=tilt+dTilt
kit.servo[1].angle=tilt
kit.servo[3].angle=tilt
if tilt>=169 or tilt<=11:
dTilt=dTilt*(-1)
if cv2.waitKey(1)==ord('q'):
break
cam.release()
cv2.destroyAllWindows()
相机的参数配置的说明
#在运行时如果出错会给出相机相应的配置信息,一般是相机的长宽,和帧率不对应
pipeline = '''nvarguscamerasrc !
video/x-raw(memory:NVMM), #使用缓存
width=1920, height=1080, #镜头初始拍摄的长和宽
format=NV12, framerate=30/1 ! #视频格式,和帧率一秒30帧
nvvidconv flip-method=0 ! #是否翻转返回的图像
video/x-raw, width=1920, height=1080, format=BGRx ! #返回的一些格式
videoconvert ! video/x-raw, format=BGR ! appsink''' #应该是视频格式是否转换
cap = cv2.VideoCapture(pipeline, cv2.CAP_GSTREAMER)
基础的代码CSI相机,此处可运行。
import cv2 as cv
print(cv.__version__)
dispW=640
dispH=480
flip=2
#如果是usb相机,使用下面的命令替换,参数配置
#cam_rgb = cv.VideoCapture(0) #多个相机的话,尝试不同的数字,默认是主机的相机
#设置宽高属性,默认是640*480
#cam_rgb.set(cv.CAP_PROP_FRAME_WIDTH,dispW)
#cam_rgb.set(cv.CAP_PROP_FRAME_HEIGHT,dispH)
camSet='nvarguscamerasrc ! video/x-raw(memory:NVMM), width=3264, height=2464, format=NV12, framerate=21/1 ! nvvidconv flip-method='+str(flip)+' ! video/x-raw, width='+str(dispW)+', height='+str(dispH)+', format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink'
cam=cv.VideoCapture(camSet)
while True:
ret, frame = cam.read()
cv.imshow('nanoCam',frame)
if cv.waitKey(1)==ord('q'):
break
cam.release()
cv.destroyAllWindows()