|
#!/bin/sh -eu |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_CUDAVER="11.8" |
|
_TRTVER="8.6.1.6" |
|
_CUDNNVER="8.9.1" |
|
|
|
|
|
usage() { echo "usage: $0 [-i <dir> | --installdir <dir>] [-y|--yes] [-f|--force] [-p|--prereq]"; exit 0;} |
|
die() { echo "$0: ERROR: $@" 1>&2; exit 1; } |
|
progress() { echo "========== $@ =========="; } |
|
|
|
check_exist() { |
|
msg="$1" |
|
shift |
|
for i; do if [ -e "$i" ]; then return; fi; done |
|
die "Could not find $msg: $@" |
|
} |
|
|
|
|
|
SAMPDIR="$(cd ${AR_SDK_SAMPLES_DIR:-`dirname "$0"`}; pwd)" |
|
if [ ! -e "$SAMPDIR/build_samples.sh" ] |
|
then |
|
die "cannot find samples directory" |
|
fi |
|
|
|
if [ -f /etc/os-release ] |
|
then |
|
. /etc/os-release |
|
OS="$ID$VERSION_ID" |
|
case "$OS" in |
|
centos7 | ubuntu18.04 | ubuntu20.04 | ubuntu22.04 | rocky8.7 | rocky8.8 | debian11 );; |
|
*) die "unsupported linux version: $OS";; |
|
esac |
|
else |
|
die "cannot determine os version" |
|
fi |
|
|
|
|
|
TEMP=$(getopt -o 'xfdci:ypb?' --long 'force,debug,cleanup,installdir:,yes,build,prereq,help' -- "$@") |
|
if [ $? -ne 0 ]; then usage; fi |
|
eval set -- "$TEMP" |
|
unset TEMP |
|
|
|
|
|
|
|
_YES="false" |
|
_FORCE="false" |
|
_BUILD_TYPE="Release" |
|
_INSTALLDIR="" |
|
_CLEANUP="false" |
|
_BUILD="true" |
|
_PREREQ="true" |
|
_PREGEN="true" |
|
while true; do |
|
case "$1" in |
|
'-x') set -x;; |
|
'-f' | '--force') _FORCE="true";; |
|
'-d' | '--debug') _BUILD_TYPE="Debug";; |
|
'-c' | '--cleanup') _CLEANUP="true";; |
|
'-i' | '--installdir') _INSTALLDIR="$2";shift;; |
|
'-y' | '--yes') _YES="true";; |
|
'-p' | '--prereq') _BUILD="false"; _PREGEN="true";; |
|
'-b' | '--build') _PREREQ="false";; |
|
'--') shift;break;; |
|
*) usage;; |
|
esac |
|
shift |
|
done |
|
|
|
|
|
if ! $_YES |
|
then |
|
echo "" |
|
echo "====================================================================" |
|
echo "This script will:" |
|
if [ "$OS" = "centos7" ] |
|
then |
|
echo "- INSTALL pre-requisite packages using yum" |
|
echo "- BUILD pre-requisite packages (opencv + ffmpeg)" |
|
else |
|
echo "- INSTALL pre-requisite packages using apt-get" |
|
fi |
|
echo "- build the sample apps to a location of your choice" |
|
echo "" |
|
echo "This may install many pre-requisite packages" |
|
if [ "$OS" = "centos7" ] |
|
then |
|
echo "and the the build may take some time" |
|
fi |
|
|
|
echo "" |
|
read -p "Ok to continue? (yes/no) " ans |
|
case "$ans" in |
|
[yY] | [Yy][Ee][Ss]);; |
|
*) echo "aborted."; exit 1;; |
|
esac |
|
fi |
|
|
|
if [ -z "$_INSTALLDIR" ] && ! $_YES; then |
|
echo "Please provide an absolute path for installation directory below, or use the default. " |
|
read -p "Install to [~/mysamples]: " _INSTALLDIR |
|
fi |
|
|
|
_INSTALLDIR="${_INSTALLDIR:-$HOME/mysamples}" |
|
mkdir -p "$_INSTALLDIR/source" |
|
|
|
progress "copy samples to $_INSTALLDIR" |
|
|
|
echo "cp -r $SAMPDIR/* $_INSTALLDIR/source/" |
|
cp -r $SAMPDIR/* "$_INSTALLDIR/source/" |
|
|
|
|
|
if [ -d "$_INSTALLDIR/pregen" ] && [ ! -d "$_INSTALLDIR/extras" ] |
|
then |
|
progress "copy preinstalled packages to $_INSTALLDIR" |
|
cp -r "$_INSTALLDIR/pregen/" "$_INSTALLDIR/extras/" |
|
fi |
|
|
|
|
|
if [ -x /usr/bin/sudo ] |
|
then |
|
SUDO="sudo" |
|
else |
|
SUDO="" |
|
fi |
|
|
|
if $_PREREQ |
|
then |
|
|
|
progress "check prerequisities" |
|
|
|
case "$OS" in |
|
|
|
centos7) |
|
|
|
|
|
PRE_REQ_LIST=" |
|
cmake3 |
|
gcc |
|
gcc-c++ |
|
git |
|
gtk2-devel |
|
jasper-devel |
|
libdc1394-devel |
|
libjpeg-turbo-devel |
|
libpng-devel |
|
libtiff-devel |
|
libv4l-devel |
|
libwebp-devel |
|
v4l-utils |
|
yasm |
|
|
|
autoconf |
|
automake |
|
libtool |
|
|
|
make |
|
wget |
|
|
|
mesa-libGLES-devel |
|
glfw-devel |
|
" |
|
|
|
if $_FORCE || ! rpm -q epel-release $PRE_REQ_LIST |
|
then |
|
echo "installing required packages:" |
|
set -x |
|
$SUDO yum -y install epel-release |
|
$SUDO yum -y install $PRE_REQ_LIST |
|
set +x |
|
else |
|
echo "Required packages are already installed" |
|
fi |
|
|
|
CMAKE=cmake3 |
|
|
|
;; |
|
|
|
rocky8.7 | rocky8.8 ) |
|
PRE_REQ_LIST=" |
|
git |
|
cmake |
|
gcc |
|
gcc-c++ |
|
make |
|
python2 |
|
python3 |
|
python3-numpy |
|
platform-python-devel |
|
gtk2-devel |
|
findutils |
|
diffutils |
|
libdc1394 |
|
libjpeg-turbo |
|
libjpeg-turbo-devel |
|
|
|
libv4l-devel |
|
|
|
autoconf |
|
automake |
|
libtool |
|
mesa-libGL-devel |
|
glfw-devel |
|
" |
|
|
|
if $_FORCE || ! rpm -q epel-release $PRE_REQ_LIST |
|
then |
|
echo "installing required packages:" |
|
set -xe |
|
|
|
$SUDO yum -y install epel-release |
|
$SUDO dnf config-manager --set-enabled powertools |
|
$SUDO dnf -y install $PRE_REQ_LIST |
|
set +x |
|
else |
|
echo "Required packages are already installed" |
|
fi |
|
|
|
CMAKE=cmake |
|
|
|
;; |
|
|
|
ubuntu18.04 | ubuntu20.04 | ubuntu22.04 | debian10 | debian11 ) |
|
|
|
PRE_REQ_LIST=" |
|
cmake |
|
g++ |
|
make |
|
ffmpeg |
|
libopencv-dev |
|
libgles2-mesa-dev |
|
libglfw3-dev |
|
" |
|
|
|
if $_FORCE || ! dpkg --verify $PRE_REQ_LIST >/dev/null |
|
then |
|
echo "installing required packages:" |
|
set -x |
|
$SUDO apt-get update |
|
if [ -z "$SUDO" ] |
|
then |
|
export DEBIAN_FRONTEND=noninteractive |
|
apt-get install -y $PRE_REQ_LIST |
|
else |
|
$SUDO DEBIAN_FRONTEND=noninteractive apt-get install -y $PRE_REQ_LIST |
|
fi |
|
set +x |
|
else |
|
echo "Required packages are already installed" |
|
fi |
|
|
|
CMAKE=cmake |
|
|
|
;; |
|
|
|
*) die "unexpected OS":; |
|
|
|
esac |
|
|
|
|
|
cd "$_INSTALLDIR" |
|
|
|
|
|
if [ "$OS" = "centos7" ] || [ "$OS" = "rocky8.7" ] || [ "$OS" = "rocky8.8" ] |
|
then |
|
progress "build any additional prerequisites" |
|
|
|
set -e |
|
|
|
if [ -e $_INSTALLDIR/extras/bin/nasm ] && ! $_FORCE |
|
then |
|
|
|
echo "nasm: already exists" |
|
|
|
else |
|
|
|
mkdir -p $_INSTALLDIR/build/nasm |
|
cd $_INSTALLDIR/build/nasm |
|
|
|
git clone https://github.com/netwide-assembler/nasm |
|
cd nasm |
|
git -c advice.detachedHead=false checkout tags/nasm-2.15.05 |
|
|
|
sh autogen.sh |
|
sh configure --prefix="$_INSTALLDIR/extras" |
|
touch nasm.1 ndisasm.1 |
|
|
|
make -j$(nproc) |
|
make install |
|
|
|
cd $_INSTALLDIR/build |
|
$_CLEANUP && rm -rf $_INSTALLDIR/build/nasm |
|
fi |
|
|
|
export PATH="$PATH:$_INSTALLDIR/extras/bin" |
|
|
|
|
|
|
|
if [ -e $_INSTALLDIR/extras/lib/libx264.a ] && ! $_FORCE |
|
then |
|
echo "libx264: already exists" |
|
else |
|
mkdir -p $_INSTALLDIR/build/x264 |
|
cd $_INSTALLDIR/build/x264 |
|
|
|
git clone https://git.videolan.org/git/x264.git |
|
cd x264 |
|
|
|
|
|
./configure \ |
|
--enable-static \ |
|
--enable-strip \ |
|
--enable-pic \ |
|
--disable-cli \ |
|
--disable-opencl \ |
|
\ |
|
--disable-avs \ |
|
--disable-swscale \ |
|
--disable-lavf \ |
|
--disable-ffms \ |
|
--disable-gpac \ |
|
--disable-lsmash \ |
|
\ |
|
--prefix="$_INSTALLDIR/extras" |
|
|
|
make -j$(nproc) |
|
make install |
|
|
|
cd $_INSTALLDIR/build |
|
$_CLEANUP && rm -rf $_INSTALLDIR/build/x264 |
|
fi |
|
|
|
|
|
if [ -e $_INSTALLDIR/extras/bin/ffmpeg ] && ! $_FORCE |
|
then |
|
echo "ffmpeg: already exists" |
|
else |
|
mkdir -p $_INSTALLDIR/build/ffmpeg |
|
cd $_INSTALLDIR/build/ffmpeg |
|
|
|
export PKG_CONFIG_PATH="$_INSTALLDIR/extras/lib/pkgconfig:${PKG_CONFIG_PATH:-}" |
|
|
|
echo "git clone FFmpeg" |
|
git -c advice.detachedHead=false clone -b n4.3.2 --depth=1 https://github.com/FFmpeg/FFmpeg |
|
|
|
cd FFmpeg |
|
git -c advice.detachedHead=false checkout tags/n4.3.2 |
|
|
|
./configure \ |
|
--enable-pic \ |
|
--enable-shared \ |
|
--enable-ffmpeg \ |
|
--enable-ffplay \ |
|
--enable-ffprobe \ |
|
--enable-gpl \ |
|
--enable-libx264 \ |
|
--prefix="$_INSTALLDIR/extras" \ |
|
--disable-doc |
|
|
|
make -j$(nproc) |
|
make install |
|
|
|
cd $_INSTALLDIR/build |
|
$_CLEANUP && rm -rf $_INSTALLDIR/build/ffmpeg |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
export LD_LIBRARY_PATH="$_INSTALLDIR/extras/lib:/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}" |
|
|
|
if [ -e $_INSTALLDIR/extras/lib64/libopencv_core.so ] && ! $_FORCE |
|
then |
|
echo "opencv: already exists" |
|
else |
|
|
|
export PKG_CONFIG_PATH="$_INSTALLDIR/extras/lib/pkgconfig:$_INSTALLDIR/extras/lib64/pkgconfig:/usr/lib64/pkgconfig:/usr/share/pkgconfig:${PKG_CONFIG_PATH:-/usr/share/pkgconfig}" |
|
export PKG_CONFIG_LIBDIR="$_INSTALLDIR/extras/lib:$_INSTALLDIR/extras/lib64:/usr/lib64:${PKG_CONFIG_LIBDIR:-/usr/lib64}" |
|
|
|
cd "$_INSTALLDIR/build" |
|
|
|
echo "git clone opencv" |
|
git -c advice.detachedHead=false clone https://github.com/opencv/opencv.git |
|
|
|
cd opencv |
|
git -c advice.detachedHead=false checkout tags/3.4.6 |
|
|
|
mkdir build |
|
cd build |
|
|
|
$CMAKE \ |
|
-D CMAKE_INSTALL_PREFIX="$_INSTALLDIR/extras" \ |
|
-D CMAKE_BUILD_TYPE=RELEASE \ |
|
-D BUILD_opencv_stitching=OFF \ |
|
-D WITH_1394=OFF \ |
|
-D WITH_FFMPEG=ON \ |
|
\ |
|
-D WITH_GSTREAMER=OFF \ |
|
-D WITH_V4L=ON \ |
|
-D WITH_LIB4VL=ON \ |
|
-D OPENCV_SKIP_PYTHON_LOADER=ON \ |
|
-D OPENCV_GENERATE_PKGCONFIG=ON \ |
|
-D ENABLE_CXX11=ON \ |
|
\ |
|
-D BUILD_opencv_apps=OFF \ |
|
-D BUILD_DOCS=OFF \ |
|
-D BUILD_PACKAGE=OFF \ |
|
-D BUILD_PERF_TESTS=OFF \ |
|
-D BUILD_TESTS=OFF \ |
|
\ |
|
-DBUILD_LIST=core,videoio,highgui,imgproc,calib3d \ |
|
.. |
|
|
|
make -j$(nproc) |
|
make install |
|
|
|
cd $_INSTALLDIR/build |
|
$_CLEANUP && rm -rf $_INSTALLDIR/build/opencv |
|
fi |
|
|
|
if $_PREGEN |
|
then |
|
cp -R $_INSTALLDIR/extras/ $_INSTALLDIR/pregen/ |
|
fi |
|
|
|
fi |
|
|
|
progress "prerequisites for samples are complete" |
|
fi |
|
|
|
if $_BUILD |
|
then |
|
|
|
progress "verify cuda / cudnn / tensorrt" |
|
|
|
if [ -d /usr/local/ARSDK/external/cuda ] && [ -d /usr/local/ARSDK/external/tensorrt ] |
|
then |
|
echo "found ARSDK tensorrt/cuda/cudnn" |
|
|
|
export LD_LIBRARY_PATH="/usr/local/ARSDK/external/cuda/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}" |
|
export PATH="/usr/local/ARSDK/external/cuda/bin:$PATH" |
|
|
|
|
|
export LD_LIBRARY_PATH="/usr/local/ARSDK/external/tensorrt/lib:$LD_LIBRARY_PATH" |
|
export PATH="/usr/local/ARSDK/external/tensorrt/bin:$PATH" |
|
else |
|
|
|
|
|
_TRT_VER_SHORT=$(echo $_TRTVER | sed 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\..*/\1.\2\.\3/') |
|
|
|
check_exist "CUDA" /usr/local/cuda-$_CUDAVER |
|
check_exist "TensorRT" /usr/local/TensorRT-$_TRTVER/lib/libnvinfer.so.$_TRT_VER_SHORT \ |
|
/usr/lib64/libnvinfer.so.$_TRT_VER_SHORT \ |
|
/usr/lib/x86_64-linux-gnu/libnvinfer.so.$_TRT_VER_SHORT |
|
check_exist "cuDNN" /usr/local/cuda-$_CUDAVER/lib64/libcudnn.so.$_CUDNNVER \ |
|
/usr/lib64/libcudnn.so.$_CUDNNVER \ |
|
/usr/lib/x86_64-linux-gnu/libcudnn.so.$_CUDNNVER |
|
|
|
export LD_LIBRARY_PATH="/usr/local/cuda-${_CUDAVER}/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}" |
|
export PATH="/usr/local/cuda-${_CUDAVER}/bin:$PATH" |
|
|
|
export LD_LIBRARY_PATH="/usr/local/TensorRT-${_TRTVER}/lib:${LD_LIBRARY_PATH}" |
|
export PATH="/usr/local/TensorRT-${_TRTVER}/bin:$PATH" |
|
fi |
|
|
|
progress "build sample apps" |
|
|
|
|
|
set -e |
|
|
|
|
|
cd $_INSTALLDIR |
|
|
|
${CMAKE:-cmake} \ |
|
-DCMAKE_BUILD_TYPE=$_BUILD_TYPE \ |
|
$_INSTALLDIR/source |
|
|
|
make -k |
|
|
|
|
|
|
|
cp $SAMPDIR/samples/*/run*.sh $_INSTALLDIR |
|
cp $SAMPDIR/samples/BodyTrack/setup_env.sh $_INSTALLDIR |
|
|
|
|
|
echo "" |
|
echo "the sample apps have been created" |
|
echo "If you used sudo permissions to execute this build_samples.sh script" |
|
echo "please use sudo permissions when trying out the samples below as well" |
|
echo "You can try the samples using:" |
|
echo " cd $_INSTALLDIR" |
|
/bin/ls -1 run*.sh | awk '{print " ./"$0}' |
|
echo "or follow the instructions in the documentation found in:" |
|
echo " $SAMPDIR/samples/doc" |
|
echo "" |
|
echo "you can modify the sources in $_INSTALLDIR/source and rebuild:" |
|
echo " cd $_INSTALLDIR" |
|
echo " $CMAKE $_INSTALLDIR/source" |
|
echo " make" |
|
fi |
|
|