### Install Python Examples for Jetson Inference Source: https://github.com/dusty-nv/jetson-inference/blob/master/python/CMakeLists.txt This CMake code snippet handles the installation of Python example files. It uses `file(GLOB ...)` to find all `.py` files in the `examples/` directory and then copies them to the runtime output directory and installs them to the `bin` directory. ```cmake file(GLOB pyInferenceExamples examples/*.py) foreach(pyExample ${pyInferenceExamples}) message("-- Copying ${pyExample}") file(COPY ${pyExample} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) install(FILES "${pyExample}" DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) endforeach() ``` -------------------------------- ### Run Flask Web Server and DNN Example Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/webrtc-flask.md Command to launch the Flask webserver and start the WebRTC streaming thread with specified DNN models for detection, pose estimation, and action recognition. It requires navigating to the Flask directory and installing dependencies. ```bash cd jetson-inference/python/www/flask pip3 install -r requirements.txt python3 app.py --detection=ssd-mobilenet-v2 --pose=resnet18-hand --action=resnet18-kinetics ``` -------------------------------- ### Video Viewer Python Example Setup Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/aux-streaming.md Initializes the video viewer script in Python by parsing command-line arguments for input and output URIs. It uses argparse for handling arguments and jetson_utils for accessing video streams. ```python import sys import argparse from jetson_utils import videoSource, videoOutput # parse command line parser = argparse.ArgumentParser() parser.add_argument("input", type=str, help="URI of the input stream") parser.add_argument("output", type=str, default="", nargs='?', help="URI of the output stream") args = parser.parse_known_args()[0] ``` -------------------------------- ### Running JetPack Installer Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/jetpack-setup.md Commands to download and execute the JetPack installer script on a Linux host PC. This script initiates the GUI for setting up the Jetson environment. ```bash cd chmod +x JetPack-L4T--linux-x64.run ./JetPack-L4T--linux-x64.run ``` -------------------------------- ### Replicate Legacy Python Examples Installation Source: https://github.com/dusty-nv/jetson-inference/blob/master/python/CMakeLists.txt This CMake function, `copy_install`, is used to replicate legacy Python examples. It copies a specified input file to the runtime output directory and installs it to the `bin` directory with specific file permissions. ```cmake function(copy_install file_in file_out) message("-- Copying ${file_in} -> ${file_out}") configure_file(${file_in} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${file_out} COPYONLY) install(FILES "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${file_out}" DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) endfunction() ``` -------------------------------- ### Install Docker and NVIDIA Docker 2 on Ubuntu Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/digits-setup.md Installs Docker Engine and the NVIDIA Docker 2 utility on an Ubuntu system. This involves adding Docker's GPG key and repository, followed by adding the nvidia-docker repository. It configures Docker to run without sudo and requires a system reboot. ```bash sudo apt-get install -y ca-certificates curl software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | \ sudo apt-key add - curl -s -L https://nvidia.github.io/nvidia-docker/ubuntu16.04/amd64/nvidia-docker.list | \ sudo tee /etc/apt/sources.list.d/nvidia-docker.list sudo apt-get update sudo apt-get install -y nvidia-docker2 sudo usermod -aG docker $USER sudo reboot ``` -------------------------------- ### Install NVIDIA Driver (Bash) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/digits-native.md Installs the NVIDIA driver from the Ubuntu repository. Requires root privileges and a system reboot to take effect. This step is crucial for GPU-accelerated training. ```bash sudo apt-get install nvidia-384 # use nvidia-375 for alternate version sudo reboot ``` -------------------------------- ### Process Video Files with detectnet (C++/Python) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/detectnet-console-2.md Demonstrates processing video files from disk. The examples include downloading a sample video and then running detectnet on it using both C++ and Python. Output is saved to a new video file. ```bash # Download test video wget https://nvidia.box.com/shared/static/veuuimq6pwvd62p9fresqhrrmfqz0e2f.mp4 -O pedestrians.mp4 # C++ ./detectnet pedestrians.mp4 images/test/pedestrians_ssd.mp4 # Python ./detectnet.py pedestrians.mp4 images/test/pedestrians_ssd.mp4 ``` ```bash # Download test video wget https://nvidia.box.com/shared/static/i5i81mkd9wdh4j7wx04th961zks0lfh9.avi -O parking.avi # C++ ./detectnet parking.avi images/test/parking_ssd.avi # Python ./detectnet.py parking.avi images/test/parking_ssd.avi ``` -------------------------------- ### Install NVIDIA Driver on Ubuntu 16.04 Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/digits-setup.md Installs the NVIDIA driver on an Ubuntu 16.04 host system by adding the NVIDIA Developer repository and the CUDA repository. It also sets a package preference for CUDA components and installs the CUDA drivers. A reboot is required after installation. ```bash sudo apt-get install -y apt-transport-https curl cat < /dev/null deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64 / EOF curl -s \ https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub \ | sudo apt-key add - cat < /dev/null Package: * Pin: origin developer.download.nvidia.com Pin-Priority: 600 EOF sudo apt-get update && sudo apt-get install -y --no-install-recommends cuda-drivers sudo reboot ``` -------------------------------- ### Install PyTorch (Bash) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/building-repo-2.md This command executes a script within the build directory to install PyTorch. The installation is optional and intended for users who plan to perform network retraining using transfer learning. It provides a dialog to select desired PyTorch package versions. ```bash cd jetson-inference/build ./install-pytorch.sh ``` -------------------------------- ### Example Bash Command for Image Classification Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/imagenet-example-python-2.md These bash commands demonstrate how to run the image classification Python script. The first example shows basic usage with a specified image file. The second example shows how to optionally specify a different classification network using the `--network` flag. ```bash $ ./my-recognition.py my_image.jpg ``` ```bash $ ./my-recognition.py --network=resnet-18 my_image.jpg ``` -------------------------------- ### Install cuDNN Libraries (Bash) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/digits-native.md Installs the NVIDIA cuDNN (CUDA Deep Neural Network) libraries on the host PC. This involves downloading .deb packages and installing them using dpkg. Replace with the actual cuDNN version number. ```bash sudo dpkg -i libcudnn_amd64.deb sudo dpkg -i libcudnn-dev__amd64.deb ``` -------------------------------- ### Install iPython and Pandas (Bash) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/building-nvcaffe.md Installs iPython, iPython Notebook, and the Pandas library, which are optional but useful for interactive development and data analysis with nvcaffe. ```bash sudo apt-get install ipython ipython-notebook python-pandas -y ``` -------------------------------- ### JavaScript Webcam Stream and Playback Functions Source: https://github.com/dusty-nv/jetson-inference/blob/master/python/www/html/index.html This snippet defines core JavaScript functions for handling webcam streams and video playback. It includes 'play' to start streaming, 'send' to initiate sending the stream, and setup logic for accessing and listing available camera devices. It requires the browser to support media devices and potentially HTTPS for full functionality. ```javascript play = function() { playStream(document.getElementById('play-stream').value, document.getElementById('video-player')); }; send = function() { if( sendStream(getWebsocketURL('input'), document.getElementById('send-stream').value) ) play(); // autoplay browser stream } window.onload = function() { var playStream = document.getElementById('play-stream'); var sendStream = document.getElementById('send-stream'); var sendButton = document.getElementById('send-button'); playStream.value = getWebsocketURL('output'); // populate the list of browser video devices (requires HTTPS) if( checkMediaDevices() ) { navigator.mediaDevices.getUserMedia({audio: false, video: true}).then((stream) => { // get permission from user navigator.mediaDevices.enumerateDevices().then((devices) => { stream.getTracks().forEach(track => track.stop()); // close the device opened to get permissions devices.forEach((device) => { if( device.kind == 'videoinput' ) { console.log(`Browser media device: ${device.kind} label=${device.label} id=${device.deviceId}`); sendStream.add(new Option(device.label, device.deviceId)); } }); if( sendStream.options.length == 0 ) { sendStream.add(new Option('browser has no webcams available')); sendButton.disabled = true; } }); }).catch(reportError); } else { sendStream.add(new Option('use HTTPS to enable browser webcam')); sendButton.disabled = true; } } ``` -------------------------------- ### Import detectnet Python Example Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/detectnet-console-2.md This Python code snippet shows the necessary imports for the detectnet example script. It imports the jetson.inference and jetson.utils modules, along with argparse and sys for command-line argument handling. ```python import jetson.inference import jetson.utils import argparse import sys ``` -------------------------------- ### Video Viewer Output Options and Stream Examples Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/aux-streaming.md This section outlines the command-line arguments for configuring the output of video streams from the video-viewer tool. It covers specifying output URIs, codecs, encoder types, and saving streams to files. Examples demonstrate how to use these options with MIPI CSI and V4L2 cameras. ```bash $ video-viewer csi://0 # MIPI CSI camera 0 (substitue other camera numbers) $ video-viewer csi://0 output.mp4 # save output stream to MP4 file (H.264 by default) $ video-viewer csi://0 rtp://:1234 # broadcast output stream over RTP to $ video-viewer --input-width=1920 --input-height=1080 csi://0 $ video-viewer v4l2:///dev/video0 # /dev/video0 can be replaced with /dev/video1, ect. $ video-viewer /dev/video0 # dropping the v4l2:// protocol prefix is fine $ video-viewer /dev/video0 output.mp4 # save output stream to MP4 file (H.264 by default) $ video-viewer /dev/video0 rtp://:1234 # broadcast output stream over RTP to ``` -------------------------------- ### CMake Installation of Libraries, Headers, and Data Symlinks Source: https://github.com/dusty-nv/jetson-inference/blob/master/CMakeLists.txt Installs the compiled `jetson-inference` library, headers, and creates symbolic links for data to the installation prefix. It also installs CMake configuration files for external projects to import the library. ```cmake # install includes foreach(include ${inferenceIncludes}) install(FILES "${include}" DESTINATION include/jetson-inference) endforeach() # install symlink to networks and images install(CODE "execute_process( COMMAND ${CMAKE_COMMAND} -E create_symlink ${PROJECT_SOURCE_DIR}/data/networks ${CMAKE_INSTALL_PREFIX}/bin/networks )" ) install(CODE "execute_process( COMMAND ${CMAKE_COMMAND} -E create_symlink ${PROJECT_SOURCE_DIR}/data/images ${CMAKE_INSTALL_PREFIX}/bin/images )" ) # install the shared library install(TARGETS jetson-inference DESTINATION lib EXPORT jetson-inferenceConfig) # install the cmake project, for importing install(EXPORT jetson-inferenceConfig DESTINATION share/jetson-inference/cmake) # run ldconfig after installing install(CODE "execute_process( COMMAND ldconfig )") ``` -------------------------------- ### Test nvcaffe Installation (Bash) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/building-nvcaffe.md Runs the test suite for nvcaffe to verify that the compilation and installation were successful and that the library is functioning correctly. ```bash make runtest ``` -------------------------------- ### Importing Jetson Inference Modules in Python Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/detectnet-example-2.md Imports the necessary Python modules, 'detectNet' from 'jetson_inference' and 'videoSource', 'videoOutput' from 'jetson_utils', for building object detection applications on NVIDIA Jetson devices. These modules must be installed via 'sudo make install'. ```python from jetson_inference import detectNet from jetson_utils import videoSource, videoOutput ``` -------------------------------- ### Run detectnet with Specific Models (C++/Python) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/detectnet-console-2.md This example shows how to specify a particular pre-trained detection model using the `--network` flag. It defaults to SSD-Mobilenet-v2 if no network is specified. Supports both C++ and Python. ```bash # C++ $ ./detectnet --network=ssd-inception-v2 input.jpg output.jpg # Python $ ./detectnet.py --network=ssd-inception-v2 input.jpg output.jpg ``` -------------------------------- ### Python Module Imports for Jetson Inference Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/imagenet-example-python-2.md Imports the necessary Python modules for image recognition tasks on Jetson devices. It includes 'jetson.inference' for neural network models, 'jetson.utils' for image loading and manipulation, and 'argparse' for handling command-line arguments. These modules must be installed via 'sudo make install'. ```python import jetson.inference import jetson.utils import argparse ``` -------------------------------- ### Set Up Image Recognition Project Directory Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/imagenet-example.md Creates a directory for the 'my-recognition' project and downloads test images using wget. This sets up the basic file structure and sample data needed for the image recognition program. ```bash mkdir ~/my-recognition cd ~/my-recognition touch my-recognition.cpp touch CMakeLists.txt wget https://github.com/dusty-nv/jetson-inference/raw/master/data/images/black_bear.jpg wget https://github.com/dusty-nv/jetson-inference/raw/master/data/images/brown_bear.jpg wget https://github.com/dusty-nv/jetson-inference/raw/master/data/images/polar_bear.jpg ``` -------------------------------- ### Bash Commands for Setting Up Python Project Directory Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/imagenet-example-python-2.md This bash script sets up the necessary directory structure and downloads sample image files for a Python image recognition project. It creates a directory `~/my-recognition-python`, an empty file `my-recognition.py`, makes it executable, and downloads three JPEG images (black_bear.jpg, brown_bear.jpg, polar_bear.jpg) for testing. ```bash # run these commands outside of container $ cd ~/ $ mkdir my-recognition-python $ cd my-recognition-python $ touch my-recognition.py $ chmod +x my-recognition.py $ wget https://github.com/dusty-nv/jetson-inference/raw/master/data/images/black_bear.jpg $ wget https://github.com/dusty-nv/jetson-inference/raw/master/data/images/brown_bear.jpg $ wget https://github.com/dusty-nv/jetson-inference/raw/master/data/images/polar_bear.jpg ``` -------------------------------- ### Get Drag Coordinates (C++) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/glDisplay_8h_source.html Retrieves the start and end coordinates (x1, y1, x2, y2) of the current drag operation. This provides the precise start and end points of the drag. ```C++ bool GetDragCoords( int* x1, int* y1, int* x2, int* y2 ); ``` -------------------------------- ### Get Drag Start and End Coordinates (C++) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/group__OpenGL.html Retrieves the starting and ending coordinates of the current mouse drag. Returns false if no drag is active. The coordinates are output through the provided integer pointers. ```cpp bool GetDragCoords(int* x1, int* y1, int* x2, int* y2); ``` -------------------------------- ### Include Headers for Image Recognition and Loading Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/imagenet-example.md Includes the necessary C++ headers for image recognition ('imageNet.h') and image loading ('loadImage.h') from the jetson-inference and jetson-utils libraries. These headers are typically found in '/usr/local/include' after installation. ```cpp // include imageNet header for image recognition #include // include loadImage header for loading images #include ``` -------------------------------- ### Configure Project with CMake (Bash) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/building-repo-2.md These commands navigate into the jetson-inference project directory, create a build subdirectory, and then execute CMake to configure the project. The CMake process automatically runs a script to install prerequisites and download DNN models. ```bash cd jetson-inference mkdir build cd build cmake ../ ``` -------------------------------- ### Create detectNet Network Instance (Command Line) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/group__detectNet.html Loads a new detectNet network instance by parsing configuration options from a commandLine object. This is a convenient way to load networks with pre-defined parameters. ```cpp static detectNet* detectNet::Create( const commandLine& cmdLine ) ``` -------------------------------- ### Get current application time in nanoseconds Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/timespec_8h_source.html Calculates and returns the current application time as a 64-bit unsigned integer representing nanoseconds. This provides a high-resolution measurement of the elapsed time since the application started. It internally uses the `apptime` function. ```cpp uint64_t apptime_nano() { timespec t; apptime(&t); return (uint64_t)t.tv_sec * uint64_t(1000000000) + (uint64_t)t.tv_nsec; } ``` -------------------------------- ### JavaScript: Initialize and Control Video Stream Playback Source: https://github.com/dusty-nv/jetson-inference/blob/master/python/www/recognizer/templates/index.html Initializes video stream playback by getting values from input elements and playing the stream. It handles autoplay for browser streams and populates lists of available video devices. Includes error handling and setup for tooltips and mobile navigation. ```javascript play = function() { playStream(document.getElementById('play-stream').value, document.getElementById('video-player')); }; send = function() { if( sendStream(getWebsocketURL('input'), document.getElementById('send-stream').value) ) play(); // autoplay browser stream } window.onload = function() { var playStream = document.getElementById('play-stream'); var sendStream = document.getElementById('send-stream'); var sendButton = document.getElementById('send-button'); playStream.value = getWebsocketURL('output'); {% if send_webrtc %} // populate the list of browser video devices (requires HTTPS) if( checkMediaDevices() ) { navigator.mediaDevices.getUserMedia({audio: false, video: true}).then((stream) => { // get permission from user navigator.mediaDevices.enumerateDevices().then((devices) => { stream.getTracks().forEach(track => track.stop()); // close the device opened to get permissions devices.forEach((device) => { if( device.kind == 'videoinput' ) { console.log(`Browser media device: ${device.kind} label=${device.label} id=${device.deviceId}`); sendStream.add(new Option(device.label, device.deviceId)); } }); if( sendStream.options.length == 0 ) { sendStream.add(new Option('browser has no webcams available')); sendButton.disabled = true; } }); }).catch(reportError); } else { sendStream.add(new Option('use HTTPS to enable browser webcam')); sendButton.disabled = true; } {% else %} // auto-play other sources, since they're already running play(); // hide the camera switching button (d-none is boostrap for display: none) document.getElementById('switch-camera-div').classList.add('d-none'); {% endif %} // enable bootstrap tooltips const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]'); const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl)); // add the initial tag options populateTagOptions(); onTagsChanged(); // move the navbar to the bottom on mobile console.log(`Browser: ${navigator.userAgent}`); console.log(`Vendor: ${navigator.vendor}`); if( isMobileBrowser() ) { document.getElementById('bottom-div').appendChild(document.getElementById('navbar-div')); } } ``` -------------------------------- ### Include Headers for Image Recognition and Loading Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/imagenet-example-2.md Includes necessary C++ headers for image recognition (imageNet) and image loading (loadImage). These headers are typically installed in '/usr/local/include' after building the project. ```cpp #include #include ``` -------------------------------- ### Check for XML Name Start Character in C++ (tinyxml2) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/xml_8h_source.html Checks if a character is a valid start character for an XML name. It considers alphabetic characters, underscores, and colons as valid starting characters. For characters outside the ASCII range (>= 128), it assumes they are valid name start characters as a heuristic. ```cpp static bool IsNameStartChar( unsigned char ch ) { if ( ch >= 128 ) { // This is a heuristic guess in attempt to not implement Unicode-aware isalpha() return true; } if ( isalpha( ch ) ) { return true; } return ch == ':' || ch == '_'; } ``` -------------------------------- ### Python Video Configuration Options Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/aux-streaming.md Demonstrates how to hardcode video configuration settings like resolution, framerate, and flip method for video sources, and codec and bitrate for video outputs using an 'options' dictionary. ```python # Assume videoSource and videoOutput are imported # from jetson_inference import videoSource, videoOutput # Placeholder for actual imports if running standalone class MockVideoSource: def __init__(self, input_path, argv=None, options=None): self.input_path = input_path self.options = options or {} print(f"VideoSource initialized with input: {self.input_path}, options: {self.options}") class MockVideoOutput: def __init__(self, output_path, argv=None, options=None): self.output_path = output_path self.options = options or {} print(f"VideoOutput initialized with output: {self.output_path}, options: {self.options}") videoSource = MockVideoSource videoOutput = MockVideoOutput # --- Original Code --- input_stream = videoSource("/dev/video0", options={'width': 1280, 'height': 720, 'framerate': 30, 'flipMethod': 'rotate-180'}) output_stream = videoOutput("my_video.mp4", options={'codec': 'h264', 'bitrate': 4000000}) ``` -------------------------------- ### Configure Video Input and Output with Jetson Utils Source: https://context7.com/dusty-nv/jetson-inference/llms.txt Demonstrates how to configure various video input sources (cameras, files, streams) and output destinations (display, files, streams) using the `jetson_utils` library. It shows instantiation of `videoSource` and `videoOutput` objects with different options and arguments, including codecs and bitrates for file output and streaming protocols. ```python #!/usr/bin/env python3 from jetson_utils import videoSource, videoOutput # Input source options: # - Camera: "csi://0" (CSI), "/dev/video0" (V4L2), "v4l2:///dev/video0" # - Video file: "file://video.mp4", "video.mkv" # - Image: "image.jpg", "directory/*.jpg" (sequence) # - Network stream: "rtsp://username:password@ip:port", "rtp://@:1234" # - Headless (null): "null" input = videoSource("csi://0", argv=['--input-width=1280', '--input-height=720']) # Output destination options: # - Display: "display://0" # - Video file: "file://output.mp4", "output.mkv" # - Image: "image-%i.jpg" (sequence with frame number) # - Network stream: "rtsp://@:8554/stream", "webrtc://@:8554/stream" # - Headless: "null" output = videoOutput("display://0") # Video file with codec options output_file = videoOutput("output.mp4", argv=[ '--output-codec=h264', # or h265, vp8, vp9, mjpeg '--bitrate=4000000' # bits per second ]) # Network streaming rtsp_output = videoOutput("rtsp://@:8554/stream") # WebRTC streaming for web browsers webrtc_output = videoOutput("webrtc://@:8554/stream") # Process frames while True: img = input.Capture() if img is None: continue # Get image properties width = img.width height = img.height format = img.format print(f"Frame: {width}x{height}, format: {format}") # Render to multiple outputs output.Render(img) output_file.Render(img) # Set status bar text output.SetStatus("Processing... 30 FPS") if not input.IsStreaming() or not output.IsStreaming(): break ``` -------------------------------- ### ActionNet Creation with Command Line Arguments Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/actionNet_8h_source.html This static method creates an instance of the ActionNet class using command-line arguments. It parses input arguments to configure the network, specifying model paths, input/output formats, batch size, precision, and device. This is a common way to initialize the network with user-defined parameters. ```cpp static actionNet* Create( int argc, char** argv ); ``` -------------------------------- ### Run Pre-Build Dependency Installer (CMake) Source: https://github.com/dusty-nv/jetson-inference/blob/master/CMakeLists.txt Executes a pre-build dependency installation script if the BUILD_DEPS variable is set to 'YES'. This script ensures all necessary libraries and tools are installed before the main build process begins. The BUILD_DEPS variable is automatically reset to 'NO' after execution. ```cmake if( ${BUILD_DEPS} ) message("-- Launching pre-build dependency installer script...") message("-- Build interactive: ${BUILD_INTERACTIVE}") execute_process(COMMAND sh ../CMakePreBuild.sh ${BUILD_INTERACTIVE} WORKING_DIRECTORY ${PROJECT_BINARY_DIR} RESULT_VARIABLE PREBUILD_SCRIPT_RESULT) set(BUILD_DEPS "NO" CACHE BOOL "If YES, will install dependencies into sandbox. Automatically reset to NO after dependencies are installed." FORCE) message("-- Finished installing dependencies") endif() ``` -------------------------------- ### Get Class Information - segNet C++ Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/segNet_8h_source.html Retrieves information about segmentation classes. Functions are provided to find a class ID by its label name, get the total number of classes, retrieve the label string for a given class ID, and get the color associated with a class ID. ```cpp int FindClassID( const char* label_name ); ``` ```cpp inline uint32_t GetNumClasses() const { return DIMS_C([mOutputs[0].dims]); } ``` ```cpp inline const char* GetClassLabel( uint32_t id ) const { return GetClassDesc(id); } ``` ```cpp inline const char* GetClassDesc( uint32_t id ) const { return id < mClassLabels.size() ? mClassLabels[id].c_str() : NULL; } ``` ```cpp inline float4 GetClassColor( uint32_t id ) const { return mClassColors[id]; } ``` -------------------------------- ### Clone DIGITS Repository (Bash) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/digits-native.md Clones the DIGITS (Deep Learning GPU Training System) repository from GitHub. DIGITS is a web service for training DNNs and managing datasets, primarily used on the host PC for training. ```bash git clone https://github.com/nvidia/DIGITS ``` -------------------------------- ### Configure CMakeLists.txt for Jetson Inference Project (CMake) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/imagenet-example.md Sets up the CMake build system for a project that uses the jetson-inference and jetson-utils libraries. It specifies required CMake versions, project name, finds necessary packages (including CUDA and Qt4), and links the executable to the jetson-inference library. ```cmake # require CMake 2.8 or greater cmake_minimum_required(VERSION 2.8) # declare my-recognition project project(my-recognition) # import jetson-inference and jetson-utils packages. # note that if you didn't do "sudo make install" # while building jetson-inference, this will error. find_package(jetson-utils) find_package(jetson-inference) # CUDA and Qt4 are required find_package(CUDA) find_package(Qt4) # setup Qt4 for build include(${QT_USE_FILE}) add_definitions(${QT_DEFINITIONS}) # compile the my-recognition program cuda_add_executable(my-recognition my-recognition.cpp) # link my-recognition to jetson-inference library target_link_libraries(my-recognition jetson-inference) ``` -------------------------------- ### Install Dependencies and Build Jetson-Inference (Bash) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/building-repo-2.md This bash script updates the package list, installs essential build tools and Python development packages, clones the jetson-inference repository, and then builds and installs the project using CMake and Make. It concludes with a command to update the dynamic linker cache. ```bash sudo apt-get update sudo apt-get install git cmake libpython3-dev python3-numpy git clone --recursive --depth=1 https://github.com/dusty-nv/jetson-inference cd jetson-inference mkdir build cd build cmake ../ make -j$(nproc) sudo make install sudo ldconfig ``` -------------------------------- ### WebRTCServer - Create Server Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/classWebRTCServer-members.html Creates and initializes a WebRTC server instance. This method sets up the server to listen on a specified port and optionally configure STUN server and SSL certificates. ```APIDOC ## POST /webrtc/server/create ### Description Creates and initializes a WebRTC server instance. This method sets up the server to listen on a specified port and optionally configure STUN server and SSL certificates. ### Method POST ### Endpoint /webrtc/server/create ### Parameters #### Request Body - **port** (uint16_t) - Optional - The port to listen on. Defaults to WEBRTC_DEFAULT_PORT. - **stun_server** (const char*) - Optional - The STUN server address. Defaults to WEBRTC_DEFAULT_STUN_SERVER. - **ssl_cert** (const char*) - Optional - Path to the SSL certificate file. - **ssl_key** (const char*) - Optional - Path to the SSL key file. - **threaded** (bool) - Optional - Whether to run the server in a separate thread. Defaults to true. ### Request Example ```json { "port": 8080, "stun_server": "stun.l.google.com:19302", "ssl_cert": "/path/to/cert.pem", "ssl_key": "/path/to/key.pem", "threaded": true } ``` ### Response #### Success Response (200) - **server_id** (string) - An identifier for the created server instance. #### Response Example ```json { "server_id": "server_12345" } ``` ``` -------------------------------- ### Verify NVIDIA Driver and CUDA Toolkit (Bash) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/digits-native.md Verifies that the NVIDIA driver is loaded and that the CUDA toolkit is functional by running included samples. It checks for the nvidia_uvm module and then compiles and runs deviceQuery and bandwidthTest. ```bash lsmod | grep nvidia cd /usr/local/cuda/samples sudo make cd bin/x86_64/linux/release/ ./deviceQuery ./bandwidthTest --memory=pinned ``` -------------------------------- ### Clone Jetson-Inference Repository (Bash) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/building-repo-2.md This sequence of bash commands first ensures git and cmake are installed, then clones the jetson-inference repository, changes the directory into it, and initializes its submodules. The submodule initialization is crucial for fetching all necessary components of the project. ```bash sudo apt-get update sudo apt-get install git cmake git clone https://github.com/dusty-nv/jetson-inference cd jetson-inference git submodule update --init ``` -------------------------------- ### poseNet: Pose Detection Usage Example Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/classposeNet-members.html Provides a usage example or entry point for the poseNet functionality. This might detail how to instantiate and run pose detection. ```cpp inlinestatic Usage(); ``` -------------------------------- ### Get Network Output Pointer Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/group__poseNet.html Gets the CUDA pointer to the output memory of a specified layer. This allows direct access to the network's output data on the GPU. ```APIDOC ## GET /api/network/output/ptr ### Description Gets the CUDA pointer to the output memory of a specified layer. ### Method GET ### Endpoint /api/network/output/ptr ### Parameters #### Query Parameters - **layer** (uint32_t) - Optional - Specifies the layer index. Defaults to 0. ### Response #### Success Response (200) - **pointer** (string) - The CUDA pointer address as a string (e.g., "0x..."). #### Response Example ```json { "pointer": "0x7f8a01234567" } ``` ``` -------------------------------- ### Build and Run Recognition Program (Shell) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/imagenet-example-2.md These shell commands outline the process of compiling and executing a C++ recognition program. It involves navigating to the project directory, configuring the build using CMake, and then compiling the code with 'make'. The example also shows how to run the compiled program with image files as arguments to classify them. ```bash $ cd ~/my-recognition $ cmake . $ make ``` ```bash $ ./my-recognition polar_bear.jpg image is recognized as 'ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus' (class #296) with 99.999878% confidence ``` ```bash $ ./my-recognition brown_bear.jpg image is recognized as 'brown bear, bruin, Ursus arctos' (class #294) with 99.928925% confidence ``` ```bash $ ./my-recognition black_bear.jpg image is recognized as 'American black bear, black bear, Ursus americanus, Euarctos americanus' (class #295) with 98.898628% confidence ``` -------------------------------- ### Copy Installation Scripts (CMake) Source: https://github.com/dusty-nv/jetson-inference/blob/master/CMakeLists.txt Copies necessary shell scripts and configuration files for installing PyTorch to the build directory. These scripts are used later in the build process to set up the PyTorch environment. ```cmake file(COPY "tools/install-pytorch.sh" DESTINATION ${PROJECT_BINARY_DIR}) file(COPY "tools/install-pytorch.rc" DESTINATION ${PROJECT_BINARY_DIR}) ``` -------------------------------- ### KeyboardDevice Creation and Management (C++) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/classKeyboardDevice.html Demonstrates how to create and manage a KeyboardDevice instance. It includes creating the device with a specified path and its destructor for cleanup. The Create function takes an optional path to the input device file. ```cpp /* * @brief Create device. * @param path The input device path. Defaults to "/dev/input/by-path/platform-i8042-serio-0-event-kbd". * @return A pointer to the created KeyboardDevice instance. */ static KeyboardDevice* Create(const char* path = "/dev/input/by-path/platform-i8042-serio-0-event-kbd"); /* * @brief Destructor. */ ~KeyboardDevice(); ``` -------------------------------- ### Verify PyTorch and CUDA Installation Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/pytorch-transfer-learning.md Python code to verify the PyTorch and TorchVision installation, and to confirm that the CUDA GPU is detected and functional. It prints the versions and performs basic tensor operations on the GPU. ```python import torch print(torch.__version__) print('CUDA available: ' + str(torch.cuda.is_available())) a = torch.cuda.FloatTensor(2).zero_() print('Tensor a = ' + str(a)) b = torch.randn(2).cuda() print('Tensor b = ' + str(b)) c = a + b print('Tensor c = ' + str(c)) ``` ```python import torchvision print(torchvision.__version__) ``` -------------------------------- ### Enable Object Tracking with detectnet Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/detectnet-tracking.md This command-line snippet demonstrates how to enable object tracking when running the detectnet utility. It includes downloading a sample video and then running detectnet with the `--tracking` flag in both C++ and Python. ```bash # Download test video wget https://nvidia.box.com/shared/static/veuuimq6pwvd62p9fresqhrrmfqz0e2f.mp4 -O pedestrians.mp4 # C++ $ detectnet --model=peoplenet --tracking pedestrians.mp4 pedestrians_tracking.mp4 # Python $ detectnet.py --model=peoplenet --tracking pedestrians.mp4 pedestrians_tracking.mp4 ``` -------------------------------- ### Install nvcaffe Dependencies (Bash) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/building-nvcaffe.md Installs essential dependencies for building nvcaffe using apt-get. Includes cmake, protobuf, leveldb, snappy, hdf5, boost, BLAS, gflags, glog, lmdb, and Python development packages. ```bash sudo apt-get update -y sudo apt-get install cmake -y # General dependencies sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev \ libhdf5-serial-dev protobuf-compiler -y sudo apt-get install --no-install-recommends libboost-all-dev -y # BLAS sudo apt-get install libatlas-base-dev -y # Remaining Dependencies sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev -y # Python Dependencies sudo apt-get install python-dev python-numpy python-skimage python-protobuf -y ``` -------------------------------- ### Run Jetson Inference Applications Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/aux-docker.md Demonstrates how to execute sample applications like `video-viewer`, `imagenet`, and `detectnet` after the jetson-inference container is running. These commands are executed from the build directory within the container. Images saved from these applications are recommended to be stored in `images/test` for easy host access. ```bash $ cd build/aarch64/bin $ ./video-viewer /dev/video0 $ ./imagenet images/jellyfish.jpg images/test/jellyfish.jpg $ ./detectnet images/peds_0.jpg images/test/peds_0.jpg # (press Ctrl+D to exit the container) ``` -------------------------------- ### segNet Creation Overloads Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/segNet_8h_source.html Provides multiple static methods for creating segNet instances. These methods allow initialization with a network name, model paths, command-line arguments, or a command-line object. They support configuration of batch size, precision, and device type. ```cpp static segNet* Create( const char* network="fcn-resnet18-voc", uint32_t maxBatchSize=DEFAULT_MAX_BATCH_SIZE, precisionType precision=TYPE_FASTEST, deviceType device=DEVICE_GPU, bool allowGPUFallback=true ); ``` ```cpp static segNet* Create( const char* prototxt_path, const char* model_path, const char* class_labels, const char* class_colors=NULL, const char* input = SEGNET_DEFAULT_INPUT, const char* output = SEGNET_DEFAULT_OUTPUT, uint32_t maxBatchSize=DEFAULT_MAX_BATCH_SIZE, precisionType precision=TYPE_FASTEST, deviceType device=DEVICE_GPU, bool allowGPUFallback=true ); ``` ```cpp static segNet* Create( int argc, char** argv ); ``` ```cpp static segNet* Create( const commandLine& cmdLine ); ``` -------------------------------- ### Get ImageNet Class Information Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/classimageNet.html Retrieves information about a specific image recognition class by its index. Methods are available to get the class description, label, synset category, and the path to the file containing class descriptions. ```cpp const char* imageNet::GetClassDesc( int _index_ ) ``` ```cpp const char* imageNet::GetClassLabel( int _index_ ) ``` ```cpp const char* imageNet::GetClassPath( void ) ``` ```cpp const char* imageNet::GetClassSynset( int _index_ ) ``` -------------------------------- ### TensorRT Version Check Macro (C++) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/group__tensorNet.html A macro to check if the installed TensorRT version meets a specified major, minor, and patch version. It evaluates to true if the installed version is greater than or equal to the specified version. ```cpp #define TENSORRT_VERSION_CHECK( major, minor, patch ) ( (NV_TENSORRT_MAJOR > major || (NV_TENSORRT_MAJOR == major && NV_TENSORRT_MINOR > minor) || (NV_TENSORRT_MAJOR == major && NV_TENSORRT_MINOR == minor && NV_TENSORRT_PATCH >= patch)) ) ``` -------------------------------- ### KeyboardDevice::Create Method (C++) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/devKeyboard_8h_source.html Factory method to create and initialize a KeyboardDevice instance. It allows specifying the path to the input event device, with a default path provided. ```cpp static KeyboardDevice * Create(const char *path="/dev/input/by-path/platform-i8042-serio-0-event-kbd"); ``` -------------------------------- ### Check if Character is Valid for XML Name Start (C++) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/XML_8h_source.html Checks if a character is a valid starting character for an XML name. It allows alphabetic characters, underscores, and colons, with a heuristic for extended ASCII characters. ```cpp inline static bool IsNameStartChar( unsigned char ch ) { if ( ch >= 128 ) { // This is a heuristic guess in attempt to not implement Unicode-aware isalpha() return true; } if ( isalpha( ch ) ) { return true; } return ch == ':' || ch == '_'; } ``` -------------------------------- ### Install Python Development Packages (Bash) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/building-repo-2.md This command installs the necessary Python 3 development headers and the Python NumPy library. These packages are required for building the Python extension modules that provide bindings to the jetson-inference C++ code. ```bash sudo apt-get install libpython3-dev python3-numpy ``` -------------------------------- ### ActionNet Initialization Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/actionNet_8h_source.html This protected method initializes the ActionNet with specified parameters. It takes model paths, class descriptions, input/output details, batch size, precision, device type, and a fallback option. This method is called internally by the Create methods to set up the network. ```cpp bool init( const char* model_path, const char* class_path, const char* input, const char* output, uint32_t maxBatchSize, precisionType precision, deviceType device, bool allowGPUFallback ); ``` -------------------------------- ### WebRTCServer::init Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/classWebRTCServer.html Initializes the WebRTC server, preparing it to listen for incoming connections. ```APIDOC ## POST /webrtc/init ### Description Initializes the WebRTC server, making it ready to accept connections. This is typically called after creating the server instance. ### Method POST ### Endpoint /webrtc/init ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```bash curl -X POST http://localhost:8080/webrtc/init ``` ### Response #### Success Response (200) - **status** (boolean) - True if initialization was successful, false otherwise. #### Response Example ```json { "status": true } ``` ``` -------------------------------- ### C++ commandLine Get Positional Arguments Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/classcommandLine.html Retrieves a string argument by its position (index) in the command line. Returns a default value if the position is out of bounds. Also provides a function to get the total count of positional arguments. ```cpp const char* commandLine::GetPosition( unsigned int _position_, const char * _defaultValue_ = NULL ) const ``` ```cpp unsigned int commandLine::GetPositionArgs( ) const ``` -------------------------------- ### Create detectNet Instance (command line args) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/classdetectNet.html Creates a detectNet network instance by parsing command-line arguments. This is a convenient method for loading networks directly from execution parameters. ```cpp static detectNet* Create(int argc, char **argv); ``` -------------------------------- ### C++ Log Level Management Functions Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/logging_8h_source.html Provides inline functions to get and set the current logging level. It also includes functions to get the log file pointer and filename. These functions are essential for controlling the verbosity and output destination of log messages. ```cpp static inline void SetLevel( Level level ) { mLevel = level; } static inline FILE* GetFile() { return mFile; } static inline const char* GetFilename() { return mFilename.c_str(); } ``` -------------------------------- ### Create backgroundNet with command line arguments (C++) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/backgroundNet_8h_source.html Creates an instance of the backgroundNet class using command-line arguments. This method allows for flexible configuration of the network, including specifying the model path, input/output layers, batch size, precision, and device type. It returns a pointer to the initialized backgroundNet object. ```cpp static backgroundNet* Create( int argc, char** argv ); ``` -------------------------------- ### XMLNode: Get and Set User Data (C++) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/xml_8h_source.html Provides methods to get and set user-defined data associated with an XML node. This is useful for attaching custom information to nodes during XML processing. The data is stored as a void pointer. ```C++ void* GetUserData() const { return _userData; } ``` ```C++ void SetUserData(void* userData) { _userData = userData; } ``` -------------------------------- ### Get current application time in timespec format Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/timespec_8h_source.html Captures the current system time and stores it in a timespec structure. This function is often used to mark the beginning or end of a time interval for measurement purposes. It relies on underlying system calls to get the timestamp. ```cpp void apptime(timespec* a) { timespec t; timestamp(&t); timeDiff(__apptime_begin__, t, a); } ``` -------------------------------- ### Create videoSource from Command Line Arguments (C++) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/classvideoSource.html Creates a videoSource interface by parsing command-line arguments. It utilizes the videoOptions struct for configuration and expects a resource URI to be provided either as a positional argument or via the --input= option. Dependencies include standard C++ libraries for argument parsing. ```cpp static videoSource* videoSource::Create( const int _argc_, char **_argv_, int _positionArg_ = -1 ) ``` -------------------------------- ### Get and Set XML Element Text (C++) Source: https://github.com/dusty-nv/jetson-inference/blob/master/docs/html/XML_8h_source.html Provides methods to get and set the text content of an XML element. Overloaded versions of SetText allow setting text from various data types, including strings and numerical types. ```cpp const char* GetText() const; void SetText( const char* inText ); void SetText( int value ); void SetText( unsigned value ); void SetText(int64_t value); void SetText( bool value ); void SetText( double value ); void SetText( float value ); ``` -------------------------------- ### CMake: Copy and Install Python and Shell Scripts Source: https://github.com/dusty-nv/jetson-inference/blob/master/tools/CMakeLists.txt This CMake configuration copies Python and shell scripts to the runtime output directory and then installs them into the 'bin' directory. This ensures that executable tools are available in the expected locations. Scripts include 'test-models.py', 'tao-model-downloader.sh', and 'l4t_version.sh'. ```cmake file(COPY "test-models.py" DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) file(COPY "tao-model-downloader.sh" DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) file(COPY "l4t_version.sh" DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) install(PROGRAMS "test-models.py" DESTINATION bin) install(PROGRAMS "tao-model-downloader.sh" DESTINATION bin) install(PROGRAMS "l4t_version.sh" DESTINATION bin) ```