最近开始学jetson nano,由于Jetson nano是arm核心的,有很多库和软件都不兼容,踩了很多坑,下面分享一下自己的经验。
1. VScode安装
由于Jetson nano性能比较有限,文本编译器我装的是VS code,由于核心是arm,官方下载的VScode不能用。从这个网站下载,选后缀带arm64的
2. pytorch安装
pytorch按几个博主的方法都容易出错,最后按着官方的方法进行安装,有问题可以多在英伟达平台上问,管理员回复频率很多。https://forums.developer.nvidia.com/t/pytorch-for-jetson-version-1-6-0-now-available/72048,我装的是1.6版本的。
首先下载1.6版本的whl,然后按照时把1.4换成自己下载的1.6,就行,安装torchvision的时候还要注意版本的匹配,第二句用git clone -b v0.7.0 https://github.com/pytorch/vision torchvision,倒数第三句如果是python3,记得用sudo python3 setup.py install
在安装的过程中,还会再从网上下载东西,我的网连接不上,我把源换成了清华源,就可以了,注意选择arm版本的,还有自己的ubuntu版本,jetson nano的版本是18.04,换成arm版本的操作是把图中的网址变成https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/
https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/
剩下的就没什么了,远程控制软件选自己喜欢的就行,我在Windows上用的pycharm远程链接。
4、用opencv调用摄像头
安装好板载摄像头后,使用nvgstcapture-1.0打开摄像头,测试。
没问题后用安装以下代码用opencv调用摄像头
import cv2
def gstreamer_pipeline(
capture_width=1280,
capture_height=720,
display_width=1280,
display_height=720,
framerate=60,
flip_method=0,
):
return (
"nvarguscamerasrc ! "
"video/x-raw(memory:NVMM), "
"width=(int)%d, height=(int)%d, "
"format=(string)NV12, framerate=(fraction)%d/1 ! "
"nvvidconv flip-method=%d ! "
"video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! "
"videoconvert ! "
"video/x-raw, format=(string)BGR ! appsink"
% (
capture_width,
capture_height,
framerate,
flip_method,
display_width,
display_height,
)
)
def show_camera():
cap = cv2.VideoCapture(gstreamer_pipeline(flip_method=0), cv2.CAP_GSTREAMER)
while cap.isOpened():
flag, img = cap.read()
cv2.imshow("CSI Camera", img)
kk = cv2.waitKey(1)
# do other things
if kk == ord('q'): # 按下 q 键,退出
break
cap.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
show_camera()
然后我一直用pycharm远程链接,这个代码怎么都跑不通,后来我在板子上用VScode跑通了,好像必须在板子上跑,不能远程连接跑(也可能是pycharm有问题)
配置环境配置了2天,希望能够帮助大家。