jetson tx2 使用opencv的gstreamer

原因:由于刷机jetson tx2的jetpack安装的openCV4Tegra不支持gstreamer所以需要卸载jetpack安装的opencv安装支持gstreamer的opencv版本

已经在Jetson TX2上安装了JetPack-3.3(或JetPack-3.2.1或JetPack-3.1),更高版本的jetpack不能使用次方法

安装步骤

  1. 删除所有由JetPack(或OpenCV4Tegra)安装的旧opencv内容
sudo apt-get purge libopencv*

2.删除其他未使用的apt包(可选操作项)

sudo apt autoremove
  1. 将所有已安装的apt软件包升级到最新版本(可选操作项)
sudo apt-get update
sudo apt-get dist-upgrade

4.下载Jetson TX2 OpenCV安装程序:

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

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

gedit buildOpenCV.sh

6.构建opencv,如果没有opencv/build这个文件夹重新执行./buildOpenCV.sh

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

测试程序:

#include 

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: \n\t" << pipeline << "\n";

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

你可能感兴趣的:(jetson,配置,opencv,c++,cmake)