Skip to content

Commit 5c5e399

Browse files
committed
Repair jetson xavier nx picture pure white problem
1 parent 41523d0 commit 5c5e399

File tree

7 files changed

+895
-1
lines changed

7 files changed

+895
-1
lines changed

Jetson/Jetvariety/example/gstreamer-tools/utils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ class ArducamUtils(object):
7171
v4l2.V4L2_PIX_FMT_SRGGB10:{ "depth":10, "cvt_code": cv2.COLOR_BAYER_BG2BGR, "convert2rgb": 0},
7272
v4l2.V4L2_PIX_FMT_Y10:{ "depth":10, "cvt_code": -1, "convert2rgb": 0},
7373
}
74+
pixfmt_map_xavier_nx = {
75+
v4l2.V4L2_PIX_FMT_SBGGR10:{ "depth":16, "cvt_code": cv2.COLOR_BAYER_RG2BGR, "convert2rgb": 0},
76+
v4l2.V4L2_PIX_FMT_SGBRG10:{ "depth":16, "cvt_code": cv2.COLOR_BAYER_GR2BGR, "convert2rgb": 0},
77+
v4l2.V4L2_PIX_FMT_SGRBG10:{ "depth":16, "cvt_code": cv2.COLOR_BAYER_GB2BGR, "convert2rgb": 0},
78+
v4l2.V4L2_PIX_FMT_SRGGB10:{ "depth":16, "cvt_code": cv2.COLOR_BAYER_BG2BGR, "convert2rgb": 0},
79+
v4l2.V4L2_PIX_FMT_Y10:{ "depth":16, "cvt_code": -1, "convert2rgb": 0},
80+
}
7481

