├── Examples ├── README.md ├── cannyDetection.py └── gstreamer_view.cpp ├── LICENSE ├── README.md ├── buildAndPackageOpenCV.sh ├── buildOpenCV.sh ├── patches └── OpenGLHeader.patch ├── removeOpenCVSources.sh └── scripts ├── jetson_easy LICENSE └── jetson_variables /Examples/README.md: -------------------------------------------------------------------------------- 1 | There are two example programs here. Both programs require OpenCV to be installed with GStreamer support enabled. 2 | Both of these examples were last tested with L4T 28.2, OpenCV 3.4.1 3 | 4 | The first is a simple C++ program to view the onboard camera feed from the Jetson Dev Kit. 5 | 6 | To compile gstreamer_view.cpp: 7 | 8 | $ gcc -std=c++11 `pkg-config --cflags opencv` `pkg-config --libs opencv` gstreamer_view.cpp -o gstreamer_view -lstdc++ -lopencv_core -lopencv_highgui -lopencv_videoio 9 | 10 | to run the program: 11 | 12 | $ ./gstreamer_view 13 | 14 | The second is a Python program that reads the onboard camera feed from the Jetson Dev Kit and does Canny Edge Detection. 15 | 16 | To run the Canny detection demo (Python 2.7): 17 | 18 | $ python cannyDetection.py 19 | 20 | With Python 3.3: 21 | 22 | $ python3 cannyDetection.py 23 | 24 | With the Canny detection demo, use the less than (<) and greater than (>) to adjust the edge detection parameters. 25 | 26 | ## Notes 27 | 28 | 1. The gstreamer_view example is from Peter Moran: 29 | https://gist.github.com/peter-moran/742998d893cd013edf6d0c86cc86ff7f 30 | Note that the nvvidconv flip-method was changed to 0. Earlier versions of L4T used a flip method of 2. 31 | 32 | 2. For the Python examples, you will need to have the appropriate librariers installed. From the buildOpenCV scripts: 33 | 34 | #### Python 2.7 35 | $ sudo apt-get install -y python-dev python-numpy python-py python-pytest 36 | #### Python 3.5 37 | $ sudo apt-get install -y python3-dev python3-numpy python3-py python3-pytest 38 | 39 | 40 | ## License 41 | MIT License 42 | 43 | Copyright (c) 2017-2018 Jetsonhacks 44 | 45 | Permission is hereby granted, free of charge, to any person obtaining a copy 46 | of this software and associated documentation files (the "Software"), to deal 47 | in the Software without restriction, including without limitation the rights 48 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 49 | copies of the Software, and to permit persons to whom the Software is 50 | furnished to do so, subject to the following conditions: 51 | 52 | The above copyright notice and this permission notice shall be included in all 53 | copies or substantial portions of the Software. 54 | 55 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 56 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 57 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 58 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 59 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 60 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 61 | SOFTWARE. 62 | 63 | gstreamer_view example Copyright (c) 2017 Peter Moran 64 | 65 | -------------------------------------------------------------------------------- /Examples/cannyDetection.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # MIT License 3 | 4 | # Copyright (c) 2017-18 Jetsonhacks 5 | 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | 24 | import sys 25 | import argparse 26 | import cv2 27 | import numpy as np 28 | 29 | def parse_cli_args(): 30 | parser = argparse.ArgumentParser() 31 | parser.add_argument("--video_device", dest="video_device", 32 | help="Video device # of USB webcam (/dev/video?) [0]", 33 | default=0, type=int) 34 | arguments = parser.parse_args() 35 | return arguments 36 | 37 | # On versions of L4T previous to L4T 28.1, flip-method=2 38 | # Use the Jetson onboard camera 39 | def open_onboard_camera(): 40 | return cv2.VideoCapture("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)640, height=(int)480, format=(string)I420, framerate=(fraction)30/1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink") 41 | 42 | # Open an external usb camera /dev/videoX 43 | def open_camera_device(device_number): 44 | return cv2.VideoCapture(device_number) 45 | 46 | 47 | def read_cam(video_capture): 48 | if video_capture.isOpened(): 49 | windowName = "CannyDemo" 50 | cv2.namedWindow(windowName, cv2.WINDOW_NORMAL) 51 | cv2.resizeWindow(windowName,1280,720) 52 | cv2.moveWindow(windowName,0,0) 53 | cv2.setWindowTitle(windowName,"Canny Edge Detection") 54 | showWindow=3 # Show all stages 55 | showHelp = True 56 | font = cv2.FONT_HERSHEY_PLAIN 57 | helpText="'Esc' to Quit, '1' for Camera Feed, '2' for Canny Detection, '3' for All Stages. '4' to hide help" 58 | edgeThreshold=40 59 | showFullScreen = False 60 | while True: 61 | if cv2.getWindowProperty(windowName, 0) < 0: # Check to see if the user closed the window 62 | # This will fail if the user closed the window; Nasties get printed to the console 63 | break; 64 | ret_val, frame = video_capture.read(); 65 | hsv=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 66 | blur=cv2.GaussianBlur(hsv,(7,7),1.5) 67 | edges=cv2.Canny(blur,0,edgeThreshold) 68 | if showWindow == 3: # Need to show the 4 stages 69 | # Composite the 2x2 window 70 | # Feed from the camera is RGB, the others gray 71 | # To composite, convert gray images to color. 72 | # All images must be of the same type to display in a window 73 | frameRs=cv2.resize(frame, (640,360)) 74 | hsvRs=cv2.resize(hsv,(640,360)) 75 | vidBuf = np.concatenate((frameRs, cv2.cvtColor(hsvRs,cv2.COLOR_GRAY2BGR)), axis=1) 76 | blurRs=cv2.resize(blur,(640,360)) 77 | edgesRs=cv2.resize(edges,(640,360)) 78 | vidBuf1 = np.concatenate( (cv2.cvtColor(blurRs,cv2.COLOR_GRAY2BGR),cv2.cvtColor(edgesRs,cv2.COLOR_GRAY2BGR)), axis=1) 79 | vidBuf = np.concatenate( (vidBuf, vidBuf1), axis=0) 80 | 81 | if showWindow==1: # Show Camera Frame 82 | displayBuf = frame 83 | elif showWindow == 2: # Show Canny Edge Detection 84 | displayBuf = edges 85 | elif showWindow == 3: # Show All Stages 86 | displayBuf = vidBuf 87 | 88 | if showHelp == True: 89 | cv2.putText(displayBuf, helpText, (11,20), font, 1.0, (32,32,32), 4, cv2.LINE_AA) 90 | cv2.putText(displayBuf, helpText, (10,20), font, 1.0, (240,240,240), 1, cv2.LINE_AA) 91 | cv2.imshow(windowName,displayBuf) 92 | key=cv2.waitKey(10) 93 | if key == 27: # Check for ESC key 94 | cv2.destroyAllWindows() 95 | break ; 96 | elif key==49: # 1 key, show frame 97 | cv2.setWindowTitle(windowName,"Camera Feed") 98 | showWindow=1 99 | elif key==50: # 2 key, show Canny 100 | cv2.setWindowTitle(windowName,"Canny Edge Detection") 101 | showWindow=2 102 | elif key==51: # 3 key, show Stages 103 | cv2.setWindowTitle(windowName,"Camera, Gray scale, Gaussian Blur, Canny Edge Detection") 104 | showWindow=3 105 | elif key==52: # 4 key, toggle help 106 | showHelp = not showHelp 107 | elif key==44: # , lower canny edge threshold 108 | edgeThreshold=max(0,edgeThreshold-1) 109 | print ('Canny Edge Threshold Maximum: ',edgeThreshold) 110 | elif key==46: # , raise canny edge threshold 111 | edgeThreshold=edgeThreshold+1 112 | print ('Canny Edge Threshold Maximum: ', edgeThreshold) 113 | elif key==74: # Toggle fullscreen; This is the F3 key on this particular keyboard 114 | # Toggle full screen mode 115 | if showFullScreen == False : 116 | cv2.setWindowProperty(windowName, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) 117 | else: 118 | cv2.setWindowProperty(windowName, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_NORMAL) 119 | showFullScreen = not showFullScreen 120 | 121 | else: 122 | print ("camera open failed") 123 | 124 | 125 | 126 | if __name__ == '__main__': 127 | arguments = parse_cli_args() 128 | print("Called with args:") 129 | print(arguments) 130 | print("OpenCV version: {}".format(cv2.__version__)) 131 | print("Device Number:",arguments.video_device) 132 | if arguments.video_device==0: 133 | video_capture=open_onboard_camera() 134 | else: 135 | video_capture=open_camera_device(arguments.video_device) 136 | read_cam(video_capture) 137 | video_capture.release() 138 | cv2.destroyAllWindows() 139 | -------------------------------------------------------------------------------- /Examples/gstreamer_view.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Example code for displaying gstreamer video from the CSI port of the Nvidia Jetson in OpenCV. 3 | Created by Peter Moran on 7/29/17. 4 | https://gist.github.com/peter-moran/742998d893cd013edf6d0c86cc86ff7f 5 | */ 6 | 7 | #include 8 | 9 | std::string get_tegra_pipeline(int width, int height, int fps) { 10 | return "nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)" + std::to_string(width) + ", height=(int)" + 11 | std::to_string(height) + ", format=(string)I420, framerate=(fraction)" + std::to_string(fps) + 12 | "/1 ! nvvidconv flip-method=0 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink"; 13 | } 14 | 15 | int main() { 16 | // Options 17 | int WIDTH = 1920; 18 | int HEIGHT = 1080; 19 | int FPS = 30; 20 | 21 | // Define the gstream pipeline 22 | std::string pipeline = get_tegra_pipeline(WIDTH, HEIGHT, FPS); 23 | std::cout << "Using pipeline: \n\t" << pipeline << "\n"; 24 | 25 | // Create OpenCV capture object, ensure it works. 26 | cv::VideoCapture cap(pipeline, cv::CAP_GSTREAMER); 27 | if (!cap.isOpened()) { 28 | std::cout << "Connection failed"; 29 | return -1; 30 | } 31 | 32 | // View video 33 | cv::Mat frame; 34 | while (1) { 35 | cap >> frame; // Get a new frame from camera 36 | 37 | // Display frame 38 | imshow("Display window", frame); 39 | cv::waitKey(1); //needed to show frame 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-2018 Jetsonhacks 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # buildOpenCVTX1 2 | Build and install OpenCV for the NVIDIA Jetson TX1 3 | 4 | These scripts build OpenCV version 3.4 for the NVIDIA Jetson TX1 Development Kit. Please see Releases/Tags for earlier versions. 5 | 6 | OpenCV is a rich environment which can be configured in many different ways. You should configure OpenCV for your needs, by modifying the build file "buildOpenCV.sh". Note that selecting different options in OpenCV may also have additional library requirements which are not included in these scripts. Please read the notes below for other important points before installing. 7 | 8 | The Jetson does not have enough disk space to build a full configuration on the eMMC. The easiest method to build is to place the OpenCV source directory on external media such as a SD card, a USB flash drive or SATA drive. 9 | 10 | The buildOpenCV script has two optional command line parameters: 11 | 12 | 16 | 17 | To run the the build file: 18 | 19 | $ ./buildOpenCV.sh -s <file directory> 20 | 21 | This will build OpenCV is the given file directory and install OpenCV is the /usr/local directory. 22 | 23 | The folder ~/opencv and ~/opencv_extras contain the source, build and extra data files. If you wish to remove them after installation, a convenience script is provided: 24 | 25 | $ ./removeOpenCVSources.sh -d <file directory> 26 | 27 | where the <file directory> contains the OpenCV source. 28 | 29 |

