日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Tegra平台构建OpenCV_Building OpenCV for Tegra with CUDA

發布時間:2023/12/18 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Tegra平台构建OpenCV_Building OpenCV for Tegra with CUDA 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

內容目錄

  • 獲取源碼
  • 編譯準備
  • 編譯配置
  • 編譯Opencv
  • 測試Opencv
  • 安裝Opencv
  • 編譯Opencv2.4.x
  • CMake參數指南

Tegra平臺下基于CUDA使用Opencv

本文檔是構建OpenCV庫的基本指南,CUDA支持在Tegra環境中使用。它涵蓋了從源代碼中構建版本3.1.0庫的基本元素,包括三種不同類型的平臺:

  • NVIDIA DRIVE? PX 2 (V4L)
  • NVIDIA??Tegra??Linux Driver Package (L4T)
  • Desktop Linux (Ubuntu 14.04 LTS and 16.04 LTS)

本文檔并不是對構建OpenCV時可用的所有選項的詳盡指南。具體來說,它涵蓋了構建每個平臺時所使用的基本選項,但不包括任何不需要的選項(或與它們的默認值保持不變)。另外,CUDA工具包的安裝也不在這里。

本文檔的重點是構建OpenCV的3.1.0版本,但是這里的指導原則也可以從git存儲庫的主分支中構建。關于OpenCV 2.4.13版本的構建,有些CMake選項存在差異,這在OpenCV 2.4的構建中總結如下Building OpenCV 2.4.X部分。

大多數配置命令都基于安裝了CUDA 8.0的系統。在Jetson TK1的例子中,使用了一個較舊的CUDA,因為該平臺不支持8.0。這些指令可能也適用于舊版本的CUDA,但只測試了8.0。

關于本地編譯和交叉編譯的說明

OpenCV構建系統支持所有支持平臺的本機編譯,以及ARM等平臺的交叉編譯。本機編譯過程更簡單,而交叉編譯通常更快。
目前,本文只關注本機編譯。

獲取源碼

  • ?OpenCV downloads?下載頁面
  • ?從?GitHub?clone倉庫

對于本指南,重點是使用git存儲庫。這是因為OpenCV的3.1.0版本如果不應用git存儲庫中的一些微小的上游更改,就無法使用CUDA 8.0構建。

# Clone the opencv repository locally: $ git clone https://github.com/opencv/opencv.git

想要編譯3.1.0版本?(而不是編譯最新的版本), 你必須checkout到3.1.0分支:

$ cd opencv $ git checkout -b v3.1.0 3.1.0

注意:該操作在你克隆倉庫中創建一個新的本地分支。

有一些上游更改必須通過git cherry-pick命令進行應用。第一種方法是應用修復程序,具體地使用8.0版本的CUDA,而不是3.1.0版本的一部分:

# While still in the opencv directory: $ git cherry-pick 10896

你將看到以下命令的輸出:

[v3.1.0 d6d69a7] GraphCut deprecated in CUDA 7.5 and removed in 8.0Author: Vladislav Vinogradov <vlad.vinogradov@itseez.com>1 file changed, 2 insertions(+), 1 deletion(-)

其次,對于CMake宏調用有一個修復,這在一些系統上是有問題的:

$ git cherry pick cdb9c

你應該看到如下類似輸出:

[v3.1.0-28613 e5ac2e4] gpu samples: fix REMOVE_ITEM errorAuthor: Alexander Alekhin <alexander.alekhin@itseez.com>1 file changed, 1 insertion(+), 1 deletion(-)

需要的最后一個上游修復涉及到與開發人員包捆綁在一起的pkg-config配置文件 (libopencv-dev):

$ git cherry-pick 24dbb

你應該看到如下類似輸出:

