Jetson Nano——使用JetCam官方库调用双CSI摄像头

环境准备

参考官方配置方案

git clone https://github.com/NVIDIA-AI-IOT/jetcam
cd jetcam
sudo python3 setup.py install

即可完成库的下载和安装。

报错No nodule named ‘traitlets’

若遇到该报错:
在这里插入图片描述

pip3 install traitlets

安装该包即可。

CSI摄像头测试代码

若只有一个CSI摄像头,将camera1相关的代码注释掉即可。

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
    点赞
  • 44
    收藏
    觉得还不错? 一键收藏
  • 12
    评论
Jetson Nano 使用 CSI (Camera Serial Interface) 接口连接摄像头。要在 Jetson Nano 上使用 CSI 摄像头,您需要使用 NVIDIA JetPack SDK 安装相应的软件和驱动程序,并编写相应的 C 代码来访问和控制摄像头。 以下是一些基本的步骤,可以帮助您开始使用 CSI 摄像头: 1. 安装 JetPack SDK:JetPack SDK 包含了 NVIDIA Jetson Nano 的所有软件和驱动程序。您可以从 NVIDIA 的官方网站上下载 JetPack SDK,并按照指南进行安装。 2. 连接 CSI 摄像头:将 CSI 摄像头插入 Jetson Nano 的 CSI 接口。 3. 编写 C 代码:使用 GStreamer 编写 C 代码来访问和控制摄像头。GStreamer 是一种流媒体框架,可以帮助您在 Jetson Nano 上捕获和处理视频流。您可以使用 GStreamer 的 nvarguscamerasrc 插件来访问 CSI 摄像头。 以下是一个简单的 C 代码示例,可以使用 nvarguscamerasrc 插件捕获 CSI 摄像头的视频流: ```c #include <gst/gst.h> int main(int argc, char* argv[]) { GstElement *pipeline, *source, *sink; GstBus *bus; GstMessage *msg; GstStateChangeReturn ret; /* Initialize GStreamer */ gst_init(&argc, &argv); /* Create the elements */ source = gst_element_factory_make("nvarguscamerasrc", "source"); sink = gst_element_factory_make("nveglglessink", "sink"); /* Create the empty pipeline */ pipeline = gst_pipeline_new("test-pipeline"); if (!pipeline || !source || !sink) { g_printerr("Not all elements could be created.\n"); return -1; } /* Build the pipeline */ gst_bin_add_many(GST_BIN(pipeline), source, sink, NULL); if (gst_element_link(source, sink) != TRUE) { g_printerr("Elements could not be linked.\n"); gst_object_unref(pipeline); return -1; } /* Start playing */ ret = gst_element_set_state(pipeline, GST_STATE_PLAYING); if (ret == GST_STATE_CHANGE_FAILURE) { g_printerr("Unable to set the pipeline to the playing state.\n"); gst_object_unref(pipeline); return -1; } /* Wait until error or EOS */ bus = gst_element_get_bus(pipeline); msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS); /* Parse message */ if (msg != NULL) { GError *err; gchar *debug_info; switch (GST_MESSAGE_TYPE(msg)) { case GST_MESSAGE_ERROR: gst_message_parse_error(msg, &err, &debug_info); g_printerr("Error received from element %s: %s\n", GST_OBJECT_NAME(msg->src), err->message); g_printerr("Debugging information: %s\n", debug_info ? debug_info : "none"); g_clear_error(&err); g_free(debug_info); break; case GST_MESSAGE_EOS: g_print("End-Of-Stream reached.\n"); break; default: /* We should not reach here because we only asked for ERRORs and EOS */ g_printerr("Unexpected message received.\n"); break; } gst_message_unref(msg); } /* Free resources */ gst_object_unref(bus); gst_element_set_state(pipeline, GST_STATE_NULL); gst_object_unref(pipeline); return 0; } ``` 4. 编译和运行代码:使用 gcc 编译上述 C 代码,并在 Jetson Nano 上运行它。您应该能够看到 CSI 摄像头的视频流在屏幕上显示出来。 请注意,上述代码仅仅是一个简单的示例。如果您需要更复杂的功能,例如捕获图像、处理视频流等,请参考 GStreamer 的官方文档,并编写相应的 C 代码来实现您的需求。
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值