diff --git a/.gitignore b/.gitignore index 27cf8ed81ca76f19263faddf83252fdaa3df5de1..5a98e865bb6e304126f77026efbfa5ff204fb9e2 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ lab-designs/viewer doc/ web-service/npm-debug.log web-service/server/npm-debug.log -gmon.out \ No newline at end of file +gmon.out +.devcontainer.json \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5f294f78bfc8adb9a9cc67eaf70d77ea738ee329..c8856cd9841b1ed5451abc93e1af558b4dfdf718 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -25,12 +25,7 @@ build: # - apt-get update -qq && apt-get install -y -qq g++ cmake git # - apt-get install -y -qq libopencv-dev libgoogle-glog-dev liburiparser-dev libreadline-dev libmsgpack-dev uuid-dev script: - - mkdir build - - cd build - - /snap/bin/cmake .. -GNinja -DCMAKE_CXX_FLAGS="-fdiagnostics-color" -DWITH_OPTFLOW=TRUE -DUSE_CPPCHECK=FALSE -DBUILD_CALIBRATION=TRUE -DWITH_CERES=TRUE -DCMAKE_BUILD_TYPE=Release -DCPACK_GENERATOR=DEB - - ninja - - ninja package - - ctest --output-on-failure + - ./docker/CI/pipeline-script.sh # - cd ../SDK/Python # - python3 -m unittest discover test diff --git a/CMakeLists.txt b/CMakeLists.txt index dfe9498e2ba491633d9147cb89fc1feaf38b9a26..5a8e01e5053cfade27c1975715ece359e32ed767 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,7 @@ MACRO( VERSION_STR_TO_INTS major minor patch version ) ENDMACRO( VERSION_STR_TO_INTS ) if (CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_CUDA_HOST_COMPILER gcc-7) + set(CMAKE_CUDA_HOST_COMPILER gcc) endif() find_package( OpenCV REQUIRED COMPONENTS core imgproc highgui cudaimgproc calib3d imgcodecs videoio aruco cudaarithm cudastereo cudaoptflow face tracking quality xfeatures2d) @@ -290,6 +290,7 @@ enable_language(CUDA) if (NOT WIN32) set(CMAKE_CUDA_FLAGS "-Xcompiler -fPIC") + set(CMAKE_CUDA_STANDARD 14) endif() set(CMAKE_CUDA_ARCHITECTURES 61) set(CMAKE_CUDA_FLAGS_DEBUG "--gpu-architecture=compute_61 -g -DDEBUG -D_DEBUG") diff --git a/README.md b/README.md index f439aa9098cc3a45a4cefaa695fc1ffcc3aecc48..a7db913063fef368346db54fbab04bd45dbfc925 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,37 @@ found in the `config` folder. The intention is that a web interface will eventually enable this configuration to take place online. ## Build + +### Container +FTL can be built and developed inside a docker container. To do this, run the +following sequence of commands and create a `.devcontainer.json` file as shown. + +Note: A ~3Gb image will be downloaded when running these commands, which +contains all build dependencies and tools. + +```bash +cd ./docker/devel +docker build -t ftl-devel --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) . +``` + +And the `.devcontainer.json` looks similar to this and goes in the repository +root: + +```json +{ + "image": "ftl-devel", + "runArgs": [ + "--runtime=nvidia", + "--device=/dev/snd", + "--device=/dev/bus/usb", + "-e", "DISPLAY=:1", + "-v", "/tmp/.X11-unix:/tmp/.X11-unix", + ], + "extensions": [] +} +``` + +### Local Use the following commands in the root repository directory to build: ```bash diff --git a/SDK/CPP/public/CMakeLists.txt b/SDK/CPP/public/CMakeLists.txt index 25770980fd34f26eb4205d1fecaf4df1da4f80b9..b3a689f08f997ba11b191348e1c86985466f8e6e 100644 --- a/SDK/CPP/public/CMakeLists.txt +++ b/SDK/CPP/public/CMakeLists.txt @@ -23,7 +23,7 @@ if(WIN32) set(OS_LIBS "") else() add_definitions(-DUNIX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC -march=native -mfpmath=sse -Wall -Werror=unused-result -Werror=return-type -pthread") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fPIC -march=native -mfpmath=sse -Wall -Werror=unused-result -Werror=return-type -pthread") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") set(OS_LIBS "dl") diff --git a/components/operators/src/analysis/tracking/detectandtrack.cpp b/components/operators/src/analysis/tracking/detectandtrack.cpp index 0b9e783e0419256b357a27970beb6fb6eb0e6604..7f4b86ba66a0b0c03e110f78f4de8871a50c36eb 100644 --- a/components/operators/src/analysis/tracking/detectandtrack.cpp +++ b/components/operators/src/analysis/tracking/detectandtrack.cpp @@ -194,7 +194,9 @@ bool DetectAndTrack::track(const Mat &im) { } else { it++; }*/ - if (it->fail_count >= max_fail_ || !it->tracker->update(im, it->object)) { + cv::Rect rect = it->object; + + if (it->fail_count >= max_fail_ || !it->tracker->update(im, rect)) { it = tracked_.erase(it); } else { ++it; diff --git a/components/operators/src/analysis/tracking/nvopticalflow.cpp b/components/operators/src/analysis/tracking/nvopticalflow.cpp index 8c0d38a6937e08b1efba9f61601029b4bd9cad15..e0d3ca44b781dc388a1c50167cedc12b80a26ea3 100644 --- a/components/operators/src/analysis/tracking/nvopticalflow.cpp +++ b/components/operators/src/analysis/tracking/nvopticalflow.cpp @@ -43,7 +43,7 @@ bool NVOpticalFlow::init() { return false; } nvof_ = cv::cuda::NvidiaOpticalFlow_1_0::create( - size_.width, size_.height, + size_, cv::cuda::NvidiaOpticalFlow_1_0::NV_OF_PERF_LEVEL_SLOW, true, false, false, 0); diff --git a/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp b/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp index 192697d2ac240ad434e3a21b9ad35ff816cfffe4..27e01dba9d4ce6dfaa09639036e221c1ca6e27ad 100644 --- a/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp +++ b/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp @@ -254,7 +254,7 @@ void StereoVideoSource::updateParameters(ftl::rgbd::Frame &frame) { return true; }); - if (lsrc_->isStereo()) { + if (lsrc_->isStereo() && calibration_.enabled) { Eigen::Matrix4d pose; // NOTE: pose update (new origin/rotation) cv::cv2eigen(calibration_.origin * rectification_->getPose(Channel::Left), pose); diff --git a/docker/CI/Dockerfile b/docker/CI/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..3b55e246f255e785c4b317ceb9d83786b3bc304d --- /dev/null +++ b/docker/CI/Dockerfile @@ -0,0 +1,19 @@ +FROM ftlab/base:1.0-dev + +RUN mkdir /opt/ftl +WORKDIR /opt/ftl +COPY ./applications ./applications +COPY ./cmake ./cmake +COPY ./components ./components +COPY ./lib ./lib +COPY ./ext ./ext +COPY ./SDK ./SDK + +CMD mkdir build &&\ + cd build &&\ + cmake .. -GNinja -DCMAKE_CXX_FLAGS="-fdiagnostics-color" -DWITH_OPTFLOW=TRUE -DUSE_CPPCHECK=FALSE -DBUILD_CALIBRATION=TRUE -DWITH_CERES=TRUE -DCMAKE_BUILD_TYPE=Release -DCPACK_GENERATOR=DEB &&\ + ninja &&\ + ninja package &&\ + ctest --output-on-failure + + diff --git a/docker/CI/container-script.sh b/docker/CI/container-script.sh new file mode 100755 index 0000000000000000000000000000000000000000..61d46ee1444ee744f6db10962d8ebd90f8af5ebf --- /dev/null +++ b/docker/CI/container-script.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +cd /opt/ftl +mkdir build +cd build +cmake .. -DCMAKE_CXX_FLAGS="-fdiagnostics-color" -DWITH_OPTFLOW=TRUE -DUSE_CPPCHECK=FALSE -DBUILD_CALIBRATION=TRUE -DWITH_CERES=TRUE -DCMAKE_BUILD_TYPE=Release -DCPACK_GENERATOR=DEB && +make -j4 && +ctest --output-on-failure diff --git a/docker/CI/pipeline-script.sh b/docker/CI/pipeline-script.sh new file mode 100755 index 0000000000000000000000000000000000000000..1fe21694edbbbf7cb4a392078344cd480f9d7d46 --- /dev/null +++ b/docker/CI/pipeline-script.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +docker run \ + --runtime=nvidia \ + --device=/dev/snd \ + --device=/dev/bus/usb \ + -e NVIDIA_DRIVER_CAPABILITIES=graphics,compute,utility,video \ + -v "${PWD}:/opt/ftl" \ + -u $(id -u ${USER}):$(id -g ${USER}) \ + ftlab/base:1.0-dev \ + /opt/ftl/docker/CI/container-script.sh + \ No newline at end of file diff --git a/docker/base/Dockerfile b/docker/base/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..9f4775d8bbdfa61a551339891123fd784a5ea59b --- /dev/null +++ b/docker/base/Dockerfile @@ -0,0 +1,168 @@ +FROM nvidia/cuda:11.4.0-devel-ubuntu20.04 AS devel + +ARG OPENCV_VERSION=4.5.3 +ARG DEBIAN_FRONTEND=noninteractive +ENV TZ=Europe/London +ENV NVIDIA_DRIVER_CAPABILITIES graphics,compute,utility,video + +RUN apt-get update &&\ + # Install build tools, build dependencies and python + apt-get install --no-install-recommends -y \ + build-essential \ + cmake \ + git \ + openssh-client \ + wget \ + unzip \ + yasm \ + cppcheck \ + pkg-config \ + libceres-dev \ + libreadline-dev \ + libopus-dev \ + libxtst-dev \ + libswscale-dev \ + libtbb2 \ + libtbb-dev \ + libjpeg-dev \ + libpng-dev \ + libglew-dev \ + zlib1g-dev \ + libasound-dev \ + libavcodec-dev \ + libavformat-dev \ + libavutil-dev \ + libpostproc-dev \ + libswscale-dev \ + libeigen3-dev \ + libgtk2.0-dev \ + libxxf86vm-dev \ + uuid-dev \ + libmsgpack-dev \ + liburiparser-dev \ + software-properties-common \ + && apt-key adv --keyserver keys.gnupg.net --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE || apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE && \ + add-apt-repository "deb https://librealsense.intel.com/Debian/apt-repo focal main" -u && \ + apt-get update && \ + apt-get install --no-install-recommends -y \ + librealsense2-dev \ + && rm -rf /var/lib/apt/lists/* + +COPY ./libnvcuvid.so ./libnvidia-encode.so /usr/lib/x86_64-linux-gnu/ + +RUN cd /opt/ &&\ + # Pylon + wget -O pylon.deb https://seafile.utu.fi/f/b4585f6c84f0462fac04/?dl=1 &&\ + apt-get install ./pylon.deb &&\ + rm ./pylon.deb &&\ + rm -rf /var/lib/apt/lists/* &&\ + # Portaudio + cd /opt/ &&\ + wget http://files.portaudio.com/archives/pa_stable_v190700_20210406.tgz &&\ + tar -xf ./pa_stable_v190700_20210406.tgz &&\ + rm ./pa_stable_v190700_20210406.tgz &&\ + cd ./portaudio &&\ + ./configure && make && make install &&\ + rm -rf ./portaudio &&\ + # Download and unzip OpenCV and opencv_contrib and delte zip files + cd /opt/ &&\ + wget https://github.com/opencv/opencv/archive/$OPENCV_VERSION.zip &&\ + unzip $OPENCV_VERSION.zip &&\ + rm $OPENCV_VERSION.zip &&\ + wget https://github.com/opencv/opencv_contrib/archive/$OPENCV_VERSION.zip &&\ + unzip ${OPENCV_VERSION}.zip &&\ + rm ${OPENCV_VERSION}.zip &&\ + # Create build folder and switch to it + mkdir /opt/opencv-${OPENCV_VERSION}/build && cd /opt/opencv-${OPENCV_VERSION}/build &&\ + # Cmake configure + cmake \ + -DOPENCV_EXTRA_MODULES_PATH=/opt/opencv_contrib-${OPENCV_VERSION}/modules \ + -DWITH_CUDA=ON \ + -DOPENCV_ENABLE_NONFREE=ON\ + -DCUDA_ARCH_BIN="6.1 7.5" \ + -DBUILD_TESTS=OFF\ + -DBUILD_PERF_TESTS=OFF\ + -DBUILD_EXAMPLES=OFF\ + -DBUILD_opencv_bioinspired=OFF\ + -DBUILD_opencv_cudaobjdetect=OFF\ + -DBUILD_opencv_dnn=OFF\ + -DBUILD_opencv_dnn_objdetect=OFF\ + -DBUILD_opencv_dnn_superres=OFF\ + -DBUILD_opencv_fuzzy=OFF\ + -DBUILD_opencv_hdf=OFF\ + -DBUILD_opencv_hfs=OFF\ + -DBUILD_opencv_dpm=OFF\ + -DBUILD_opencv_image_hash=OFF\ + -DBUILD_opencv_java_bindings_generator=OFF\ + -DBUILD_opencv_js=OFF\ + -DBUILD_opencv_saliency=OFF\ + -DBUILD_opencv_sfm=OFF\ + -DBUILD_opencv_stitching=OFF\ + -DBUILD_opencv_structured_light=OFF\ + -DBUILD_opencv_superres=OFF\ + -DBUILD_opencv_surface_matching=OFF\ + -DBUILD_opencv_viz=OFF\ + -DBUILD_opencv_xobjdetect=OFF\ + -DBUILD_opencv_gapi=OFF\ + -DBUILD_opencv_videostab=OFF\ + -DBUILD_opencv_rgbd=OFF\ + -DWITH_CUDNN=OFF\ + -DWITH_TIFF=OFF\ + -DWITH_WEBP=OFF\ + -DWITH_OPENEXR=OFF\ + -DWITH_OPENCL=OFF\ + -DWITH_PROTOBUF=OFF\ + -DCMAKE_BUILD_TYPE=RELEASE \ + # Install path will be /usr/local/lib (lib is implicit) + -DCMAKE_INSTALL_PREFIX=/usr/local \ + .. &&\ + # Make + make -j"$(nproc)" && \ + # Install to /usr/local/lib + make install && \ + ldconfig &&\ + # Remove OpenCV sources and build folder + rm -rf /opt/opencv-${OPENCV_VERSION} && rm -rf /opt/opencv_contrib-${OPENCV_VERSION} &&\ + ln -s /usr/local/include/opencv4/opencv2 /usr/local/include/opencv2 + +FROM nvidia/cuda:11.4.0-base-ubuntu20.04 AS runtime + +ARG OPENCV_VERSION=4.5.3 +ARG DEBIAN_FRONTEND=noninteractive +ENV TZ=Europe/London +ENV NVIDIA_DRIVER_CAPABILITIES graphics,compute,utility,video + +RUN apt-get update && apt-get upgrade -y &&\ + # Install build tools, build dependencies and python + apt-get install --no-install-recommends -y \ + libceres1 \ + libreadline8 \ + libopus0 \ + libxtst6 \ + libtbb2 \ + libjpeg8 \ + libpng16-16 \ + libtiff5 \ + libavformat58 \ + libpq5 \ + libxine2 \ + libglew2.1 \ + zlib1g \ + libasound2 \ + libavcodec58 \ + libavutil56 \ + libpostproc55 \ + libswscale5 \ + libgtk2.0-0 \ + libxxf86vm1 \ + uuid \ + libmsgpackc2 \ + liburiparser1 \ + software-properties-common \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=devel /usr/local/share /usr/local/share +COPY --from=devel /usr/local/lib /usr/local/lib +COPY --from=devel /opt/pylon /opt/pylon +COPY --from=devel /etc/udev/rules.d/69-basler-cameras.rules /etc/udev/rules.d/ +COPY --from=devel /etc/profile.d /etc/profile.d diff --git a/docker/base/README.md b/docker/base/README.md new file mode 100644 index 0000000000000000000000000000000000000000..a11c2fe6b7a168350c93255db5d78e11fd59a369 --- /dev/null +++ b/docker/base/README.md @@ -0,0 +1,13 @@ +# FTL Base Docker Image +This image contains all dependencies and build tools for FTL. + +* CUDA 11.4.0 +* OpenCV 4.5.3 +* Pylon 6.1.1 + +## Image Build +An example build command is given below, just bump the version number. + +``` +docker build -t ftlab/base:1.0-dev --target=devel . +``` \ No newline at end of file diff --git a/docker/base/libnvcuvid.so b/docker/base/libnvcuvid.so new file mode 100644 index 0000000000000000000000000000000000000000..f08a209545e076a835d11dcc24bd20d22088b1c5 Binary files /dev/null and b/docker/base/libnvcuvid.so differ diff --git a/docker/base/libnvidia-encode.so b/docker/base/libnvidia-encode.so new file mode 100644 index 0000000000000000000000000000000000000000..99934c7b22357afacb382aef554075081ee787f6 Binary files /dev/null and b/docker/base/libnvidia-encode.so differ diff --git a/docker/devel/Dockerfile b/docker/devel/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..3e8f447023805b1c0d0e71ed0230ccd2fad0eb62 --- /dev/null +++ b/docker/devel/Dockerfile @@ -0,0 +1,6 @@ +FROM ftlab/base:1.0-dev + +ARG USER_ID +ARG GROUP_ID +RUN addgroup --gid $GROUP_ID user && adduser --disabled-password --gecos '' --uid $USER_ID --gid $GROUP_ID user +USER user diff --git a/docker/devel/README.md b/docker/devel/README.md new file mode 100644 index 0000000000000000000000000000000000000000..a673e9fd5ed81a8b498e640b0488ce586679ab47 --- /dev/null +++ b/docker/devel/README.md @@ -0,0 +1,9 @@ +# FTL Developer Docker Image + +This is a small wrapper image that should be built locally by the developer. It adds correct user permissions to the image to ensure files are created correctly on the host if volumes are used. + +## Image Build + +``` +docker build -t ftl-devel --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) . +``` diff --git a/lib/libstereo/CMakeLists.txt b/lib/libstereo/CMakeLists.txt index a5f3255d2ca0f72a0df3e04c71b639de6984e946..4424ee09260eafdee0ac5dd1f01187be7c8626b8 100644 --- a/lib/libstereo/CMakeLists.txt +++ b/lib/libstereo/CMakeLists.txt @@ -16,17 +16,18 @@ find_package( Threads REQUIRED ) check_language(CUDA) enable_language(CUDA) -set(CMAKE_CXX_CPPCHECK "cppcheck") +# set(CMAKE_CXX_CPPCHECK "cppcheck") set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CUDA_STANDARD 14) set(CMAKE_USE_RELATIVE_PATHS ON) set(CMAKE_CXX_FLAGS_RELEASE) if (CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_CUDA_HOST_COMPILER gcc-7) - set(CMAKE_CUDA_FLAGS "--gpu-architecture=compute_61 -std=c++14 -Xcompiler -fPIC -Xcompiler ${OpenMP_CXX_FLAGS} --expt-relaxed-constexpr") + set(CMAKE_CUDA_HOST_COMPILER gcc) + set(CMAKE_CUDA_FLAGS "--gpu-architecture=compute_61 -Xcompiler -fPIC -Xcompiler ${OpenMP_CXX_FLAGS} --expt-relaxed-constexpr") set(CMAKE_CUDA_FLAGS_RELEASE "-O3") else() - set(CMAKE_CUDA_FLAGS "--gpu-architecture=compute_61 -std=c++14 --expt-relaxed-constexpr") + set(CMAKE_CUDA_FLAGS "--gpu-architecture=compute_61 --expt-relaxed-constexpr") set(CMAKE_CUDA_FLAGS_RELEASE "-O3") endif()