Jetson TX2 摄像头读取

对于TX2来讲,若是你外接一个USB摄像头那么和在电脑上操做同样,可是要读取板上的摄像头就有点问题了,纠结了很久。app

首先测试一下摄像头,打开Jetson TX1的终端 写入命令:nvgstcapture-1.0 ,摄像头就会起来了ide

简单的使用了手册中的几个命令测试

  1. --prev_res 预览视屏的分辨率,高度和宽度,用的是CSI摄像头的话范围是 2 to 12 (5632x4224) e.g., nvgstcapture-1.0 --prev-res=3spa

  2. --cus-prev-res 自定义预览分辨率,宽度和高度,仅支持CSI摄像头 e.g., nvgstcapture-1.0 --cus-prev-res=1920x1080code

多个命令同时使用的话用!隔开 想关掉摄像头的额话,直接在终端输入q再按回车 想捕获图片的话,在终端输入j再按回车,图片将保存当前目录下orm


使用Opencv读取摄像头图片

记得必定要安装gstreamer这个依赖ip

#include <stdio.h>  
#include <opencv2/opencv.hpp>  
  
using namespace cv;  
using namespace std;  
  
int main(int argc, char** argv)  
{  
    VideoCapture cap("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720,format=(string)I420, framerate=(fraction)24/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink");  
    if (!cap.isOpened())  
    {  
        cout << "Failed to open camera." << endl;  
        return -1;  
    }  
  
    while(1)  
    {  
         Mat frame;  
        cap >> frame;  
        imshow("original", frame);  
        if((char)waitKey(30) == 27)  
            break;  
    }  
    return 0;  
}