7582
pixfmt_map_raw8 = {
7683
v4l2.V4L2_PIX_FMT_SBGGR8:{ "depth":8, "cvt_code": cv2.COLOR_BAYER_RG2BGR, "convert2rgb": 0},
@@ -119,6 +126,21 @@ class ArducamUtils(object):
119126
DEVICE_ID = 0x0030
120127

121128
def __init__(self, device_num):
129+
import subprocess
130+
command = ['bash', '-c', 'source scripts/jetson_variables.sh && env']
131+
132+
proc = subprocess.Popen(command, stdout = subprocess.PIPE)
133+
environment_vars = {}
134+
for line in proc.stdout:
135+
(key, _, value) = line.partition(b"=")
136+
environment_vars[key] = value
137+
138+
proc.communicate()
139+
140+
# Jetson Model
141+
if b"Xavier NX" in environment_vars[b"JETSON_TYPE"].strip():
142+
ArducamUtils.pixfmt_map = ArducamUtils.pixfmt_map_xavier_nx
143+
122144
self.vd = open('/dev/video{}'.format(device_num), 'w')
123145
self.refresh()
124146

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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 <http://www.gnu.org/licenses/>.
17+
18+
19+
# Read CUDA version
20+
if [ -f /usr/local/cuda/version.txt ]; then
21+
JETSON_CUDA=$(cat /usr/local/cuda/version.txt | sed 's/\CUDA Version //g')
22+
else
23+
JETSON_CUDA="NOT_INSTALLED"
24+
fi
25+
# Jetson CUDA version
26+
export JETSON_CUDA
27+
28+
# Read from OpenCV if is installed CUDA
29+
opencv_read_cuda()
30+
{
31+
# Red if use CUDA or not
32+
local OPENCV_VERSION_VERBOSE=$(opencv_version --verbose | grep "Use Cuda" )
33+
if [ ! -z "$OPENCV_VERSION_VERBOSE" ]; then
34+
# Read status of CUDA
35+
local OPENCV_CUDA_FLAG=$(echo $OPENCV_VERSION_VERBOSE | cut -f2 -d ':' | cut -f2 -d ' ' )
36+
if [ "$OPENCV_CUDA_FLAG" == "NO" ]; then
37+
# Set NO if cuda is not installed
38+
echo "NO"
39+
else
40+
# Set YES if cuda is installed
41+
echo "YES"
42+
fi
43+
return
44+
fi
45+
# read NVIDIA CUDA version
46+
OPENCV_VERSION_VERBOSE=$(opencv_version --verbose | grep "NVIDIA CUDA" )
47+
if [ ! -z "$OPENCV_VERSION_VERBOSE" ]; then
48+
# get information
49+
local OPENCV_CUDA_FLAG=$(echo $OPENCV_VERSION_VERBOSE | cut -f2 -d ':')
50+
OPENCV_CUDA_FLAG=${OPENCV_CUDA_FLAG//[[:blank:]]/}
51+
# Set YES if cuda is installed
52+
echo "YES"
53+
return
54+
fi
55+
echo "NO"
56+
return
57+
}
58+
59+
if hash opencv_version 2>/dev/null; then
60+
JETSON_OPENCV="$(opencv_version)"
61+
# Read information about cuda status
62+
JETSON_OPENCV_CUDA=$(opencv_read_cuda)
63+
else
64+
JETSON_OPENCV="NOT_INSTALLED"
65+
JETSON_OPENCV_CUDA="NO"
66+
fi
67+
# Opencv variables
68+
export JETSON_OPENCV
69+
export JETSON_OPENCV_CUDA
70+
71+
# Extract cuDNN version
72+
JETSON_CUDNN=$(dpkg -l 2>/dev/null | grep -m1 "libcudnn")
73+
if [ ! -z "$JETSON_CUDNN" ] ; then
74+
JETSON_CUDNN=$(echo $JETSON_CUDNN | sed 's/.*libcudnn[0-9] \([^ ]*\).*/\1/' | cut -d '-' -f1 )
75+
else
76+
JETSON_CUDNN="NOT_INSTALLED"
77+
fi
78+
# Export NVIDIA CuDNN Library
79+
export JETSON_CUDNN
80+
81+
# Extract TensorRT version
82+
JETSON_TENSORRT=$(dpkg -l 2>/dev/null | grep -m1 " tensorrt ")
83+
if [ ! -z "$JETSON_TENSORRT" ] ; then
84+
JETSON_TENSORRT=$(echo $JETSON_TENSORRT | sed 's/.*tensorrt \([^ ]*\).*/\1/' | cut -d '-' -f1 )
85+
else
86+
JETSON_TENSORRT="NOT_INSTALLED"
87+
fi
88+
# Export NVIDIA CuDNN TensorRT
89+
export JETSON_TENSORRT
90+
91+
# Extract Visionworks version
92+
JETSON_VISIONWORKS=$(dpkg -l 2>/dev/null | grep -m1 "libvisionworks")
93+
if [ ! -z "$JETSON_VISIONWORKS" ] ; then
94+
JETSON_VISIONWORKS=$(echo $JETSON_VISIONWORKS | sed 's/.*libvisionworks \([^ ]*\).*/\1/' )
95+
else
96+
JETSON_VISIONWORKS="NOT_INSTALLED"
97+
fi
98+
# Export NVIDIA CuDNN VisionWorks
99+
export JETSON_VISIONWORKS
100+
101+
# Extract VPI
102+
JETSON_VPI=$(dpkg -l 2>/dev/null | grep -m1 "vpi")
103+
if [ ! -z "$JETSON_VPI" ] ; then
104+
JETSON_VPI=$(echo $JETSON_VPI | sed 's/.*vpi \([^ ]*\).*/\1/' )
105+
else
106+
JETSON_VPI="NOT_INSTALLED"
107+
fi
108+
# Export VPI
109+
export JETSON_VPI
110+
111+
# Vulkan
112+
JETSON_VULKAN_INFO=$(which vulkaninfo)
113+
if [ ! -z $JETSON_VULKAN_INFO ] ; then
114+
JETSON_VULKAN_INFO=$($JETSON_VULKAN_INFO | grep -m1 "Vulkan Instance Version")
115+
JETSON_VULKAN_INFO=$(echo $JETSON_VULKAN_INFO | sed 's/.*: \([^ ]*\).*/\1/' )
116+
else
117+
JETSON_VULKAN_INFO="NOT_INSTALLED"
118+
fi
119+
# Export VPI
120+
export JETSON_VULKAN_INFO
121+
#EOF
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
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 <http://www.gnu.org/licenses/>.
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+
"32.4.3") JETSON_JETPACK="4.4" ;;
34+
"32.4.2") JETSON_JETPACK="4.4 DP" ;;
35+
"32.3.1") JETSON_JETPACK="4.3" ;;
36+
"32.2.3") JETSON_JETPACK="4.2.3" ;;
37+
"32.2.1") JETSON_JETPACK="4.2.2" ;;
38+
"32.2.0" | "32.2") JETSON_JETPACK="4.2.1" ;;
39+
"32.1.0" | "32.1") JETSON_JETPACK="4.2" ;;
40+
"31.1.0" | "31.1") JETSON_JETPACK="4.1.1" ;;
41+
"31.0.2") JETSON_JETPACK="4.1" ;;
42+
"31.0.1") JETSON_JETPACK="4.0" ;;
43+
"28.2.1") JETSON_JETPACK="3.3 | 3.2.1" ;;
44+
"28.2.0" | "28.2") JETSON_JETPACK="3.2" ;;
45+
"28.1.0" | "28.1") JETSON_JETPACK="3.1" ;;
46+
"27.1.0" | "27.1") JETSON_JETPACK="3.0" ;;
47+
"24.2.1") JETSON_JETPACK="3.0 | 2.3.1" ;;
48+
"24.2.0" | "24.2") JETSON_JETPACK="2.3" ;;
49+
"24.1.0" | "24.1") JETSON_JETPACK="2.2.1 | 2.2" ;;
50+
"23.2.0" | "23.2") JETSON_JETPACK="2.1" ;;
51+
"23.1.0" | "23.1") JETSON_JETPACK="2.0" ;;
52+
"21.5.0" | "21.5") JETSON_JETPACK="2.3.1 | 2.3" ;;
53+
"21.4.0" | "21.4") JETSON_JETPACK="2.2 | 2.1 | 2.0 | 1.2 DP" ;;
54+
"21.3.0" | "21.3") JETSON_JETPACK="1.1 DP" ;;
55+
"21.2.0" | "21.2") JETSON_JETPACK="1.0 DP" ;;
56+
*) JETSON_JETPACK="UNKNOWN" ;;
57+
esac
58+
# return type jetpack
59+
echo $JETSON_JETPACK
60+
}
61+
62+
###########################
63+
#### BOARD DETECTION ####
64+
###########################
65+
# Detection NVIDIA Jetson
66+
# Jetson TK1 can be detected with chip id
67+
# Reference:
68+
# 1. https://docs.nvidia.com/jetson/l4t/index.html (Devices Supported by This Document)
69+
# 2. https://github.com/rbonghi/jetson_stats/issues/48
70+
# 3. https://github.com/rbonghi/jetson_stats/issues/57
71+
jetson_board()
72+
{
73+
local JETSON_CHIP_ID=$1
74+
local JETSON_BOARD=$2
75+
local JETSON_TYPE=""
76+
# Detection jetson board
77+
case $JETSON_BOARD in
78+
*2180*) JETSON_TYPE="TX1" ;;
79+
P3310*) JETSON_TYPE="TX2" ;;
80+
P3489-0080*) JETSON_TYPE="TX2 4GB" ;;
81+
P3489*) JETSON_TYPE="TX2i" ;;
82+
P2888-0006*) JETSON_TYPE="AGX Xavier [8GB]" ;;
83+
P2888-0001*|P2888-0004*) JETSON_TYPE="AGX Xavier [16GB]" ;;
84+
P2888*) JETSON_TYPE="AGX Xavier [32GB]" ;;
85+
P3448-0002*) JETSON_TYPE="Nano" ;;
86+
P3448*) JETSON_TYPE="Nano (Developer Kit Version)" ;;
87+
P3668-0001*) JETSON_TYPE="Xavier NX" ;;
88+
P3668*) JETSON_TYPE="Xavier NX (Developer Kit Version)" ;;
89+
*) JETSON_TYPE="" ;;
90+
esac
91+
# if JETSON_TYPE empty, check CHIP_ID for jetson TK1
92+
if [ -z "$JETSON_TYPE" ] ; then
93+
if [ "$JETSON_CHIP_ID" == "64" ] ; then
94+
JETSON_TYPE="TK1"
95+
fi
96+
fi
97+
# Return board name
98+
echo $JETSON_TYPE
99+
}
100+
###########################
101+
102+
# Extract jetson chip id
103+
JETSON_CHIP_ID=""
104+
if [ -f /sys/module/tegra_fuse/parameters/tegra_chip_id ]; then
105+
JETSON_CHIP_ID=$(cat /sys/module/tegra_fuse/parameters/tegra_chip_id)
106+
fi
107+
# Ectract type board
108+
JETSON_SOC=""
109+
if [ -f /proc/device-tree/compatible ]; then
110+
# Extract the last part of name
111+
JETSON_SOC=$(tr -d '\0' < /proc/device-tree/compatible | sed -e 's/.*,//')
112+
fi
113+
# Extract boardids if exists
114+
JETSON_BOARDIDS=""
115+
if [ -f /proc/device-tree/nvidia,boardids ]; then
116+
JETSON_BOARDIDS=$(tr -d '\0' < /proc/device-tree/nvidia,boardids)
117+
fi
118+
119+
# Code name
120+
JETSON_CODENAME=""
121+
JETSON_TYPE="UNKNOWN"
122+
JETSON_MODULE="UNKNOWN"
123+
JETSON_BOARD="UNKNOWN"
124+
list_hw_boards()
125+
{
126+
# Extract from DTS the name of the boards available
127+
# Reference:
128+
# 1. https://unix.stackexchange.com/questions/251013/bash-regex-capture-group
129+
# 2. https://unix.stackexchange.com/questions/144298/delete-the-last-character-of-a-string-using-string-manipulation-in-shell-script
130+
local s=$1
131+
local regex='p([0-9-]+)' # Equivalent to p([\d-]*-)
132+
while [[ $s =~ $regex ]]; do
133+
local board_name=$(echo "P${BASH_REMATCH[1]::-1}")
134+
#echo $board_name
135+
# Load jetson type
136+
JETSON_TYPE=$(jetson_board $JETSON_CHIP_ID $board_name)
137+
# If jetson type is not empty the module name is the same
138+
if [ ! -z "$JETSON_TYPE" ] ; then
139+
JETSON_MODULE=$board_name
140+
echo "JETSON_TYPE=\"$JETSON_TYPE\""
141+
echo "JETSON_MODULE=\"$JETSON_MODULE\""
142+
else
143+
JETSON_BOARD=$board_name
144+
echo "JETSON_BOARD=\"$JETSON_BOARD\""
145+
fi
146+
# Find next match
147+
s=${s#*"${BASH_REMATCH[1]}"}
148+
done
149+
}
150+
# Read DTS file
151+
# 1. https://devtalk.nvidia.com/default/topic/1071080/jetson-nano/best-way-to-check-which-tegra-board/
152+
# 2. https://devtalk.nvidia.com/default/topic/1014424/jetson-tx2/identifying-tx1-and-tx2-at-runtime/
153+
# 3. https://devtalk.nvidia.com/default/topic/996988/jetson-tk1/chip-uid/post/5100481/#5100481
154+
if [ -f /proc/device-tree/nvidia,dtsfilename ]; then
155+
# ..<something>/hardware/nvidia/platform/t210/porg/kernel-dts/tegra210-p3448-0000-p3449-0000-b00.dts
156+
# The last third is the codename of the board
157+
JETSON_CODENAME=$(tr -d '\0' < /proc/device-tree/nvidia,dtsfilename)
158+
JETSON_CODENAME=$(echo ${JETSON_CODENAME#*"/hardware/nvidia/platform/"} | tr '/' '\n' | head -2 | tail -1 )
159+
# The basename extract the board type
160+
JETSON_DTS="$(tr -d '\0' < /proc/device-tree/nvidia,dtsfilename | sed 's/.*\///')"
161+
# List of all boards
162+
eval $(list_hw_boards "$JETSON_DTS")
163+
fi
164+
165+
# Print description
166+
JETSON_MACHINE=""
167+
if [ ! -z "$JETSON_TYPE" ] ; then
168+
JETSON_MACHINE="NVIDIA Jetson $JETSON_TYPE"
169+
fi
170+
# Export variables
171+
export JETSON_CHIP_ID
172+
export JETSON_SOC
173+
export JETSON_BOARDIDS
174+
export JETSON_CODENAME
175+
export JETSON_MODULE
176+
export JETSON_BOARD
177+
export JETSON_TYPE
178+
export JETSON_MACHINE
179+
180+
# Write CUDA architecture
181+
# https://developer.nvidia.com/cuda-gpus
182+
# https://devtalk.nvidia.com/default/topic/988317/jetson-tx1/what-should-be-the-value-of-cuda_arch_bin/
183+
case $JETSON_TYPE in
184+
*Xavier*) JETSON_CUDA_ARCH_BIN="7.2" ;;
185+
TX2*) JETSON_CUDA_ARCH_BIN="6.2" ;;
186+
TX1* | Nano*) JETSON_CUDA_ARCH_BIN="5.3" ;;
187+
TK1) JETSON_CUDA_ARCH_BIN="3.2" ;;
188+
* ) JETSON_CUDA_ARCH_BIN="NONE" ;;
189+
esac
190+
# Export Jetson CUDA ARCHITECTURE
191+
export JETSON_CUDA_ARCH_BIN
192+
193+
# Serial number
194+
# https://devtalk.nvidia.com/default/topic/1055507/jetson-nano/nano-serial-number-/
195+
JETSON_SERIAL_NUMBER=""
196+
if [ -f /sys/firmware/devicetree/base/serial-number ]; then
197+
JETSON_SERIAL_NUMBER=$(tr -d '\0' </sys/firmware/devicetree/base/serial-number)
198+
fi
199+
# Export NVIDIA Serial Number
200+
export JETSON_SERIAL_NUMBER
201+
202+
# NVIDIA Jetson version
203+
# reference https://devtalk.nvidia.com/default/topic/860092/jetson-tk1/how-do-i-know-what-version-of-l4t-my-jetson-tk1-is-running-/
204+
# https://stackoverflow.com/questions/16817646/extract-version-number-from-a-string
205+
# https://askubuntu.com/questions/319307/reliably-check-if-a-package-is-installed-or-not
206+
# https://github.com/dusty-nv/jetson-inference/blob/7e81381a96c1ac5f57f1728afbfdec7f1bfeffc2/tools/install-pytorch.sh#L296
207+
if [ -f /etc/nv_tegra_release ]; then
208+
# L4T string
209+
# First line on /etc/nv_tegra_release
210+
# - "# R28 (release), REVISION: 2.1, GCID: 11272647, BOARD: t186ref, EABI: aarch64, DATE: Thu May 17 07:29:06 UTC 2018"
211+
JETSON_L4T_STRING=$(head -n 1 /etc/nv_tegra_release)
212+
# Load release and revision
213+
JETSON_L4T_RELEASE=$(echo $JETSON_L4T_STRING | cut -f 2 -d ' ' | grep -Po '(?<=R)[^;]+')
214+
JETSON_L4T_REVISION=$(echo $JETSON_L4T_STRING | cut -f 2 -d ',' | grep -Po '(?<=REVISION: )[^;]+')
215+
elif dpkg --get-selections | grep -q "^nvidia-l4t-core[[:space:]]*install$"; then
216+
# Read version
217+
JETSON_L4T_STRING=$(dpkg-query --showformat='${Version}' --show nvidia-l4t-core)
218+
# extract version
219+
JETSON_L4T_ARRAY=$(echo $JETSON_L4T_STRING | cut -f 1 -d '-')
220+
# Load release and revision
221+
JETSON_L4T_RELEASE=$(echo $JETSON_L4T_ARRAY | cut -f 1 -d '.')
222+
JETSON_L4T_REVISION=${JETSON_L4T_ARRAY#"$JETSON_L4T_RELEASE."}
223+
else
224+
# Load release and revision
225+
JETSON_L4T_RELEASE="N"
226+
JETSON_L4T_REVISION="N.N"
227+
fi
228+
# Write Jetson description
229+
JETSON_L4T="$JETSON_L4T_RELEASE.$JETSON_L4T_REVISION"
230+
# Export Release L4T
231+
export JETSON_L4T_RELEASE
232+
export JETSON_L4T_REVISION
233+
export JETSON_L4T
234+
235+
JETSON_JETPACK=$(jetson_jetpack $JETSON_L4T)
236+
# Export Jetson Jetpack installed
237+
export JETSON_JETPACK
238+
# EOF

0 commit comments

Comments
 (0)