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

Posted chay

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TX2 上使用opencv 调用板载mipi摄像头相关的知识,希望对你有一定的参考价值。

安装支持Gsteramer的opencv

删除OpenCV4Tegra:

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
    }
}

以上是关于TX2 上使用opencv 调用板载mipi摄像头的主要内容,如果未能解决你的问题,请参考以下文章

在Jetson TX2上捕获显示摄像头视频

Jetson TX2opencv3 打开usb摄像头

ROS小车打造--Jetson TX2安装与调试

opencv安装在TX2上如何卸载并安装opencv

树莓派mipi-csi接口针脚定义是啥?

在Jetson TX2上安装OpenCV(3.4.0)