[v3.1.0 3a6d7ab] pkg-config: modules list contains only OpenCV modules (fixes #5852)Author: Alexander Alekhin <alexander.alekhin@itseez.com>1 file changed, 7 insertions(+), 4 deletions(-)

到此為止,opencv倉庫已經可以編譯了。

OpenCV Extra

opencv_extra倉庫包含OpenCV庫的額外數據,包括測試和演示使用的數據文件。必須分別克隆:

# In the same base directory from which you cloned OpenCV: $ git clone https://github.com/opencv/opencv_extra.git

與OpenCV源代碼一樣,必須使用與上面相同的方法將源代碼樹設置為3.1.0版本。當您從特定的標記構建時,兩個存儲庫都必須在該標記處簽出。

$ cd opencv_extra $ git checkout -b v3.1.0 3.1.0

如果你不打算運行測試或安裝測試數據以及示例和示例程序,你可以選擇不獲取這個存儲庫。如果在CMake的調用中沒有引用它,就不會使用它。

注意:如果您計劃運行測試,一些測試期望數據出現,如果沒有數據就會失敗。

編譯準備

要編譯OpenCV,您需要一個目錄來創建配置并構建庫。您還需要一些OpenCV所依賴的第三方庫。

Ubuntu Linux準備

這些是在Linux上為Tegra編譯OpenCV的基本要求:

  • CMake 2.8.10 or newer
  • CUDA toolkit 8.0 (7.0 or 7.5 may also be used)
  • Build tools (make, gcc, g++)
  • Python 2.6 or greater

這些要求是與平臺無關的(DRIVE PX 2, Desktop等等)。

在Linux上編譯opencv所需要的軟件包:

  • libglew-dev
  • libtiff5-dev
  • zlib1g-dev
  • libjpeg-dev
  • libpng12-dev
  • libjasper-dev
  • libavcodec-dev
  • libavformat-dev
  • libavutil-dev
  • libpostproc-dev
  • libswscale-dev
  • libeigen3-dev
  • libtbb-dev
  • libgtk2.0-dev
  • pkg-config

上面的一些包在Ubuntu Linux系統的通用庫中。如果你還沒有啟用該倉庫,那么在嘗試安裝上面列出的所有包之前,需要執行以下操作:

$ sudo apt-add-repository universe $ sudo apt-get update

可以將以下命令粘貼到shell中,以便安裝所需的包:

$ sudo apt-get install \libglew-dev \libtiff5-dev \zlib1g-dev \libjpeg-dev \libpng12-dev \libjasper-dev \libavcodec-dev \libavformat-dev \libavutil-dev \libpostproc-dev \libswscale-dev \libeigen3-dev \libtbb-dev \libgtk2.0-dev \pkg-config

(為了可讀性,添加了換行符和延續字符 / Line-breaks and continuation characters are added for readability.)

如果希望構建Python綁定,還需要為Python 2和Python 3中的任意一個或兩個都提供適當的包:

  • python-dev / python3-dev
  • python-numpy / python3-numpy
  • python-py / python3-py
  • python-pytest / python3-pytest

命令如下:

$ sudo apt-get install python-dev python-numpy python-py python-pytest # And, optionally: $ sudo apt-get install python3-dev python3-numpy python3-py python3-pytest

一旦安裝了所有必要的包,你就可以做編譯前的配置了

準備編譯區域

Software projects that use the CMake system for configuring their builds expect the actual builds to be done outside of the source tree itself. For configuring and building OpenCV, create a directory called "build" in the same base directory into which you cloned the git repositories:

使用CMake系統來配置構建的軟件項目期望在源代碼樹本身之外完成實際的構建。為了配置和構建OpenCV,在復制git存儲庫的同一基本目錄中創建一個名為“build”的目錄:

$ mkdir build $ cd build

You are now ready to configure and build OpenCV.

現在可以配置和編譯OpenCV了。

編譯前的配置

The CMake configuration options given below for the different platforms are targeted towards the functionality needed for Tegra. They are based on the original configuration options used for building OpenCV 2.4.13.

下面給出的針對不同平臺的CMake配置選項針對的是Tegra所需的功能。它們基于構建OpenCV 2.4.13所用的原始配置選項。

The build of OpenCV is configured with CMake. If run with no parameters, it detects what it needs to know about your system. However, it may have difficulty finding the CUDA files if they are not in a standard location, and it may try to build some options that you might otherwise not want included, so the following invocations of CMake are recommended.

使用Cmake對Opencv進行編譯。如果不帶參數運行,它會檢測到需要了解的系統信息。但是,如果CUDA文件不在標準位置,它可能很難找到它們,并且它可能嘗試構建一些您可能不希望包含的選項,因此建議使用以下CMake調用。

In each?cmake?command listed in the following sub-sections, line-breaks and indentation are added for readability. Continuation characters are also added in examples for Linux-based platforms, allowing you to copy and paste the examples directly into a shell. When entering these commands by hand, enter the command and options as a single line. For a detailed explanation of the parameters passed to?cmake, see the "CMake Parameter Reference" section.

在下面的小節中列出的每個cmake命令中,為了可讀性,都添加了換行符和縮進。在基于linux平臺的示例中還添加了延續字符,允許您直接將示例復制粘貼到shell中。手動輸入這些命令時,將命令和選項作為一行輸入。有關傳遞給cmake的參數的詳細說明,請參閱“cmake參數引用”一節。

For the Linux-based platforms, the shown value for the?CMAKE_INSTALL_PREFIX?parameter is?/usr. You can set this to whatever you want, based on the layout of your system.

對于基于linux的平臺,CMAKE_INSTALL_PREFIX參數的顯示值是/usr。您可以根據系統的布局將其設置為任意值。

In each of the?cmake?invocations below, the last parameter,?OPENCV_TEST_DATA_PATH, tells the build system where to find the test-data that is provided by the?opencv_extra?repository. When this is included, a?make install?installs this test-data alongside the libraries and example code, and a?make testautomatically provides this path to the tests that have to load data from it. If you did not clone the?opencv_extra?repository, do not include this parameter.

在下面的cmake調用中,最后一個參數OPENCV_TEST_DATA_PATH告訴構建系統在哪里找到opencv_extra存儲庫提供的測試數據。當包含這部分內容時,make install會將這些測試數據與庫和示例代碼一起安裝,而make testtest會自動提供這個路徑,以供必須從其中加載數據的測試使用。如果沒有克隆opencv_extra存儲庫,不要包含這個參數。

Vibrante V4L 環境下編譯配置

Supported platform: Drive PX 2

支持的平臺:Drive PX 2

$ cmake \-DCMAKE_BUILD_TYPE=Release \-DCMAKE_INSTALL_PREFIX=/usr \-DBUILD_PNG=OFF \-DBUILD_TIFF=OFF \-DBUILD_TBB=OFF \-DBUILD_JPEG=OFF \-DBUILD_JASPER=OFF \-DBUILD_ZLIB=OFF \-DBUILD_EXAMPLES=ON \-DBUILD_opencv_java=OFF \-DBUILD_opencv_python2=ON \-DBUILD_opencv_python3=OFF \-DENABLE_NEON=ON \-DWITH_OPENCL=OFF \-DWITH_OPENMP=OFF \-DWITH_FFMPEG=ON \-DWITH_GSTREAMER=OFF \-DWITH_GSTREAMER_0_10=OFF \-DWITH_CUDA=ON \-DWITH_GTK=ON \-DWITH_VTK=OFF \-DWITH_TBB=ON \-DWITH_1394=OFF \-DWITH_OPENEXR=OFF \-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-8.0 \-DCUDA_ARCH_BIN=6.2 \-DCUDA_ARCH_PTX="" \-DINSTALL_C_EXAMPLES=ON \-DINSTALL_TESTS=OFF \-DOPENCV_TEST_DATA_PATH=../opencv_extra/testdata \../opencv

The configuration provided above builds the Python bindings for Python 2 (but not Python 3) as part of the build process. If you want the Python 3 bindings (or do not want the Python 2 bindings), change the values of?BUILD_opencv_python2?and/or?BUILD_opencv_python3?as needed. To enable bindings, set the value to?ON, to disable them set it to?OFF:

上面提供的配置作為構建過程的一部分為Python 2(而不是Python 3)構建Python綁定。如果希望使用Python 3綁定(或者不希望使用Python 2綁定),請根據需要更改BUILD_opencv_python2和/或BUILD_opencv_python3的值。要啟用綁定,請將值設置為ON,以禁用它們將其設置為OFF:

-DBUILD_opencv_python2=OFF

Jetson L4T 環境下編譯配置

支持的平臺:

  • Jetson TK1
  • Jetson TX1

Configuration is slightly different for the Jetson TK1 and the Jetson TX1 systems.

Jetson TK1和Jetson TX1系統的配置略有不同。

Jetson TK1

$ cmake \-DCMAKE_BUILD_TYPE=Release \-DCMAKE_INSTALL_PREFIX=/usr \-DCMAKE_CXX_FLAGS=-Wa,-mimplicit-it=thumb \-DBUILD_PNG=OFF \-DBUILD_TIFF=OFF \-DBUILD_TBB=OFF \-DBUILD_JPEG=OFF \-DBUILD_JASPER=OFF \-DBUILD_ZLIB=OFF \-DBUILD_EXAMPLES=ON \-DBUILD_opencv_java=OFF \-DBUILD_opencv_python2=ON \-DBUILD_opencv_python3=OFF \-DENABLE_NEON=ON \-DWITH_OPENCL=OFF \-DWITH_OPENMP=OFF \-DWITH_FFMPEG=ON \-DWITH_GSTREAMER=OFF \-DWITH_GSTREAMER_0_10=OFF \-DWITH_CUDA=ON \-DWITH_GTK=ON \-DWITH_VTK=OFF \-DWITH_TBB=ON \-DWITH_1394=OFF \-DWITH_OPENEXR=OFF \-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-6.5 \-DCUDA_ARCH_BIN=3.2 \-DCUDA_ARCH_PTX="" \-DINSTALL_C_EXAMPLES=ON \-DINSTALL_TESTS=OFF \-DOPENCV_TEST_DATA_PATH=../opencv_extra/testdata \../opencv

Note:?This uses CUDA 6.5, not 8.0.

注意:這里編譯時使用的版本為6.5,而不是8.0

Jetson TX1

$ cmake \-DCMAKE_BUILD_TYPE=Release \-DCMAKE_INSTALL_PREFIX=/usr \-DBUILD_PNG=OFF \-DBUILD_TIFF=OFF \-DBUILD_TBB=OFF \-DBUILD_JPEG=OFF \-DBUILD_JASPER=OFF \-DBUILD_ZLIB=OFF \-DBUILD_EXAMPLES=ON \-DBUILD_opencv_java=OFF \-DBUILD_opencv_python2=ON \-DBUILD_opencv_python3=OFF \-DENABLE_PRECOMPILED_HEADERS=OFF \-DWITH_OPENCL=OFF \-DWITH_OPENMP=OFF \-DWITH_FFMPEG=ON \-DWITH_GSTREAMER=OFF \-DWITH_GSTREAMER_0_10=OFF \-DWITH_CUDA=ON \-DWITH_GTK=ON \-DWITH_VTK=OFF \-DWITH_TBB=ON \-DWITH_1394=OFF \-DWITH_OPENEXR=OFF \-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-8.0 \-DCUDA_ARCH_BIN=5.3 \-DCUDA_ARCH_PTX="" \-DINSTALL_C_EXAMPLES=ON \-DINSTALL_TESTS=OFF \-DOPENCV_TEST_DATA_PATH=../opencv_extra/testdata \../opencv

Note:?This configuration does not set the?ENABLE_NEON?parameter.

注意:這個配置沒有設置ENABLE_NEON參數。

Ubuntu Desktop Linux 環境下編譯配置

支持的平臺:

  • Ubuntu Desktop Linux 14.04 LTS
  • Ubuntu Desktop Linux 16.04 LTS

The configuration options given to?cmake?below are targeted towards the functionality needed for Tegra. For a desktop system, you may wish to adjust some options to enable (or disable) certain features. The features enabled below are based on the building of OpenCV 2.4.13.

下面提供給cmake的配置選項針對的是Tegra所需的功能。對于桌面系統,你可能希望調整一些選項以啟用(或禁用)某些特性。下面啟用的特性基于OpenCV 2.4.13的構建。

$ cmake \-DCMAKE_BUILD_TYPE=Release \-DCMAKE_INSTALL_PREFIX=/usr \-DBUILD_PNG=OFF \-DBUILD_TIFF=OFF \-DBUILD_TBB=OFF \-DBUILD_JPEG=OFF \-DBUILD_JASPER=OFF \-DBUILD_ZLIB=OFF \-DBUILD_EXAMPLES=ON \-DBUILD_opencv_java=OFF \-DBUILD_opencv_python2=ON \-DBUILD_opencv_python3=OFF \-DWITH_OPENCL=OFF \-DWITH_OPENMP=OFF \-DWITH_FFMPEG=ON \-DWITH_GSTREAMER=OFF \-DWITH_GSTREAMER_0_10=OFF \-DWITH_CUDA=ON \-DWITH_GTK=ON \-DWITH_VTK=OFF \-DWITH_TBB=ON \-DWITH_1394=OFF \-DWITH_OPENEXR=OFF \-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-8.0 \-DCUDA_ARCH_BIN='3.0 3.5 5.0 6.0 6.2' \-DCUDA_ARCH_PTX="" \-DINSTALL_C_EXAMPLES=ON \-DINSTALL_TESTS=OFF \-DOP 同樣需要注意的是:這里的cuda版本為8.0,根據自己需要可以更改

?

總結

以上是生活随笔為你收集整理的Tegra平台构建OpenCV_Building OpenCV for Tegra with CUDA的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。