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;  
}
相關文章
相關標籤/搜索