• TX2 上使用opencv 调用板载mipi摄像头


    使用命令测试

    gst-launch-1.0 nvcamerasrc ! 'video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)I420, framerate=(fraction)60/1' ! nvvidconv ! 'video/x-raw(memory:NVMM), format=(string)I420' ! nvoverlaysink -e
    

    安装支持Gsteramer的opencv

    删除OpenCV4Tegra:
    如果已经安装了系统自带的opencv 需要先进行卸载:

    sudo apt-get purge libopencv4tegra-dev libopencv4tegra
    sudo apt-get purge libopencv4tegra-repo
    sudo apt-get update
    

    下载Jetson TX2 OpenCV安装程序:

    git clone https://github.com/jetsonhacks/buildOpenCVTX2.git
    cd buildOpenCVTX2
    

    打开buildOpenCV.sh并将 -DWITH_GSTREAMER = OFF 更改为-DWITH_GSTREAMER = ON,确保OpenCV编译时使用gstreamer支持。
    构建OpenCV:

    ./buildOpenCV.sh
    cd 〜/opencv /build
    sudo make install
    

    测试程序

    #include <opencv2/opencv.hpp>
    
    std::string get_tegra_pipeline(int width, int height, int fps) {
        return "nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)" + std::to_string(width) + ", height=(int)" +
                std::to_string(height) + ", format=(string)I420, framerate=(fraction)" + std::to_string(fps) +
                "/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink";
    }
    
    int main() {
        // Options
        int  WIDTH = 1920;
        int  HEIGHT = 1080;
        int FPS = 30;
    
        // Define the gstream pipeline
        std::string pipeline = get_tegra_pipeline(WIDTH, HEIGHT, FPS);
        std::cout << "Using pipeline: 
    	" << pipeline << "
    ";
    
        // Create OpenCV capture object, ensure it works.
        cv::VideoCapture cap(pipeline, cv::CAP_GSTREAMER);
        if (!cap.isOpened()) {
            std::cout << "Connection failed";
            return -1;
        }
    
        // View video
        cv::Mat frame;
        while (1) {
            cap >> frame;  // Get a new frame from camera
    
            // Display frame
            imshow("Display window", frame);
            cv::waitKey(1); //needed to show frame
        }
    }
    
    

    Makefile

    # build mipi opencv test
     
    CC = g++
    
    
    CFLAGS = -w -O3 -std=c++11
    
    SRCS = main.cpp 
    
    INC += -I /usr/include
    INC += -I `pkg-config --cflags opencv`
    
    
    LIBS += -L /usr/lib/ -lstdc++ 
    LIBS += `pkg-config --libs opencv`
    
    
    TARGET = test
    
    target:
    	$(CC) $(CFLAGS) -o  $(TARGET)   $(SRCS) $(INC) $(LIBS) 
    	#*****************finished building*****************
    
    clean:
    	rm -f $(TARGET)  
    
    
  • 相关阅读:
    ROXFiler 2.6
    ubuntu下lxr的运用
    NTFS3G-Linux 的 NTFS 驱动步骤
    Songbird 0.2.5 Final
    ePDFView:一个轻量的 PDF 文档阅读东西
    Gmail Notifier:又一个 Gmail 邮件通知法式
    Hybrid Share-文件分享软件
    Dolphin:KDE 中的文件管理器
    文泉驿点阵宋体 0.8(嬴政)正式公布
    KDE 4 Kludge 发布宣布
  • 原文地址:https://www.cnblogs.com/chay/p/10287902.html
Copyright © 2020-2023  润新知