Packaging

30 | An alternative build script, buildAndPackageOpenCV.sh , will build the OpenCV package as described above and the build .deb files using the standard OpenCV mechanism defined using the CPACK_BINARY_DEB=ON in the OpenCV Make file. See the script. 31 | 32 | The buildAndPackageOpenCV script has two optional command line parameters: 33 | 34 | 38 | 39 | To run the the build file: 40 | 41 | $ ./buildAndPackageOpenCV.sh -s <file directory> 42 | 43 | This example will build OpenCV in the given file directory and install OpenCV in the /usr/local directory. 44 | 45 | The corresponding .deb files will be in the <file directory>/opencv/build directory in .deb file and compressed forms. 46 | 47 |

Installing .deb files

48 | 49 | To install .deb files: 50 | 51 | Switch to the directory where the .deb files are located. Then: 52 | 53 |
54 | $ sudo dpkg -i OpenCV-<OpenCV Version info>-aarch64-libs.deb 55 | 56 | For example: $ sudo dpkg -i OpenCV-3.4.1-1-g75a2577-aarch64-libs.deb 57 | 58 | $ sudo apt-get install -f 59 | 60 | $ sudo dpkg -i OpenCV-<OpenCV Version info>-aarch64-dev.deb 61 | 62 | $ sudo dpkg -i OpenCV-<OpenCV Version info>-aarch64-python.deb
63 | 64 | The libraries will be installed in /usr/lib 65 | 66 | Binaries are in /usr/bin 67 | 68 | opencv.pc is in /usr/lib/pkgconfig 69 | 70 | Package Notes: 71 | 75 | 76 | 77 | ## Notes 78 | There may be issues if different version of OpenCV are installed. JetPack normally installs OpenCV in the /usr folder. You will need to consider if this is appropriate for your application. It is important to realize that many packages may rely on OpenCV. The standard installation by JetPack places the OpenCV libraries in the /usr directory. 79 | 80 | You may consider removing OpenCV installed by JetPack before performing this script installation: 81 | 82 | $ sudo apt-get purge libopencv* 83 | 84 | With this script release, the script now installs OpenCV in /usr/local. Earlier versions of this script installed in /usr. You may have to set your include and libraries and/or PYTHONPATH to point to the new version. See the Examples folder. Alternatively, you may want to change the script to install into the /usr directory. 85 | 86 | The Jetson is an aarch64 machine, which means that the OpenCV configuration variable ENABLE_NEON is ignored. The compiler includes NEON support for all machines with aarch64 architecture. 87 | 88 | These scripts rely on OpenCV finding the correct CUDA version, instead of setting it manually. 89 | 90 | Special thanks to Daniel (Github user @dkoguciuk) for script cleanup. 91 | 92 | 93 | ## References 94 | 95 | Most of this information is derived from: 96 | 97 | http://docs.opencv.org/3.2.0/d6/d15/tutorial_building_tegra_cuda.html 98 | 99 | https://devtalk.nvidia.com/default/topic/965134/opencv-3-1-compilation-on-tx1-lets-collect-the-quot-definitive-quot-cmake-settings-/?offset=3 100 | 101 | ## Release Notes 102 | June 2018 103 | * L4T 28.2 104 | * CUDA 9 105 | * OpenCV 3.4 106 | * Added command line arguments to set source and installation directories 107 | * Add a script to build OpenCV .deb packages. 108 | * Add upstream patch for C library compilation issues 109 | 110 | May 2018 111 | * L4T 28.2 112 | * CUDA 9 113 | * OpenCV 3.4 114 | * OpenGL support added to build script 115 | * Fast Math support (cuBLAS) added 116 | * Supports both Python 3 and Python 2 117 | * Canny Detection example supports built-in camera and USB camera. See the Examples folder 118 | 119 | September 2017 120 | 121 | Initial Release 122 | L4T 28.1 123 | OpenCV 3.3 124 | 125 | ## License 126 | MIT License 127 | 128 | Copyright (c) 2017-2018 Jetsonhacks 129 | 130 | Permission is hereby granted, free of charge, to any person obtaining a copy 131 | of this software and associated documentation files (the "Software"), to deal 132 | in the Software without restriction, including without limitation the rights 133 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 134 | copies of the Software, and to permit persons to whom the Software is 135 | furnished to do so, subject to the following conditions: 136 | 137 | The above copyright notice and this permission notice shall be included in all 138 | copies or substantial portions of the Software. 139 | 140 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 141 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 142 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 143 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 144 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 145 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 146 | SOFTWARE. 147 | 148 | -------------------------------------------------------------------------------- /buildAndPackageOpenCV.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # License: MIT. See license file in root directory 3 | # Copyright(c) JetsonHacks (2017-2018) 4 | 5 | OPENCV_VERSION=3.4.1 6 | # Jetson TX2 7 | # ARCH_BIN=6.2 8 | # Jetson TX1 9 | ARCH_BIN=5.3 10 | INSTALL_DIR=/usr/local 11 | # Download the opencv_extras repository 12 | # If you are installing the opencv testdata, ie 13 | # OPENCV_TEST_DATA_PATH=../opencv_extra/testdata 14 | # Make sure that you set this to YES 15 | # Value should be YES or NO 16 | DOWNLOAD_OPENCV_EXTRAS=NO 17 | # Source code directory 18 | OPENCV_SOURCE_DIR=$HOME 19 | WHEREAMI=$PWD 20 | 21 | CLEANUP=true 22 | 23 | function usage 24 | { 25 | echo "usage: ./buildAndPackage.sh [[-s sourcedir ] | [-h]]" 26 | echo "-s | --sourcedir Directory in which to place the opencv sources (default $HOME)" 27 | echo "-i | --installdir Directory in which to install opencv libraries (default /usr/local)" 28 | echo "-h | --help This message" 29 | } 30 | 31 | # Iterate through command line inputs 32 | while [ "$1" != "" ]; do 33 | case $1 in 34 | -s | --sourcedir ) shift 35 | OPENCV_SOURCE_DIR=$1 36 | ;; 37 | -i | --installdir ) shift 38 | INSTALL_DIR=$1 39 | ;; 40 | -h | --help ) usage 41 | exit 42 | ;; 43 | * ) usage 44 | exit 1 45 | esac 46 | shift 47 | done 48 | 49 | CMAKE_INSTALL_PREFIX=$INSTALL_DIR 50 | 51 | source scripts/jetson_variables 52 | 53 | # Print out the current configuration 54 | echo "Build configuration: " 55 | echo " NVIDIA Jetson $JETSON_BOARD" 56 | echo " Operating System: $JETSON_L4T_STRING [Jetpack $JETSON_JETPACK]" 57 | echo " Current OpenCV Installation: $JETSON_OPENCV" 58 | echo " OpenCV binaries will be installed in: $CMAKE_INSTALL_PREFIX" 59 | echo " OpenCV Source will be installed in: $OPENCV_SOURCE_DIR" 60 | 61 | if [ $DOWNLOAD_OPENCV_EXTRAS == "YES" ] ; then 62 | echo "Also installing opencv_extras" 63 | fi 64 | 65 | # Repository setup 66 | sudo apt-add-repository universe 67 | sudo apt-get update 68 | 69 | # Download dependencies for the desired configuration 70 | cd $WHEREAMI 71 | sudo apt-get install -y \ 72 | cmake \ 73 | libavcodec-dev \ 74 | libavformat-dev \ 75 | libavutil-dev \ 76 | libeigen3-dev \ 77 | libglew-dev \ 78 | libgtk2.0-dev \ 79 | libgtk-3-dev \ 80 | libjasper-dev \ 81 | libjpeg-dev \ 82 | libpng12-dev \ 83 | libpostproc-dev \ 84 | libswscale-dev \ 85 | libtbb-dev \ 86 | libtiff5-dev \ 87 | libv4l-dev \ 88 | libxvidcore-dev \ 89 | libx264-dev \ 90 | qt5-default \ 91 | zlib1g-dev \ 92 | pkg-config 93 | 94 | # https://devtalk.nvidia.com/default/topic/1007290/jetson-tx2/building-opencv-with-opengl-support-/post/5141945/#5141945 95 | cd /usr/local/cuda/include 96 | sudo patch -N cuda_gl_interop.h $WHEREAMI'/patches/OpenGLHeader.patch' 97 | # Clean up the OpenGL tegra libs that usually get crushed 98 | cd /usr/lib/aarch64-linux-gnu/ 99 | sudo ln -sf tegra/libGL.so libGL.so 100 | 101 | # Python 2.7 102 | sudo apt-get install -y python-dev python-numpy python-py python-pytest 103 | # Python 3.5 104 | sudo apt-get install -y python3-dev python3-numpy python3-py python3-pytest 105 | 106 | # GStreamer support 107 | sudo apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev 108 | 109 | cd $OPENCV_SOURCE_DIR 110 | git clone https://github.com/opencv/opencv.git 111 | cd opencv 112 | git checkout -b v${OPENCV_VERSION} ${OPENCV_VERSION} 113 | if [ $OPENCV_VERSION = 3.4.1 ] ; then 114 | # For 3.4.1, use this commit to fix samples/gpu/CMakeLists.txt 115 | git merge ec0bb66 116 | # For 3.4.1, use this to fix C compilation issues (like in YOLO) 117 | git cherry-pick 549b5df 118 | fi 119 | 120 | if [ $DOWNLOAD_OPENCV_EXTRAS == "YES" ] ; then 121 | echo "Installing opencv_extras" 122 | # This is for the test data 123 | cd $OPENCV_SOURCE_DIR 124 | git clone https://github.com/opencv/opencv_extra.git 125 | cd opencv_extra 126 | git checkout -b v${OPENCV_VERSION} ${OPENCV_VERSION} 127 | fi 128 | 129 | cd $OPENCV_SOURCE_DIR/opencv 130 | mkdir build 131 | cd build 132 | 133 | # Here are some options to install source examples and tests 134 | # -D INSTALL_TESTS=ON \ 135 | # -D OPENCV_TEST_DATA_PATH=../opencv_extra/testdata \ 136 | # -D INSTALL_C_EXAMPLES=ON \ 137 | # -D INSTALL_PYTHON_EXAMPLES=ON \ 138 | # There are also switches which tell CMAKE to build the samples and tests 139 | # Check OpenCV documentation for details 140 | 141 | 142 | time cmake -D CMAKE_BUILD_TYPE=RELEASE \ 143 | -D CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} \ 144 | -D WITH_CUDA=ON \ 145 | -D CUDA_ARCH_BIN=${ARCH_BIN} \ 146 | -D CUDA_ARCH_PTX="" \ 147 | -D ENABLE_FAST_MATH=ON \ 148 | -D CUDA_FAST_MATH=ON \ 149 | -D WITH_CUBLAS=ON \ 150 | -D WITH_LIBV4L=ON \ 151 | -D WITH_GSTREAMER=ON \ 152 | -D WITH_GSTREAMER_0_10=OFF \ 153 | -D WITH_QT=ON \ 154 | -D WITH_OPENGL=ON \ 155 | -D CPACK_BINARY_DEB=ON \ 156 | ../ 157 | 158 | if [ $? -eq 0 ] ; then 159 | echo "CMake configuration make successful" 160 | else 161 | # Try to make again 162 | echo "CMake issues " >&2 163 | echo "Please check the configuration being used" 164 | exit 1 165 | fi 166 | 167 | # Consider $ sudo nvpmodel -m 2 or $ sudo nvpmodel -m 0 168 | NUM_CPU=$(nproc) 169 | time make -j$(($NUM_CPU - 1)) 170 | if [ $? -eq 0 ] ; then 171 | echo "OpenCV make successful" 172 | else 173 | # Try to make again; Sometimes there are issues with the build 174 | # because of lack of resources or concurrency issues 175 | echo "Make did not build " >&2 176 | echo "Retrying ... " 177 | # Single thread this time 178 | make 179 | if [ $? -eq 0 ] ; then 180 | echo "OpenCV make successful" 181 | else 182 | # Try to make again 183 | echo "Make did not successfully build" >&2 184 | echo "Please fix issues and retry build" 185 | exit 1 186 | fi 187 | fi 188 | 189 | echo "Installing ... " 190 | sudo make install 191 | if [ $? -eq 0 ] ; then 192 | echo "OpenCV installed in: $CMAKE_INSTALL_PREFIX" 193 | else 194 | echo "There was an issue with the final installation" 195 | exit 1 196 | fi 197 | 198 | echo "Starting Packaging" 199 | sudo ldconfig 200 | NUM_CPU=$(nproc) 201 | time sudo make package -j$(($NUM_CPU - 1)) 202 | if [ $? -eq 0 ] ; then 203 | echo "OpenCV make package successful" 204 | else 205 | # Try to make again; Sometimes there are issues with the build 206 | # because of lack of resources or concurrency issues 207 | echo "Make package did not build " >&2 208 | echo "Retrying ... " 209 | # Single thread this time 210 | sudo make package 211 | if [ $? -eq 0 ] ; then 212 | echo "OpenCV make package successful" 213 | else 214 | # Try to make again 215 | echo "Make package did not successfully build" >&2 216 | echo "Please fix issues and retry build" 217 | exit 1 218 | fi 219 | fi 220 | 221 | 222 | # check installation 223 | IMPORT_CHECK="$(python -c "import cv2 ; print cv2.__version__")" 224 | if [[ $IMPORT_CHECK != *$OPENCV_VERSION* ]]; then 225 | echo "There was an error loading OpenCV in the Python sanity test." 226 | echo "The loaded version does not match the version built here." 227 | echo "Please check the installation." 228 | echo "The first check should be the PYTHONPATH environment variable." 229 | fi 230 | -------------------------------------------------------------------------------- /buildOpenCV.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # License: MIT. See license file in root directory 3 | # Copyright(c) JetsonHacks (2017-2018) 4 | 5 | OPENCV_VERSION=3.4.1 6 | # Jetson TX2 7 | # ARCH_BIN=6.2 8 | # Jetson TX1 9 | ARCH_BIN=5.3 10 | INSTALL_DIR=/usr/local 11 | # Download the opencv_extras repository 12 | # If you are installing the opencv testdata, ie 13 | # OPENCV_TEST_DATA_PATH=../opencv_extra/testdata 14 | # Make sure that you set this to YES 15 | # Value should be YES or NO 16 | DOWNLOAD_OPENCV_EXTRAS=NO 17 | # Source code directory 18 | OPENCV_SOURCE_DIR=$HOME 19 | WHEREAMI=$PWD 20 | 21 | CLEANUP=true 22 | 23 | function usage 24 | { 25 | echo "usage: ./buildOpenCVTX1.sh [[-s sourcedir ] | [-h]]" 26 | echo "-s | --sourcedir Directory in which to place the opencv sources (default $HOME)" 27 | echo "-i | --installdir Directory in which to install opencv libraries (default /usr/local)" 28 | echo "-h | --help This message" 29 | } 30 | 31 | # Iterate through command line inputs 32 | while [ "$1" != "" ]; do 33 | case $1 in 34 | -s | --sourcedir ) shift 35 | OPENCV_SOURCE_DIR=$1 36 | ;; 37 | -i | --installdir ) shift 38 | INSTALL_DIR=$1 39 | ;; 40 | -h | --help ) usage 41 | exit 42 | ;; 43 | * ) usage 44 | exit 1 45 | esac 46 | shift 47 | done 48 | 49 | CMAKE_INSTALL_PREFIX=$INSTALL_DIR 50 | 51 | source scripts/jetson_variables 52 | 53 | # Print out the current configuration 54 | echo "Build configuration: " 55 | echo " NVIDIA Jetson $JETSON_BOARD" 56 | echo " Operating System: $JETSON_L4T_STRING [Jetpack $JETSON_JETPACK]" 57 | echo " Current OpenCV Installation: $JETSON_OPENCV" 58 | echo " OpenCV binaries will be installed in: $CMAKE_INSTALL_PREFIX" 59 | echo " OpenCV Source will be installed in: $OPENCV_SOURCE_DIR" 60 | 61 | if [ $DOWNLOAD_OPENCV_EXTRAS == "YES" ] ; then 62 | echo "Also installing opencv_extras" 63 | fi 64 | 65 | # Repository setup 66 | sudo apt-add-repository universe 67 | sudo apt-get update 68 | 69 | # Download dependencies for the desired configuration 70 | cd $WHEREAMI 71 | sudo apt-get install -y \ 72 | cmake \ 73 | libavcodec-dev \ 74 | libavformat-dev \ 75 | libavutil-dev \ 76 | libeigen3-dev \ 77 | libglew-dev \ 78 | libgtk2.0-dev \ 79 | libgtk-3-dev \ 80 | libjasper-dev \ 81 | libjpeg-dev \ 82 | libpng12-dev \ 83 | libpostproc-dev \ 84 | libswscale-dev \ 85 | libtbb-dev \ 86 | libtiff5-dev \ 87 | libv4l-dev \ 88 | libxvidcore-dev \ 89 | libx264-dev \ 90 | qt5-default \ 91 | zlib1g-dev \ 92 | pkg-config 93 | 94 | # https://devtalk.nvidia.com/default/topic/1007290/jetson-tx2/building-opencv-with-opengl-support-/post/5141945/#5141945 95 | cd /usr/local/cuda/include 96 | sudo patch -N cuda_gl_interop.h $WHEREAMI'/patches/OpenGLHeader.patch' 97 | # Clean up the OpenGL tegra libs that usually get crushed 98 | cd /usr/lib/aarch64-linux-gnu/ 99 | sudo ln -sf tegra/libGL.so libGL.so 100 | 101 | # Python 2.7 102 | sudo apt-get install -y python-dev python-numpy python-py python-pytest 103 | # Python 3.5 104 | sudo apt-get install -y python3-dev python3-numpy python3-py python3-pytest 105 | 106 | # GStreamer support 107 | sudo apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev 108 | 109 | cd $OPENCV_SOURCE_DIR 110 | git clone https://github.com/opencv/opencv.git 111 | cd opencv 112 | git checkout -b v${OPENCV_VERSION} ${OPENCV_VERSION} 113 | if [ $OPENCV_VERSION = 3.4.1 ] ; then 114 | # For 3.4.1, use this commit to fix samples/gpu/CMakeLists.txt 115 | git merge ec0bb66 116 | # For 3.4.1, use this to fix C compilation issues (like in YOLO) 117 | git cherry-pick 549b5df 118 | fi 119 | 120 | if [ $DOWNLOAD_OPENCV_EXTRAS == "YES" ] ; then 121 | echo "Installing opencv_extras" 122 | # This is for the test data 123 | cd $OPENCV_SOURCE_DIR 124 | git clone https://github.com/opencv/opencv_extra.git 125 | cd opencv_extra 126 | git checkout -b v${OPENCV_VERSION} ${OPENCV_VERSION} 127 | fi 128 | 129 | cd $OPENCV_SOURCE_DIR/opencv 130 | mkdir build 131 | cd build 132 | 133 | # Here are some options to install source examples and tests 134 | # -D INSTALL_TESTS=ON \ 135 | # -D OPENCV_TEST_DATA_PATH=../opencv_extra/testdata \ 136 | # -D INSTALL_C_EXAMPLES=ON \ 137 | # -D INSTALL_PYTHON_EXAMPLES=ON \ 138 | # There are also switches which tell CMAKE to build the samples and tests 139 | # Check OpenCV documentation for details 140 | 141 | time cmake -D CMAKE_BUILD_TYPE=RELEASE \ 142 | -D CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} \ 143 | -D WITH_CUDA=ON \ 144 | -D CUDA_ARCH_BIN=${ARCH_BIN} \ 145 | -D CUDA_ARCH_PTX="" \ 146 | -D ENABLE_FAST_MATH=ON \ 147 | -D CUDA_FAST_MATH=ON \ 148 | -D WITH_CUBLAS=ON \ 149 | -D WITH_LIBV4L=ON \ 150 | -D WITH_GSTREAMER=ON \ 151 | -D WITH_GSTREAMER_0_10=OFF \ 152 | -D WITH_QT=ON \ 153 | -D WITH_OPENGL=ON \ 154 | ../ 155 | 156 | if [ $? -eq 0 ] ; then 157 | echo "CMake configuration make successful" 158 | else 159 | # Try to make again 160 | echo "CMake issues " >&2 161 | echo "Please check the configuration being used" 162 | exit 1 163 | fi 164 | 165 | # Consider $ sudo nvpmodel -m 2 or $ sudo nvpmodel -m 0 166 | NUM_CPU=$(nproc) 167 | time make -j$(($NUM_CPU - 1)) 168 | if [ $? -eq 0 ] ; then 169 | echo "OpenCV make successful" 170 | else 171 | # Try to make again; Sometimes there are issues with the build 172 | # because of lack of resources or concurrency issues 173 | echo "Make did not build " >&2 174 | echo "Retrying ... " 175 | # Single thread this time 176 | make 177 | if [ $? -eq 0 ] ; then 178 | echo "OpenCV make successful" 179 | else 180 | # Try to make again 181 | echo "Make did not successfully build" >&2 182 | echo "Please fix issues and retry build" 183 | exit 1 184 | fi 185 | fi 186 | 187 | echo "Installing ... " 188 | sudo make install 189 | if [ $? -eq 0 ] ; then 190 | echo "OpenCV installed in: $CMAKE_INSTALL_PREFIX" 191 | else 192 | echo "There was an issue with the final installation" 193 | exit 1 194 | fi 195 | 196 | # check installation 197 | IMPORT_CHECK="$(python -c "import cv2 ; print cv2.__version__")" 198 | if [[ $IMPORT_CHECK != *$OPENCV_VERSION* ]]; then 199 | echo "There was an error loading OpenCV in the Python sanity test." 200 | echo "The loaded version does not match the version built here." 201 | echo "Please check the installation." 202 | echo "The first check should be the PYTHONPATH environment variable." 203 | fi 204 | -------------------------------------------------------------------------------- /patches/OpenGLHeader.patch: -------------------------------------------------------------------------------- 1 | diff --git a/cuda_gl_interop.h b/cuda_gl_interop.h 2 | index 0f4aa17..e8c538c 100644 3 | --- a/cuda_gl_interop.h 4 | +++ b/cuda_gl_interop.h 5 | @@ -59,13 +59,13 @@ 6 | 7 | #else /* __APPLE__ */ 8 | 9 | -#if defined(__arm__) || defined(__aarch64__) 10 | -#ifndef GL_VERSION 11 | -#error Please include the appropriate gl headers before including cuda_gl_interop.h 12 | -#endif 13 | -#else 14 | +//#if defined(__arm__) || defined(__aarch64__) 15 | +//#ifndef GL_VERSION 16 | +//#error Please include the appropriate gl headers before including cuda_gl_interop.h 17 | +//#endif 18 | +//#else 19 | #include 20 | -#endif 21 | +//#endif 22 | 23 | #endif /* __APPLE__ */ 24 | 25 | -------------------------------------------------------------------------------- /removeOpenCVSources.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # License: MIT. See license file in root directory 3 | # Copyright(c) JetsonHacks (2017-2018) 4 | 5 | # Default installation is in the $HOME directory 6 | 7 | OPENCV_SOURCE_DIR=$HOME 8 | 9 | function usage 10 | { 11 | echo "usage: ./removeOpenCVSources.sh [[-s sourcedir ] | [-h]]" 12 | echo "-d | --directory Directory from which to remove the opencv sources (default $HOME)" 13 | echo "-h | --help This message" 14 | } 15 | 16 | # Iterate through command line inputs 17 | while [ "$1" != "" ]; do 18 | case $1 in 19 | -d | --directory ) shift 20 | OPENCV_SOURCE_DIR=$1 21 | ;; 22 | -h | --help ) usage 23 | exit 24 | ;; 25 | * ) usage 26 | exit 1 27 | esac 28 | shift 29 | done 30 | 31 | echo "Removing opencv directory from $OPENCV_SOURCE_DIR" 32 | cd $OPENCV_SOURCE_DIR 33 | 34 | if [ -d "opencv" ] ; then 35 | if [ -L "opencv" ] ; then 36 | echo "opencv is a symlink, unable to remove" 37 | else 38 | echo "Removing opencv sources" 39 | sudo rm -r opencv 40 | fi 41 | else 42 | echo "Could not find opencv directory" 43 | fi 44 | 45 | if [ -d "opencv_extra" ] ; then 46 | if [ -L "opencv_extra" ] ; then 47 | echo "opencv_extra is a symlink, unable to remove" 48 | else 49 | echo "Removing opencv_extra sources" 50 | sudo rm -r opencv_extra 51 | fi 52 | else 53 | echo "Could not find opencv_extra directory" 54 | fi 55 | 56 | -------------------------------------------------------------------------------- /scripts/jetson_easy LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Raffaello Bonghi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /scripts/jetson_variables: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This file is part of the jetson_stats package (https://github.com/rbonghi/jetson_stats or http://rnext.it). 3 | # Copyright (c) 2020 Raffaello Bonghi. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Affero General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Affero General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Affero General Public License 16 | # along with this program. If not, see . 17 | 18 | 19 | # TODO Add enviroments variables: 20 | # - UID -> https://devtalk.nvidia.com/default/topic/996988/jetson-tk1/chip-uid/post/5100481/#5100481 21 | # - GCID, BOARD, EABI 22 | 23 | ########################### 24 | #### JETPACK DETECTION #### 25 | ########################### 26 | # Write version of jetpack installed 27 | # https://developer.nvidia.com/embedded/jetpack-archive 28 | jetson_jetpack() 29 | { 30 | local JETSON_L4T=$1 31 | local JETSON_JETPACK="" 32 | case $JETSON_L4T in 33 | "35.1.0") JETSON_JETPACK="5.0.2" ;; 34 | "34.1.1") JETSON_JETPACK="5.0.1 DP" ;; 35 | "34.1.0") JETSON_JETPACK="5.0 DP" ;; 36 | "32.7.3") JETSON_JETPACK="4.6.3" ;; 37 | "32.7.2") JETSON_JETPACK="4.6.2" ;; 38 | "32.7.1") JETSON_JETPACK="4.6.1" ;; 39 | "32.6.1") JETSON_JETPACK="4.6" ;; 40 | "32.5.1" | "32.5.2") JETSON_JETPACK="4.5.1" ;; 41 | "32.5.0" | "32.5") JETSON_JETPACK="4.5" ;; 42 | "32.4.4") JETSON_JETPACK="4.4.1" ;; 43 | "32.4.3") JETSON_JETPACK="4.4" ;; 44 | "32.4.2") JETSON_JETPACK="4.4 DP" ;; 45 | "32.3.1") JETSON_JETPACK="4.3" ;; 46 | "32.2.3") JETSON_JETPACK="4.2.3" ;; 47 | "32.2.1") JETSON_JETPACK="4.2.2" ;; 48 | "32.2.0" | "32.2") JETSON_JETPACK="4.2.1" ;; 49 | "32.1.0" | "32.1") JETSON_JETPACK="4.2" ;; 50 | "31.1.0" | "31.1") JETSON_JETPACK="4.1.1" ;; 51 | "31.0.2") JETSON_JETPACK="4.1" ;; 52 | "31.0.1") JETSON_JETPACK="4.0" ;; 53 | "28.4.0") JETSON_JETPACK="3.3.3" ;; 54 | "28.2.1") JETSON_JETPACK="3.3 | 3.2.1" ;; 55 | "28.2.0" | "28.2") JETSON_JETPACK="3.2" ;; 56 | "28.1.0" | "28.1") JETSON_JETPACK="3.1" ;; 57 | "27.1.0" | "27.1") JETSON_JETPACK="3.0" ;; 58 | "24.2.1") JETSON_JETPACK="3.0 | 2.3.1" ;; 59 | "24.2.0" | "24.2") JETSON_JETPACK="2.3" ;; 60 | "24.1.0" | "24.1") JETSON_JETPACK="2.2.1 | 2.2" ;; 61 | "23.2.0" | "23.2") JETSON_JETPACK="2.1" ;; 62 | "23.1.0" | "23.1") JETSON_JETPACK="2.0" ;; 63 | "21.5.0" | "21.5") JETSON_JETPACK="2.3.1 | 2.3" ;; 64 | "21.4.0" | "21.4") JETSON_JETPACK="2.2 | 2.1 | 2.0 | 1.2 DP" ;; 65 | "21.3.0" | "21.3") JETSON_JETPACK="1.1 DP" ;; 66 | "21.2.0" | "21.2") JETSON_JETPACK="1.0 DP" ;; 67 | *) JETSON_JETPACK="UNKNOWN" ;; 68 | esac 69 | # return type jetpack 70 | echo $JETSON_JETPACK 71 | } 72 | ########################### 73 | 74 | JETSON_MODEL="UNKNOWN" 75 | # Extract jetson model name 76 | if [ -f /sys/firmware/devicetree/base/model ]; then 77 | JETSON_MODEL=$(tr -d '\0' < /sys/firmware/devicetree/base/model) 78 | fi 79 | 80 | # Extract jetson chip id 81 | JETSON_CHIP_ID="" 82 | if [ -f /sys/module/tegra_fuse/parameters/tegra_chip_id ]; then 83 | JETSON_CHIP_ID=$(cat /sys/module/tegra_fuse/parameters/tegra_chip_id) 84 | fi 85 | # Ectract type board 86 | JETSON_SOC="" 87 | if [ -f /proc/device-tree/compatible ]; then 88 | # Extract the last part of name 89 | JETSON_SOC=$(tr -d '\0' < /proc/device-tree/compatible | sed -e 's/.*,//') 90 | fi 91 | # Extract boardids if exists 92 | JETSON_BOARDIDS="" 93 | if [ -f /proc/device-tree/nvidia,boardids ]; then 94 | JETSON_BOARDIDS=$(tr -d '\0' < /proc/device-tree/nvidia,boardids) 95 | fi 96 | 97 | # Code name 98 | JETSON_CODENAME="" 99 | JETSON_MODULE="UNKNOWN" 100 | JETSON_CARRIER="UNKNOWN" 101 | list_hw_boards() 102 | { 103 | # Extract from DTS the name of the boards available 104 | # Reference: 105 | # 1. https://unix.stackexchange.com/questions/251013/bash-regex-capture-group 106 | # 2. https://unix.stackexchange.com/questions/144298/delete-the-last-character-of-a-string-using-string-manipulation-in-shell-script 107 | local s=$1 108 | local regex='p([0-9-]+)' # Equivalent to p([\d-]*-) 109 | while [[ $s =~ $regex ]]; do 110 | local board_name=$(echo "P${BASH_REMATCH[1]}" | sed 's/-*$//' ) 111 | # Load jetson type 112 | # If jetson type is not empty the module name is the same 113 | if [ $JETSON_MODULE = "UNKNOWN" ] ; then 114 | JETSON_MODULE=$board_name 115 | echo "JETSON_MODULE=\"$JETSON_MODULE\"" 116 | else 117 | JETSON_CARRIER=$board_name 118 | echo "JETSON_CARRIER=\"$JETSON_CARRIER\"" 119 | fi 120 | # Find next match 121 | s=${s#*"${BASH_REMATCH[1]}"} 122 | done 123 | } 124 | # Read DTS file 125 | # 1. https://devtalk.nvidia.com/default/topic/1071080/jetson-nano/best-way-to-check-which-tegra-board/ 126 | # 2. https://devtalk.nvidia.com/default/topic/1014424/jetson-tx2/identifying-tx1-and-tx2-at-runtime/ 127 | # 3. https://devtalk.nvidia.com/default/topic/996988/jetson-tk1/chip-uid/post/5100481/#5100481 128 | if [ -f /proc/device-tree/nvidia,dtsfilename ]; then 129 | # ../hardware/nvidia/platform/t210/porg/kernel-dts/tegra210-p3448-0000-p3449-0000-b00.dts 130 | # The last third is the codename of the board 131 | JETSON_CODENAME=$(tr -d '\0' < /proc/device-tree/nvidia,dtsfilename) 132 | JETSON_CODENAME=$(echo ${JETSON_CODENAME#*"/hardware/nvidia/platform/"} | tr '/' '\n' | head -2 | tail -1 ) 133 | # The basename extract the board type 134 | JETSON_DTS="$(tr -d '\0' < /proc/device-tree/nvidia,dtsfilename | sed 's/.*\///')" 135 | # List of all boards 136 | eval $(list_hw_boards "$JETSON_DTS") 137 | fi 138 | 139 | # Export variables 140 | export JETSON_MODEL 141 | export JETSON_CHIP_ID 142 | export JETSON_SOC 143 | export JETSON_BOARDIDS 144 | export JETSON_CODENAME 145 | export JETSON_MODULE 146 | export JETSON_CARRIER 147 | 148 | # Write CUDA architecture 149 | # https://developer.nvidia.com/cuda-gpus 150 | # https://devtalk.nvidia.com/default/topic/988317/jetson-tx1/what-should-be-the-value-of-cuda_arch_bin/ 151 | case $JETSON_MODEL in 152 | *Orin*) JETSON_CUDA_ARCH_BIN="8.7" ;; 153 | *Xavier*) JETSON_CUDA_ARCH_BIN="7.2" ;; 154 | *TX2*) JETSON_CUDA_ARCH_BIN="6.2" ;; 155 | *TX1* | *Nano*) JETSON_CUDA_ARCH_BIN="5.3" ;; 156 | *TK1*) JETSON_CUDA_ARCH_BIN="3.2" ;; 157 | * ) JETSON_CUDA_ARCH_BIN="NONE" ;; 158 | esac 159 | # Export Jetson CUDA ARCHITECTURE 160 | export JETSON_CUDA_ARCH_BIN 161 | 162 | # Serial number 163 | # https://devtalk.nvidia.com/default/topic/1055507/jetson-nano/nano-serial-number-/ 164 | JETSON_SERIAL_NUMBER="" 165 | if [ -f /sys/firmware/devicetree/base/serial-number ]; then 166 | JETSON_SERIAL_NUMBER=$(tr -d '\0'