板载摄像头教程
板载摄像头教程
如何测试摄像头,打开Jetson 设备的终端
输入命令:nvgstcapture-1.0 ,摄像头就会起来了
此方法只能打开一个摄像头,且不容易关闭,非常麻烦.下面介绍使用python代码打开两路csi
摄像头的方法.
1.安装traitlets
首先记得查看自己的python版本,以python3.7为分界线。
python3.7以下用traitlets 4.x;(如未安装pip3,则应该首先安装pip3,安装命令为sudo apt install python3-pip)
pip3 install traitlets==4.3.3
python3.7以上才可以用traitlets 5.x
pip3 install traitlets
traitlets的历史版本https://pypi.org/project/traitlets/#history
2.安装Jetcam
参考官方github的内容https://github.com/NVIDIA-AI-IOT/jetcam
git clone https://github.com/NVIDIA-AI-IOT/jetcam
cd jetcam
sudo python3 setup.py install
3. 编写test.py代码
from jetcam.csi_camera import CSICamera
import cv2
camera0 = CSICamera(capture_device=0, width=224, height=224)
#camera1 = CSICamera(capture_device=1, width=224, height=224)
image0 = camera0.read()
print(image0.shape)
#image1 = camera1.read()
#print(image1.shape)
print(camera0.value.shape)
#print(camera1.value.shape)
while 1:
image0 = camera0.read()
#image1 = camera1.read()
cv2.imshow("CSI Camera0", image0)
#cv2.imshow("CSI Camera1", image1)
kk = cv2.waitKey(1)
if kk == ord('q'): # 按下 q 键,退出
break
4. 执行该代码 python3 test.py.