commit 614ab9dba0f44dafe2aef9fce4907398c0370df7 Author: James Deng Date: Fri Mar 1 19:26:21 2024 +0800 Update for v1.0alpha1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fde9bce --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.vs +.vscode + +out +build* +CMakeSettings.json diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..ae3daf4 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,319 @@ +# This file is a template, and might need editing before it works on your project. +# This is a sample GitLab CI/CD configuration file that should run without any modifications. +# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts, +# it uses echo commands to simulate the pipeline execution. +# +# A pipeline is composed of independent jobs that run scripts, grouped into stages. +# Stages run in sequential order, but jobs within stages run in parallel. +# +# For more information, see: https://docs.gitlab.com/ee/ci/yaml/index.html#stages +# +# You can copy and paste this template into a new `.gitlab-ci.yml` file. +# You should not add this template to an existing `.gitlab-ci.yml` file by using the `include:` keyword. +# +# To contribute improvements to CI/CD templates, please follow the Development guide at: +# https://docs.gitlab.com/ee/development/cicd/templates.html +# This specific template is located at: +# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml + +stages: # List of stages for jobs, and their order of execution + - build + - test + - package + - upload + - deploy + +image: harbor.bianbu.xyz/spacemit-ai/bianbu-ai-support:v1.1.1 + +.only-defaults: &only-defaults + only: + - tags + - main + - cicd + - merge_requests + - schedules + +.rule-upload: &rule-upload + rules: + - if: '$CI_COMMIT_TAG =~ /^bianbu-23.10\/.*$/' + when: on_success + + +variables: + SDK: "/opt" + DATA: "$SDK/bianbu-ai-support/data" + CROSS_TOOL: "$SDK/spacemit-gcc/bin/riscv64-unknown-linux-gnu-" + SYSROOT: "$SDK/spacemit-gcc/sysroot" + QEMU_CMD: "$SDK/qemu/bin/qemu-riscv64 -L $SYSROOT" + ORT_HOME_X86: "/home/workspace/onnxruntime-linux-x64-1.15.1" + CI_NEXUS_URL: "https://nexus.bianbu.xyz/service/rest/repository/browse/bianbu-ai/onnxruntime/" + CI_INSTALL_OPTION: "--with-demo --with-ort" + KUBERNETES_MEMORY_LIMIT: "6Gi" + KUBERNETES_MEMORY_REQUEST: "6Gi" + +build-job-x86_64: # This job runs in the build stage, which runs first. + stage: build + variables: + BUILD_DIR: "build.x86_64" + ORT_HOME: "${ORT_HOME_X86}" + INSTALL_PREFIX: "bianbu-ai-support.x86_64" + before_script: + - echo "Before scripts ..." + script: + - echo "Compiling the code ..." + - | + mkdir ${BUILD_DIR} + pushd ${BUILD_DIR} + cmake .. -DORT_HOME=${ORT_HOME} -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DDEMO=ON + make install -j`nproc` VERBOSE=1 + popd + # copy demo and data + - if [[ "${CI_INSTALL_OPTION}" =~ "--with-demo" ]]; then cp -rdf demo ${BUILD_DIR}/${INSTALL_PREFIX} && cp -rdf data ${BUILD_DIR}/${INSTALL_PREFIX}/demo; fi + # copy onnxruntime + - if [[ "${CI_INSTALL_OPTION}" =~ "--with-ort" ]]; then mkdir -p ${BUILD_DIR}/${INSTALL_PREFIX}/lib/3rdparty/onnxruntime && cp -rdf ${ORT_HOME}/* ${BUILD_DIR}/${INSTALL_PREFIX}/lib/3rdparty/onnxruntime; fi + - | + pushd demo + mkdir ${BUILD_DIR} + pushd ${BUILD_DIR} + cmake .. -DBIANBUAI_HOME=$(pwd)/../../${BUILD_DIR}/${INSTALL_PREFIX} -DORT_HOME=${ORT_HOME} + make -j`nproc` VERBOSE=1 + popd + - echo "Compile complete." + artifacts: + paths: + - ${BUILD_DIR} + - demo/${BUILD_DIR} + <<: *only-defaults + +build-job-riscv64: # This job runs in the build stage, which runs second. + stage: build + variables: + BUILD_DIR: "build.riscv64" + ORT_HOME: "${CI_PROJECT_DIR}/spacemit-ort" + # TODO: fix opencv.v4.6.0 output precision error + OPENCV_SHARED_DIR: "$SDK/bianbu-ai-support/3rdparty/opencv.v4.7.0.shared" # v4.6.0.shared.qt5 + OPENCV_STATIC_DIR: "$SDK/bianbu-ai-support/3rdparty/opencv.v4.7.0.static" + INSTALL_PREFIX: "bianbu-ai-support.riscv64" + before_script: + - echo "Before scripts ..." + #- set -x + #- echo "CI_BUILDS_DIR ${CI_BUILDS_DIR}" + #- echo "CI_PROJECT_DIR ${CI_PROJECT_DIR}" + - echo "Downloading latest spacemit-ort ..." + - wget $(curl -X GET ${CI_NEXUS_URL} | grep -oP 'https:[^>]*.rv64.v[\d\.]*tar.gz' | tail -n 1) -O spacemit-ort.latest.tar.gz --no-check-certificate + - | + mkdir spacemit-ort + tar xzf spacemit-ort.latest.tar.gz -C spacemit-ort --strip-components 1 + tree -L 3 . + script: + - echo "Compiling the code ..." + # Note: To use opencv static libraries, one'd better set OpenCV_DIR variable instead of OPENCV_INC and OPENCV_LIB variables. + - | + mkdir ${BUILD_DIR} + pushd ${BUILD_DIR} + cmake .. -DORT_HOME=${ORT_HOME} -DOpenCV_DIR=${OPENCV_STATIC_DIR}/lib/cmake/opencv4 -DCMAKE_C_COMPILER=${CROSS_TOOL}gcc -DCMAKE_CXX_COMPILER=${CROSS_TOOL}g++ -DCMAKE_SYSROOT=${SYSROOT} -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DDEMO=ON + make install -j`nproc` VERBOSE=1 + popd + # copy demo and data + - if [[ "${CI_INSTALL_OPTION}" =~ "--with-demo" ]]; then cp -rdf demo ${BUILD_DIR}/${INSTALL_PREFIX} && cp -rdf data ${BUILD_DIR}/${INSTALL_PREFIX}/demo; fi + # copy onnxruntime + - if [[ "${CI_INSTALL_OPTION}" =~ "--with-ort" ]]; then mkdir -p ${BUILD_DIR}/${INSTALL_PREFIX}/lib/3rdparty/onnxruntime && cp -rdf ${ORT_HOME}/* ${BUILD_DIR}/${INSTALL_PREFIX}/lib/3rdparty/onnxruntime; fi + # - mkdir ${BUILD_DIR} && pushd ${BUILD_DIR} && cmake .. -DORT_HOME=${ORT_HOME} -DOPENCV_INC=${OPENCV_SHARED_DIR}/include/opencv4 -DOPENCV_LIB=${OPENCV_SHARED_DIR}/lib -DCMAKE_C_COMPILER=${CROSS_TOOL}gcc -DCMAKE_CXX_COMPILER=${CROSS_TOOL}g++ -DCMAKE_SYSROOT=${SYSROOT} -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DDEMO=ON -DUSE_OPENCV_SHARED_LIBS=ON && make install -j`nproc` VERBOSE=1 && popd + - | + pushd demo + mkdir ${BUILD_DIR} + pushd ${BUILD_DIR} + cmake .. -DBIANBUAI_HOME=$(pwd)/../../${BUILD_DIR}/${INSTALL_PREFIX} -DORT_HOME=${ORT_HOME} -DOPENCV_INC=${OPENCV_SHARED_DIR}/include/opencv4 -DOPENCV_LIB=${OPENCV_SHARED_DIR}/lib -DCMAKE_C_COMPILER=${CROSS_TOOL}gcc -DCMAKE_CXX_COMPILER=${CROSS_TOOL}g++ -DCMAKE_SYSROOT=${SYSROOT} + make -j`nproc` VERBOSE=1 + popd + # - echo "Compile complete." + artifacts: + paths: + - ${BUILD_DIR} + - spacemit-ort + - demo/${BUILD_DIR} + <<: *only-defaults + +build-job-riscv64-deb: + stage: build + image: harbor.bianbu.xyz/spacemit-ai/bianbu-ai-support:debian + dependencies: [] + script: + - echo "Building debian package for tag $CI_COMMIT_TAG" + - | + set -x + mount -o bind $CI_PROJECT_DIR/.. /mnt/ + schroot -r -c persistent-session --directory /mnt/ai/support + apt build-dep -y $(pwd) + dpkg-buildpackage -us -b -uc --no-pre-clean --no-post-clean + exit + mkdir bianbu-dev + mv ../bianbu-ai-support-* bianbu-dev + mv ../bianbu-ai-support_* bianbu-dev + artifacts: + paths: + - bianbu-dev + only: + - deb + + +x86_64-test-job: # This job runs in the test stage. + stage: test # It only starts when the job in the build stage completes successfully. + dependencies: + - build-job-x86_64 + script: + - echo "Running unit tests ... (This will take several seconds.)" + - export LD_LIBRARY_PATH=${ORT_HOME_X86}/lib:$LD_LIBRARY_PATH + - demo/build.x86_64/classification_demo $DATA/models/squeezenet1.1-7.onnx $DATA/labels/synset.txt $DATA/imgs/dog.jpg + - demo/build.x86_64/detection_demo $DATA/models/nanodet-plus-m_320.onnx $DATA/labels/coco.txt $DATA/imgs/person0.jpg result0.jpg + - $([[ "3aeb3a152ce55a94c0c7bac303534b8d" == "$(md5sum result0.jpg | awk '{print $1}')" ]]) + - echo "Running x86_64 tests done!" + <<: *only-defaults + +riscv64-test-job: # This job runs in the test stage. + stage: test # It only starts when the job in the build stage completes successfully. + dependencies: + - build-job-riscv64 + script: + - echo "Running unit tests ... (This will take several seconds.)" + - ${QEMU_CMD} demo/build.riscv64/classification_demo $DATA/models/squeezenet1.1-7.onnx $DATA/labels/synset.txt $DATA/imgs/dog.jpg + - ${QEMU_CMD} demo/build.riscv64/detection_demo $DATA/models/nanodet-plus-m_320.onnx $DATA/labels/coco.txt $DATA/imgs/person0.jpg result0.jpg + - $([[ "3aeb3a152ce55a94c0c7bac303534b8d" == "$(md5sum result0.jpg | awk '{print $1}')" ]]) + - echo "Running riscv64 tests done!" + <<: *only-defaults + +package-daily-dpkg: + stage: package + variables: + CI_PKG_OPTION: "--skip-py" # "--skip-ort --skip-py" + CI_PKG_VERSION: "1.0.7" + dependencies: + - build-job-x86_64 + - build-job-riscv64 + script: + #- echo $(date +"%Y%m%d_%H%M%S") + - mkdir -p output + # make deb ball + - | + bash ci/pack.sh build.x86_64/bianbu-ai-support.x86_64 ${CI_PKG_OPTION} + mv bianbu-ai-support-*.deb output/bianbu-ai-support_${CI_PKG_VERSION}_amd64.deb + - | + bash ci/pack.sh build.riscv64/bianbu-ai-support.riscv64 ${CI_PKG_OPTION} + mv bianbu-ai-support-*.deb output/bianbu-ai-support_${CI_PKG_VERSION}_riscv64.deb + #- rm -rf build.x86_64 build.riscv64 demo + artifacts: + paths: + - output/bianbu-ai-support_*.deb + <<: *only-defaults + +package-daily-prebuilt: + stage: package + dependencies: + - build-job-x86_64 + - build-job-riscv64 + script: + - mkdir -p output + # make tar ball + - | + pushd build.x86_64 + tar czf ../output/bianbu-ai-support.x86_64.$(date +"%Y%m%d_%H%M%S").tar.gz bianbu-ai-support.x86_64 + popd + - | + pushd build.riscv64 + tar czf ../output/bianbu-ai-support.riscv64.$(date +"%Y%m%d_%H%M%S").tar.gz bianbu-ai-support.riscv64 + popd + #- rm -rf build.x86_64 build.riscv64 demo + artifacts: + paths: + - output/bianbu-ai-support.*.tar.gz + <<: *only-defaults + + +upload-archive-nexus: + stage: upload + dependencies: + - build-job-x86_64 + - build-job-riscv64 + script: + - tag=v${CI_COMMIT_REF_NAME#*/} + - | + pushd build.x86_64 + tar czf bianbu-ai-support.x86_64.${tag}.tar.gz bianbu-ai-support.x86_64 + curl -k -u $NEXUS_USERNAME:$NEXUS_PASSWORD --upload-file bianbu-ai-support.x86_64.${tag}.tar.gz https://nexus.bianbu.xyz/repository/bianbu-ai/support-library/bianbu-ai-support.x86_64.${tag}.tar.gz + popd + - | + pushd build.riscv64 + tar czf bianbu-ai-support.riscv64.${tag}.tar.gz bianbu-ai-support.riscv64 + curl -k -u $NEXUS_USERNAME:$NEXUS_PASSWORD --upload-file bianbu-ai-support.riscv64.${tag}.tar.gz https://nexus.bianbu.xyz/repository/bianbu-ai/support-library/bianbu-ai-support.riscv64.${tag}.tar.gz + popd + <<: *rule-upload + +upload-archive-bianbu: + stage: upload + image: harbor.bianbu.xyz/gitlab/ci-pack + dependencies: [] + script: + # TODO: replace by shell script + - echo "Building for tag $CI_COMMIT_TAG" + - eval $(ssh-agent -s) + - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + - ssh-keyscan gitlab.dc.com >> ~/.ssh/known_hosts + - chmod 644 ~/.ssh/known_hosts + - git config --global user.email "bianbu-ci@spacemit.com" + - git config --global user.name "bianbu-ci" + # prepare bianbu-dev toolkits + - cd .. + - git clone git@gitlab.dc.com:bianbu/bianbu-devscripts.git + - export PATH=$(pwd)/bianbu-devscripts:$PATH + # prepare source code + - cd $CI_PROJECT_DIR + - git checkout ${CI_COMMIT_TAG%%/*} + - bianbu-pkg -u local -w . -t $CI_COMMIT_TAG + - changes_file=$(find ../ -maxdepth 1 -type f -name "*.changes" | head -n 1) + # upload + - ssh-keyscan reprepro-headless-service.buildsystem.svc.cluster.local >> ~/.ssh/known_hosts + - bianbu-dev upload $changes_file # --suite mantic-spacemit + # change proxy as ssh + - git remote set-url origin git@gitlab.dc.com:$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME.git + - git push origin --all + # status + - echo "Bianbu devscripts successfully packaged." + <<: *rule-upload + + +lint-test-job: # This job also runs in the test stage. + stage: test # It can run at the same time as unit-test-job (in parallel). + dependencies: [] + script: + - echo "Linting code... This will take about 2 seconds." + - sleep 2 + - echo "No lint issues found." + <<: *only-defaults + +deploy-job: # This job runs in the deploy stage. + stage: deploy # It only runs when *both* jobs in the test stage complete successfully. + environment: production + dependencies: [] + script: + - echo "Deploying application..." + - echo "Application successfully deployed." + only: + - tags + + +# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings +# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings +# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings +# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings +# Note that environment variables can be set in several places +# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence + +sast: + stage: test + dependencies: [] + +include: + - template: Security/SAST.gitlab-ci.yml + - template: Security/Secret-Detection.gitlab-ci.yml \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..4cf2200 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.10) + +project(bianbuai) +add_subdirectory(${CMAKE_SOURCE_DIR}/src) + +option(DEMO "option for Demo" OFF) +if (DEMO) + set(BIANBUAI_HOME ${CMAKE_SOURCE_DIR}) # useless but necessary + add_subdirectory(${CMAKE_SOURCE_DIR}/demo) + install(DIRECTORY ${CMAKE_SOURCE_DIR}/rootfs/usr/bin DESTINATION .) + install(DIRECTORY ${CMAKE_SOURCE_DIR}/rootfs/usr/share DESTINATION .) + install(DIRECTORY ${CMAKE_SOURCE_DIR}/rootfs/etc DESTINATION ..) +endif() +# always install demo project with test data +#install(DIRECTORY ${CMAKE_SOURCE_DIR}/demo DESTINATION .) +#install(DIRECTORY ${CMAKE_SOURCE_DIR}/data DESTINATION demo) + +option(TEST "option for Test" ON) +if (TEST) + add_subdirectory(${CMAKE_SOURCE_DIR}/src/tests) +endif() \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..dc8cc09 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# support + + +## Getting started + +### install dependence +gcc version: 14 + +prepare opencv (at least version 4.2.0) +```bash +sudo apt-get install libopencv-dev +``` +prepare onnxruntime + +visit [onnxruntime release](https://github.com/microsoft/onnxruntime/releases/tag/v1.15.1) and download proper version. + + +### build demo with bash followed + +```bash +ORT_HOME=${PATH_TO_ONNXRUNTIME} +# Note: Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set +# "OpenCV_DIR" to a directory containing one of the following names: +# OpenCVConfig.cmake +# opencv-config.cmake +OPENCV_DIR=${PATH_TO_OPENCV_CMAKE_DIR} + +mkdir build && pushd build +cmake .. -DORT_HOME=${ORT_HOME} -DOpenCV_DIR=${OPENCV_DIR} -DCMAKE_BUILD_TYPE=Debug -DTEST=OFF -DDEMO=ON +make install -j`nproc` +popd + +# Or with cross compiler: +CROSS_TOOL=${PATH_TO_COMPILER_PREFIX}- +SYSROOT=${PATH_TO_SYSROOT} +cmake .. -DORT_HOME=${ORT_HOME} -DOpenCV_DIR=${OPENCV_DIR} \ + -DCMAKE_C_COMPILER=${CROSS_TOOL}gcc -DCMAKE_CXX_COMPILER=${CROSS_TOOL}g++ -DCMAKE_SYSROOT=${SYSROOT} +``` + +### run demo + +```bash +./classification_demo +./detection_stream_demo +./detection_demo +or +./detection_demo +./detection_video_demo +./estimation_demo +./tracker_stream_demo +``` diff --git a/VERSION_NUMBER b/VERSION_NUMBER new file mode 100644 index 0000000..337a6a8 --- /dev/null +++ b/VERSION_NUMBER @@ -0,0 +1 @@ +1.0.8 \ No newline at end of file diff --git a/ci/README.md b/ci/README.md new file mode 100644 index 0000000..2cec02f --- /dev/null +++ b/ci/README.md @@ -0,0 +1,84 @@ +## CI Variables + +| Variable Name | Default Value | Description | +| :--: | :--: | :--: | +| CI_PKG_OPTION | --skip-py | options during ci `package` stage, choose values from [--skip-deb \| --skip-ort \| --skip-py \| --debug] | + +## Bianbu DevScripts + +* step by step + +```bash +# preparation: download bianbu development toolkits +git clone -b main git@gitlab.dc.com:bianbu/bianbu-devscripts.git && cd bianbu-devscripts +# preparation: install dependencies +apt update && apt install sudo vim-common -y +bash install-scripts-depends.sh +# preparation: install ca-certificates +apt-get -y install ca-certificates wget && wget https://nexus.bianbu.xyz/repository/software/dc.com-CA-Root-Base64.crt -O /usr/local/share/ca-certificates/dc.com-CA-Root-Base64.crt --no-check-certificate && update-ca-certificates +# preparation: add bianbu source list +bianbu-dev chroot +# add mantic-spacemit(similar for mantic-porting, mantic-customization) +cat <>/etc/apt/sources.list.d/bianbu.list +# mantic-spacemit +deb [signed-by=/usr/share/keyrings/bianbu-archive-keyring.gpg] https://archive.bianbu.xyz/bianbu-ports/ mantic-spacemit main universe multiverse restricted +deb-src [signed-by=/usr/share/keyrings/bianbu-archive-keyring.gpg] https://archive.bianbu.xyz/bianbu-ports/ mantic-spacemit main universe multiverse restricted +EOF +apt update +exit # quit chroot + +# quick start: check toolkit version +PATH=$(pwd):$PATH +bianbu-dev -v +bianbu-pkg -h +# quick start: default settings +bianbu-dev set-default-dist bianbu-23.10 +bianbu-dev set-default-env bianbu-scripts-env-1.8.1 +# quick start: install docker container for development(optional) +bianbu-dev install + +# ------------------------------------------------------------- + +# quick import: example with gnome-shell +# Note: To import-dsc, plz switch to any non-git repository directory +apt source --download-only gnome-shell # gnome-shell_*-0ubuntu1.debian.tar.xz, gnome-shell_*-0ubuntu1.dsc, gnome-shell_*.orig.tar.xz +bianbu-dev import-dsc gnome-shell_*-0ubuntu1.dsc +# quick glance +tree gnome-shell -L 1 + +# quick import: with bianbu-ai-support +cd bianbu-ai-support && git checkout main +# Note: version number must start with digit(required by dpkg-buildpackage) +bianbu-dev import . --suite mantic-spacemit --new-version 1.0.1 + +# ------------------------------------------------------------- + +# do sth ... +git checkout -b bianbu-23.10 # switch to bianbu-23.10 +bianbu-dev tag +bianbu-dev pack -a # same as `bianbu-dev pack && bianbu-dev build` (pack 1st, then build) + +# ------------------------------------------------------------- + +# enter develop env +bianbu-dev chroot # apt install onnxruntime, libopencv-dev + +# build package with dpkg(Note: install dependencies 1st plz, e.g. onnxruntime, opencv) +apt-get build-dep -y $(pwd) # run in bianbu-ai-support directory +dpkg-buildpackage -us -b -uc --no-pre-clean --no-post-clean # -tc +# .. +# |-- bianbu-ai-support-dbgsym_1.0.1_amd64.ddeb +# |-- bianbu-ai-support_1.0.1_amd64.buildinfo +# |-- bianbu-ai-support_1.0.1_amd64.changes +# |-- bianbu-ai-support_1.0.1_amd64.deb + +# ------------------------------------------------------------- + +# check https://archive.bianbu.xyz/bianbu-ports/logs/ for upload events +bianbu-dev upload onnxruntime_1.15.1_amd64.deb --suite mantic-porting +bianbu-dev upload onnxruntime_1.15.1_riscv64.deb --suite mantic-spacemit + +apt update +apt show onnxruntime +apt install onnxruntime +``` \ No newline at end of file diff --git a/ci/docker.ci.md b/ci/docker.ci.md new file mode 100644 index 0000000..ea9e4be --- /dev/null +++ b/ci/docker.ci.md @@ -0,0 +1,84 @@ +## Auto Construction For Debian + +* create new container + +```bash +IMAGE=harbor.bianbu.xyz/dev/bianbu-scripts-env:1.8.1 +NAME=xxx +docker run --restart=always --net=host --privileged -itd --name $NAME -v $HOME:/mnt $IMAGE /bin/bash +``` + +* enter container && apply patch + +```bash +docker exec -it $NAME /bin/bash +# download qemu patch for bianbu-scripts-env:1.8.1(x86_64) +wget https://nexus.bianbu.xyz/repository/software/qemu-user-static_8.0.4%2Bdfsg-1ubuntu3.23.10.1_amd64.deb +dpkg -i qemu-user-static_8.0.4+dfsg-1ubuntu3.23.10.1_amd64.deb +# re-register qemu-riscv64-static +update-binfmts --disable qemu-riscv64-static +update-binfmts --enable qemu-riscv64-static +# quick glance(`mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc` if necessary) +cat /proc/sys/fs/binfmt_misc/qemu-riscv64 +exit + +# enter with riscv64 rootfs +docker exec -it $NAME schroot -r -c persistent-session +``` + +* update container + +```bash +cat <>/etc/apt/sources.list.d/bianbu.list +# mantic-spacemit +deb [signed-by=/usr/share/keyrings/bianbu-archive-keyring.gpg] https://archive.bianbu.xyz/bianbu-ports/ mantic-spacemit main universe multiverse restricted +deb-src [signed-by=/usr/share/keyrings/bianbu-archive-keyring.gpg] https://archive.bianbu.xyz/bianbu-ports/ mantic-spacemit main universe multiverse restricted +# mantic-porting +deb [signed-by=/usr/share/keyrings/bianbu-archive-keyring.gpg] https://archive.bianbu.xyz/bianbu-ports/ mantic-porting main universe multiverse restricted +deb-src [signed-by=/usr/share/keyrings/bianbu-archive-keyring.gpg] https://archive.bianbu.xyz/bianbu-ports/ mantic-porting main universe multiverse restricted +# mantic-customization +#deb [signed-by=/usr/share/keyrings/bianbu-archive-keyring.gpg] https://archive.bianbu.xyz/bianbu-ports/ mantic-customization main universe multiverse restricted +#deb-src [signed-by=/usr/share/keyrings/bianbu-archive-keyring.gpg] https://archive.bianbu.xyz/bianbu-ports/ mantic-customization main universe multiverse restricted +EOF + +apt update +apt install -y debhelper cmake libopencv-dev onnxruntime + +# update /opt/smartentry/HEAD/pre-run* for smartentry(/sbin/smartentry.sh) +vi /opt/smartentry/HEAD/pre-run +# ... +``` + +* save/export container + +```bash +docker commit $NAME +``` + +* /opt/smartentry/HEAD/pre-run + +```bash +# 此脚本会在docker run 时执行 +# 可以在这里做一些修改,补丁。执行完才会执行run脚本中的内容 +if [ -d "/var/lib/schroot/unpack/persistent-session" ]; then + echo "persistent-session exists." + schroot --recover-session -c persistent-session +else + echo "persistent-session does not exist." + # start a new session with specified chroot named as persistent-session + schroot -b -c mantic-riscv64-sbuild -n persistent-session +fi +echo 'docker inited' > /root/.smartentry_status +mount -o bind /mnt /var/run/schroot/mount/persistent-session/mnt +``` + +* smoke gitlab ci test + +```bash +# run specified session +cp -rdf $CI_PROJECT_DIR/.. /mnt/ +schroot -r -c persistent-session --directory /mnt/ai/support +apt build-dep -y $(pwd) +dpkg-buildpackage -us -b -uc --no-pre-clean --no-post-clean +exit +``` \ No newline at end of file diff --git a/ci/dockerfile.riscv64 b/ci/dockerfile.riscv64 new file mode 100644 index 0000000..9b33fed --- /dev/null +++ b/ci/dockerfile.riscv64 @@ -0,0 +1,9 @@ +FROM harbor.bianbu.xyz/spacemit-ai/bianbu-ai-support:v1.1.0 + +# install spacemit-ai-sdk +COPY spacemit-ai-sdk /opt/ + +# Build/Update bianbu-ai-support:v1.0.1 image: +# $ docker build -t bianbu-ai-support:v1.0.1 -f dockerfile.riscv64 . +# $ docker tag bianbu-ai-support:v1.0.1 harbor.bianbu.xyz/spacemit-ai/bianbu-ai-support:v1.0.1 +# $ docker push harbor.bianbu.xyz/spacemit-ai/bianbu-ai-support:v1.0.1 \ No newline at end of file diff --git a/ci/dockerfile.x86_64 b/ci/dockerfile.x86_64 new file mode 100644 index 0000000..d8a2cb7 --- /dev/null +++ b/ci/dockerfile.x86_64 @@ -0,0 +1,29 @@ +FROM ubuntu:18.04 +LABEL maintainer='ai_support ' + +WORKDIR /home/workspace +ENV LANG=C.UTF-8 TZ=Asia/Shanghai + +# update source +RUN sed -i'' 's/archive\.ubuntu\.com/us\.archive\.ubuntu\.com/' /etc/apt/sources.list +RUN apt -y update + +# install tools for support library and ai toolkit cicd +RUN DEBIAN_FRONTEND=noninteractive apt install -y \ + cmake build-essential gcc g++ libglib2.0-0 \ + libopencv-dev python3 python3-pip \ + curl wget ca-certificates tree --fix-missing + +# install onnxruntime +COPY onnxruntime-linux-x64-*.tgz /tmp/ +RUN tar xzf /tmp/onnxruntime-linux-x64-1.15.1.tgz -C . && rm /tmp/onnxruntime-linux-x64-1.15.1.tgz +RUN tar xzf /tmp/onnxruntime-linux-x64-1.16.3.tgz -C . && rm /tmp/onnxruntime-linux-x64-1.16.3.tgz + +# install spacemit ca-certificates +RUN wget https://nexus.bianbu.xyz/repository/software/dc.com-CA-Root-Base64.crt -O /usr/local/share/ca-certificates/dc.com-CA-Root-Base64.crt --no-check-certificate && update-ca-certificates + +# Build bianbu-ai-support:v1.0.0 image: +# $ docker build -t bianbu-ai-support:v1.0.0 -f dockerfile.x86_64 . +# $ docker tag bianbu-ai-support:v1.0.0 harbor.bianbu.xyz/spacemit-ai/bianbu-ai-support:v1.0.0 +# $ docker push harbor.bianbu.xyz/spacemit-ai/bianbu-ai-support:v1.0.0 +# v1.0.0: digest: sha256:3a8d345662fc0e264de5d630335e778e4ce86c8b79493bb84d63fc11d5aa2b7c size: 1790 \ No newline at end of file diff --git a/ci/pack.sh b/ci/pack.sh new file mode 100644 index 0000000..027d114 --- /dev/null +++ b/ci/pack.sh @@ -0,0 +1,93 @@ +#!/bin/bash +# +# Usage: +# $ bash pack.sh [--skip-deb|--skip-ort|--skip-py|--debug] + +set -e + +[[ ${PY_CMD} ]] || PY_CMD=python3 +REPO_DIR=$(readlink -f "$(dirname $0)/..") + +# check dpkg/python3/... +function check() { + set +e + which $1 1>/dev/null 2>&1 + if [[ 0 -ne $? ]]; then + echo -e "\033[5;31m[ERROR] Plz double check if '$1' is available or not!\033[0m" + exit 1 + fi + set -e +} + +# make debian package +function make_deb_via_dpkg() { + check dpkg + + PKG_NAME=bianbu-ai-support + PKG_VER=$(cat ${REPO_DIR}/VERSION_NUMBER) + PKG_DIR=${REPO_DIR}/${PKG_NAME} + PKG_DESC="bianbu ai support library" + + INSTALL_LOCAL=$(readlink -f $1) + # check existance + if [[ ! -d $INSTALL_LOCAL ]]; then + echo -e "\033[0;31m[ERROR] local installed directory'$INSTALL_LOCAL' doesn't exist!\033[0m" + exit 2 + fi + + # get architecture + ARCH=${INSTALL_LOCAL##*.} + # update architecture for Debian && Ubuntu + if [[ "$ARCH" == "x86_64" ]]; then + ARCH="amd64" + fi + + rm -rf ${PKG_DIR} + # create debian control + mkdir -p ${PKG_DIR}/DEBIAN + cat < ${PKG_DIR}/DEBIAN/control +Package: ${PKG_NAME} +Version: ${PKG_VER} +Section: Utils +Priority: optional +Architecture: ${ARCH} +Build-Depends: cmake, debhelper-compat (= 12), onnxruntime, libopencv-dev +Depends: onnxruntime, libopencv-dev +Maintainer: - +Description: ${PKG_DESC}. +EOF + + # copy bin, lib, include, etc. + mkdir -p ${PKG_DIR}/usr/ + if [[ "$@" =~ "skip-ort" ]]; then + : + else + cp -rd ${INSTALL_LOCAL}/lib/3rdparty/onnxruntime/* ${PKG_DIR}/usr/ + fi + cp -rdf ${INSTALL_LOCAL}/* ${PKG_DIR}/usr/ + cp -rdf ${INSTALL_LOCAL}/../etc ${PKG_DIR}/ + # post process + rm -rdf ${PKG_DIR}/usr/lib/3rdparty ${PKG_DIR}/usr/demo + + # create debian package + dpkg -b ${PKG_DIR} ${PKG_NAME}-${PKG_VER}.deb +} +[[ "$@" =~ "skip-deb" ]] || make_deb_via_dpkg $@ + +# make python package +function make_python_dist_pkg() { + check ${PY_CMD} + + # prepare temp python source directory to avoid inplace constraction + TMP_DIR=${REPO_DIR}/tmp + PY_DIR=${REPO_DIR}/python + rm -rf ${TMP_DIR} && cp -rdf ${PY_DIR} ${TMP_DIR} + + # make python dist package + pushd ${TMP_DIR} + ${PY_CMD} ${TMP_DIR}/setup.py sdist --dist-dir=${REPO_DIR}/dist + ${PY_CMD} ${TMP_DIR}/setup.py bdist_wheel --dist-dir=${REPO_DIR}/dist + popd + [[ "$@" =~ "debug" ]] || rm -rf pushd ${TMP_DIR} +} +[[ "$@" =~ "skip-py" ]] || make_python_dist_pkg $@ \ No newline at end of file diff --git a/ci/test.sh b/ci/test.sh new file mode 100644 index 0000000..1d57f0c --- /dev/null +++ b/ci/test.sh @@ -0,0 +1,100 @@ +#!/bin/bash +# +# Author: hongjie.qin@spacemit.com +# Brief: test demos +# +# +# ├── bianbu-ai-support.riscv64 +# │   ├── bin +# │   ├── include +# │   │   └── bianbuai +# │   └── lib +# │   ├── 3rdparty +# │   │   ├── onnxruntime -> spacemit-ort +# │   │   ├── opencv -> opencv.v4.6.0.qt5 +# │   │   ├── opencv.v4.6.0.gtk2 +# │   │   ├── opencv.v4.6.0.qt5 +# │   │   └── spacemit-ort +# │   ├── libbianbuai.so -> libbianbuai.so.1 +# │   ├── libbianbuai.so.1 -> libbianbuai.so.1.0.1 +# │   └── libbianbuai.so.1.0.1 +# ├── data +# │   ├── config +# │   │   └── nanodet.json +# │   ├── imgs +# │   ├── labels +# │   ├── models +# │   └── videos +# │   └── test.mp4 +# └── test.sh + +#set -e +#set -x + +function show_usage() { + echo "Usage:" + echo " ${BASH_SOURCE[0]} --x86_64 # native test with x86_64 outputs" + echo " ${BASH_SOURCE[0]} --riscv64 # native test with riscv64 outputs" + echo " ${BASH_SOURCE[0]} --qemu # test riscv64 outputs on x86_64 with qemu" +} + +WORKSPACE=$(dirname $(readlink -f ${BASH_SOURCE[0]})) +BIANBUAI_HOME=$WORKSPACE/bianbu-ai-support.riscv64 + +if [[ $@ =~ "x86" ]]; then + BIANBUAI_HOME=$WORKSPACE/bianbu-ai-support.x86_64 +fi +if [[ $@ =~ "--qemu" ]]; then + if [[ $@ =~ "x86" ]]; then + echo "[ERROR] invalid options" && show_usage + exit 0 + fi + # set path for qemu and x86_64-riscv64-gcc + SDK=$(getopt -l --qemu -- $@ | tr -d "'") # e.g. $HOME/workspace/bianbu-ai-release/workspace + SDK=${SDK% --*} + if [[ -z "$SDK" ]]; then + echo "[ERROR] invalid options" && show_usage + exit 0 + fi + SYSROOT=$SDK/spacemit-gcc/sysroot + QEMU_CMD="$SDK/spacemit-qemu/bin/qemu-riscv64 -L $SYSROOT" +fi + +BIN_DIR=${BIANBUAI_HOME}/bin +LIB_BIANBUAI=${BIANBUAI_HOME}/lib +LIB_ONNXRUNTIME=${LIB_BIANBUAI}/3rdparty/onnxruntime/lib +LIB_OPENCV=${LIB_BIANBUAI}/3rdparty/opencv/lib:${LIB_BIANBUAI}/3rdparty/opencv/lib/3rdparty + +task_prepare=( + # TODO: add md5sum checking + "if [[ ! -f data/models/squeezenet1.1-7.onnx ]]; then wget https://media.githubusercontent.com/media/onnx/models/main/archive/vision/classification/squeezenet/model/squeezenet1.1-7.onnx -O data/models/squeezenet1.1-7.onnx; fi" + "if [[ ! -f data/models/nanodet-plus-m_320.onnx ]]; then wget https://bj.bcebos.com/paddlehub/fastdeploy/nanodet-plus-m_320.onnx -O data/models/nanodet-plus-m_320.onnx; fi" +) +task_classification=( + "${BIN_DIR}/classification_demo data/models/squeezenet1.1-7.onnx data/labels/synset.txt data/imgs/dog.jpg" +) +task_detection=( + "${BIN_DIR}/detection_demo data/models/nanodet-plus-m_320.onnx data/imgs/person0.jpg result0.jpg data/labels/coco.txt" + "${BIN_DIR}/detection_demo data/models/nanodet-plus-m_320.int8.onnx data/imgs/person0.jpg result0.int8.jpg data/labels/coco.txt" + "${BIN_DIR}/detection_video_demo data/models/nanodet-plus-m_320.int8.onnx data/labels/coco.txt data/videos/test.mp4 test.avi" + "${BIN_DIR}/detection_stream_demo data/models/nanodet-plus-m_320.int8.onnx data/labels/coco.txt data/videos/test.mp4 video" + "${BIN_DIR}/detection_stream_demo data/models/nanodet-plus-m_320.int8.onnx data/labels/coco.txt 0 cameraId" +) +function smoke_test() { + # preparation(e.g. download models) + echo "[INFO] Prepare ..." + for cmd in "${task_prepare[@]}"; do eval "$cmd"; done + # image classification task test + echo "[INFO] Smoke test with image classification task ..." + for cmd in "${task_classification[@]}"; do + echo "[INFO] Run: $cmd" + env LD_LIBRARY_PATH=${LIB_BIANBUAI}:${LIB_ONNXRUNTIME}:${LIB_OPENCV}:$LD_LIBRARY_PATH ${QEMU_CMD} $cmd + done + # object detection task test + echo "[INFO] Smoke test with object detection task ..." + for cmd in "${task_detection[@]}"; do + echo "[INFO] Run: $cmd" + env LD_LIBRARY_PATH=${LIB_BIANBUAI}:${LIB_ONNXRUNTIME}:${LIB_OPENCV}:$LD_LIBRARY_PATH ${QEMU_CMD} $cmd + done +} +smoke_test diff --git a/data/config/nanodet.json b/data/config/nanodet.json new file mode 100644 index 0000000..30f88e0 --- /dev/null +++ b/data/config/nanodet.json @@ -0,0 +1,12 @@ +{ + "name": "NanoDet", + "instance_name" : "object-detection-inference", + "model_path" : "../models/nanodet-plus-m_320.onnx", + "label_path" : "../labels/coco.txt", + "intra_threads_num" : 4, + "profiling_projects" : "", + "graph_optimization_level" : "ort_disable_all", + "disable_spcacemit_ep" : false, + "log_level" : 0, + "opt_model_path" : "nanodet-plus-m_320_opt.onnx" +} \ No newline at end of file diff --git a/data/config/yolov4.json b/data/config/yolov4.json new file mode 100644 index 0000000..79b2bd5 --- /dev/null +++ b/data/config/yolov4.json @@ -0,0 +1,12 @@ +{ + "name": "Yolov4", + "instance_name" : "object-detection-inference", + "model_path" : "../models/yolov4.onnx", + "label_path" : "../labels/coco.txt", + "intra_threads_num" : 4, + "profiling_projects" : "", + "graph_optimization_level" : "ort_disable_all", + "disable_spcacemit_ep" :false, + "log_level" : 0, + "opt_model_path" : "yolov4_opt.onnx" +} \ No newline at end of file diff --git a/data/config/yolov6.json b/data/config/yolov6.json new file mode 100644 index 0000000..e05c849 --- /dev/null +++ b/data/config/yolov6.json @@ -0,0 +1,12 @@ +{ + "name": "Yolov6", + "instance_name" : "object-detection-inference", + "model_path" : "../models/yolov6p5_t.onnx", + "label_path" : "../labels/coco.txt", + "intra_threads_num" : 4, + "profiling_projects" : "", + "graph_optimization_level" : "ort_disable_all", + "disable_spcacemit_ep" :false, + "log_level" : 0, + "opt_model_path" : "yolov6p5_t_opt.onnx" +} \ No newline at end of file diff --git a/data/imgs/bird.jpeg b/data/imgs/bird.jpeg new file mode 100644 index 0000000..4d699a0 Binary files /dev/null and b/data/imgs/bird.jpeg differ diff --git a/data/imgs/cat.jpg b/data/imgs/cat.jpg new file mode 100644 index 0000000..1e9eff3 Binary files /dev/null and b/data/imgs/cat.jpg differ diff --git a/data/imgs/dog.jpg b/data/imgs/dog.jpg new file mode 100644 index 0000000..3be4738 Binary files /dev/null and b/data/imgs/dog.jpg differ diff --git a/data/imgs/person0.jpg b/data/imgs/person0.jpg new file mode 100644 index 0000000..98690d7 Binary files /dev/null and b/data/imgs/person0.jpg differ diff --git a/data/imgs/person1.jpg b/data/imgs/person1.jpg new file mode 100644 index 0000000..61c46be Binary files /dev/null and b/data/imgs/person1.jpg differ diff --git a/data/imgs/person2.jpeg b/data/imgs/person2.jpeg new file mode 100644 index 0000000..9cac0bf Binary files /dev/null and b/data/imgs/person2.jpeg differ diff --git a/data/labels/coco.txt b/data/labels/coco.txt new file mode 100644 index 0000000..1f42c8e --- /dev/null +++ b/data/labels/coco.txt @@ -0,0 +1,80 @@ +person +bicycle +car +motorcycle +airplane +bus +train +truck +boat +traffic light +fire hydrant +stop sign +parking meter +bench +bird +cat +dog +horse +sheep +cow +elephant +bear +zebra +giraffe +backpack +umbrella +handbag +tie +suitcase +frisbee +skis +snowboard +sports ball +kite +baseball bat +baseball glove +skateboard +surfboard +tennis racket +bottle +wine glass +cup +fork +knife +spoon +bowl +banana +apple +sandwich +orange +broccoli +carrot +hot dog +pizza +donut +cake +chair +couch +potted plant +bed +dining table +toilet +tv +laptop +mouse +remote +keyboard +cell phone +microwave +oven +toaster +sink +refrigerator +book +clock +vase +scissors +teddy bear +hair drier +toothbrush \ No newline at end of file diff --git a/data/labels/synset.txt b/data/labels/synset.txt new file mode 100644 index 0000000..9243b00 --- /dev/null +++ b/data/labels/synset.txt @@ -0,0 +1,1000 @@ +n01440764 tench, Tinca tinca +n01443537 goldfish, Carassius auratus +n01484850 great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias +n01491361 tiger shark, Galeocerdo cuvieri +n01494475 hammerhead, hammerhead shark +n01496331 electric ray, crampfish, numbfish, torpedo +n01498041 stingray +n01514668 cock +n01514859 hen +n01518878 ostrich, Struthio camelus +n01530575 brambling, Fringilla montifringilla +n01531178 goldfinch, Carduelis carduelis +n01532829 house finch, linnet, Carpodacus mexicanus +n01534433 junco, snowbird +n01537544 indigo bunting, indigo finch, indigo bird, Passerina cyanea +n01558993 robin, American robin, Turdus migratorius +n01560419 bulbul +n01580077 jay +n01582220 magpie +n01592084 chickadee +n01601694 water ouzel, dipper +n01608432 kite +n01614925 bald eagle, American eagle, Haliaeetus leucocephalus +n01616318 vulture +n01622779 great grey owl, great gray owl, Strix nebulosa +n01629819 European fire salamander, Salamandra salamandra +n01630670 common newt, Triturus vulgaris +n01631663 eft +n01632458 spotted salamander, Ambystoma maculatum +n01632777 axolotl, mud puppy, Ambystoma mexicanum +n01641577 bullfrog, Rana catesbeiana +n01644373 tree frog, tree-frog +n01644900 tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui +n01664065 loggerhead, loggerhead turtle, Caretta caretta +n01665541 leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea +n01667114 mud turtle +n01667778 terrapin +n01669191 box turtle, box tortoise +n01675722 banded gecko +n01677366 common iguana, iguana, Iguana iguana +n01682714 American chameleon, anole, Anolis carolinensis +n01685808 whiptail, whiptail lizard +n01687978 agama +n01688243 frilled lizard, Chlamydosaurus kingi +n01689811 alligator lizard +n01692333 Gila monster, Heloderma suspectum +n01693334 green lizard, Lacerta viridis +n01694178 African chameleon, Chamaeleo chamaeleon +n01695060 Komodo dragon, Komodo lizard, dragon lizard, giant lizard, Varanus komodoensis +n01697457 African crocodile, Nile crocodile, Crocodylus niloticus +n01698640 American alligator, Alligator mississipiensis +n01704323 triceratops +n01728572 thunder snake, worm snake, Carphophis amoenus +n01728920 ringneck snake, ring-necked snake, ring snake +n01729322 hognose snake, puff adder, sand viper +n01729977 green snake, grass snake +n01734418 king snake, kingsnake +n01735189 garter snake, grass snake +n01737021 water snake +n01739381 vine snake +n01740131 night snake, Hypsiglena torquata +n01742172 boa constrictor, Constrictor constrictor +n01744401 rock python, rock snake, Python sebae +n01748264 Indian cobra, Naja naja +n01749939 green mamba +n01751748 sea snake +n01753488 horned viper, cerastes, sand viper, horned asp, Cerastes cornutus +n01755581 diamondback, diamondback rattlesnake, Crotalus adamanteus +n01756291 sidewinder, horned rattlesnake, Crotalus cerastes +n01768244 trilobite +n01770081 harvestman, daddy longlegs, Phalangium opilio +n01770393 scorpion +n01773157 black and gold garden spider, Argiope aurantia +n01773549 barn spider, Araneus cavaticus +n01773797 garden spider, Aranea diademata +n01774384 black widow, Latrodectus mactans +n01774750 tarantula +n01775062 wolf spider, hunting spider +n01776313 tick +n01784675 centipede +n01795545 black grouse +n01796340 ptarmigan +n01797886 ruffed grouse, partridge, Bonasa umbellus +n01798484 prairie chicken, prairie grouse, prairie fowl +n01806143 peacock +n01806567 quail +n01807496 partridge +n01817953 African grey, African gray, Psittacus erithacus +n01818515 macaw +n01819313 sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita +n01820546 lorikeet +n01824575 coucal +n01828970 bee eater +n01829413 hornbill +n01833805 hummingbird +n01843065 jacamar +n01843383 toucan +n01847000 drake +n01855032 red-breasted merganser, Mergus serrator +n01855672 goose +n01860187 black swan, Cygnus atratus +n01871265 tusker +n01872401 echidna, spiny anteater, anteater +n01873310 platypus, duckbill, duckbilled platypus, duck-billed platypus, Ornithorhynchus anatinus +n01877812 wallaby, brush kangaroo +n01882714 koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus +n01883070 wombat +n01910747 jellyfish +n01914609 sea anemone, anemone +n01917289 brain coral +n01924916 flatworm, platyhelminth +n01930112 nematode, nematode worm, roundworm +n01943899 conch +n01944390 snail +n01945685 slug +n01950731 sea slug, nudibranch +n01955084 chiton, coat-of-mail shell, sea cradle, polyplacophore +n01968897 chambered nautilus, pearly nautilus, nautilus +n01978287 Dungeness crab, Cancer magister +n01978455 rock crab, Cancer irroratus +n01980166 fiddler crab +n01981276 king crab, Alaska crab, Alaskan king crab, Alaska king crab, Paralithodes camtschatica +n01983481 American lobster, Northern lobster, Maine lobster, Homarus americanus +n01984695 spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish +n01985128 crayfish, crawfish, crawdad, crawdaddy +n01986214 hermit crab +n01990800 isopod +n02002556 white stork, Ciconia ciconia +n02002724 black stork, Ciconia nigra +n02006656 spoonbill +n02007558 flamingo +n02009229 little blue heron, Egretta caerulea +n02009912 American egret, great white heron, Egretta albus +n02011460 bittern +n02012849 crane +n02013706 limpkin, Aramus pictus +n02017213 European gallinule, Porphyrio porphyrio +n02018207 American coot, marsh hen, mud hen, water hen, Fulica americana +n02018795 bustard +n02025239 ruddy turnstone, Arenaria interpres +n02027492 red-backed sandpiper, dunlin, Erolia alpina +n02028035 redshank, Tringa totanus +n02033041 dowitcher +n02037110 oystercatcher, oyster catcher +n02051845 pelican +n02056570 king penguin, Aptenodytes patagonica +n02058221 albatross, mollymawk +n02066245 grey whale, gray whale, devilfish, Eschrichtius gibbosus, Eschrichtius robustus +n02071294 killer whale, killer, orca, grampus, sea wolf, Orcinus orca +n02074367 dugong, Dugong dugon +n02077923 sea lion +n02085620 Chihuahua +n02085782 Japanese spaniel +n02085936 Maltese dog, Maltese terrier, Maltese +n02086079 Pekinese, Pekingese, Peke +n02086240 Shih-Tzu +n02086646 Blenheim spaniel +n02086910 papillon +n02087046 toy terrier +n02087394 Rhodesian ridgeback +n02088094 Afghan hound, Afghan +n02088238 basset, basset hound +n02088364 beagle +n02088466 bloodhound, sleuthhound +n02088632 bluetick +n02089078 black-and-tan coonhound +n02089867 Walker hound, Walker foxhound +n02089973 English foxhound +n02090379 redbone +n02090622 borzoi, Russian wolfhound +n02090721 Irish wolfhound +n02091032 Italian greyhound +n02091134 whippet +n02091244 Ibizan hound, Ibizan Podenco +n02091467 Norwegian elkhound, elkhound +n02091635 otterhound, otter hound +n02091831 Saluki, gazelle hound +n02092002 Scottish deerhound, deerhound +n02092339 Weimaraner +n02093256 Staffordshire bullterrier, Staffordshire bull terrier +n02093428 American Staffordshire terrier, Staffordshire terrier, American pit bull terrier, pit bull terrier +n02093647 Bedlington terrier +n02093754 Border terrier +n02093859 Kerry blue terrier +n02093991 Irish terrier +n02094114 Norfolk terrier +n02094258 Norwich terrier +n02094433 Yorkshire terrier +n02095314 wire-haired fox terrier +n02095570 Lakeland terrier +n02095889 Sealyham terrier, Sealyham +n02096051 Airedale, Airedale terrier +n02096177 cairn, cairn terrier +n02096294 Australian terrier +n02096437 Dandie Dinmont, Dandie Dinmont terrier +n02096585 Boston bull, Boston terrier +n02097047 miniature schnauzer +n02097130 giant schnauzer +n02097209 standard schnauzer +n02097298 Scotch terrier, Scottish terrier, Scottie +n02097474 Tibetan terrier, chrysanthemum dog +n02097658 silky terrier, Sydney silky +n02098105 soft-coated wheaten terrier +n02098286 West Highland white terrier +n02098413 Lhasa, Lhasa apso +n02099267 flat-coated retriever +n02099429 curly-coated retriever +n02099601 golden retriever +n02099712 Labrador retriever +n02099849 Chesapeake Bay retriever +n02100236 German short-haired pointer +n02100583 vizsla, Hungarian pointer +n02100735 English setter +n02100877 Irish setter, red setter +n02101006 Gordon setter +n02101388 Brittany spaniel +n02101556 clumber, clumber spaniel +n02102040 English springer, English springer spaniel +n02102177 Welsh springer spaniel +n02102318 cocker spaniel, English cocker spaniel, cocker +n02102480 Sussex spaniel +n02102973 Irish water spaniel +n02104029 kuvasz +n02104365 schipperke +n02105056 groenendael +n02105162 malinois +n02105251 briard +n02105412 kelpie +n02105505 komondor +n02105641 Old English sheepdog, bobtail +n02105855 Shetland sheepdog, Shetland sheep dog, Shetland +n02106030 collie +n02106166 Border collie +n02106382 Bouvier des Flandres, Bouviers des Flandres +n02106550 Rottweiler +n02106662 German shepherd, German shepherd dog, German police dog, alsatian +n02107142 Doberman, Doberman pinscher +n02107312 miniature pinscher +n02107574 Greater Swiss Mountain dog +n02107683 Bernese mountain dog +n02107908 Appenzeller +n02108000 EntleBucher +n02108089 boxer +n02108422 bull mastiff +n02108551 Tibetan mastiff +n02108915 French bulldog +n02109047 Great Dane +n02109525 Saint Bernard, St Bernard +n02109961 Eskimo dog, husky +n02110063 malamute, malemute, Alaskan malamute +n02110185 Siberian husky +n02110341 dalmatian, coach dog, carriage dog +n02110627 affenpinscher, monkey pinscher, monkey dog +n02110806 basenji +n02110958 pug, pug-dog +n02111129 Leonberg +n02111277 Newfoundland, Newfoundland dog +n02111500 Great Pyrenees +n02111889 Samoyed, Samoyede +n02112018 Pomeranian +n02112137 chow, chow chow +n02112350 keeshond +n02112706 Brabancon griffon +n02113023 Pembroke, Pembroke Welsh corgi +n02113186 Cardigan, Cardigan Welsh corgi +n02113624 toy poodle +n02113712 miniature poodle +n02113799 standard poodle +n02113978 Mexican hairless +n02114367 timber wolf, grey wolf, gray wolf, Canis lupus +n02114548 white wolf, Arctic wolf, Canis lupus tundrarum +n02114712 red wolf, maned wolf, Canis rufus, Canis niger +n02114855 coyote, prairie wolf, brush wolf, Canis latrans +n02115641 dingo, warrigal, warragal, Canis dingo +n02115913 dhole, Cuon alpinus +n02116738 African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus +n02117135 hyena, hyaena +n02119022 red fox, Vulpes vulpes +n02119789 kit fox, Vulpes macrotis +n02120079 Arctic fox, white fox, Alopex lagopus +n02120505 grey fox, gray fox, Urocyon cinereoargenteus +n02123045 tabby, tabby cat +n02123159 tiger cat +n02123394 Persian cat +n02123597 Siamese cat, Siamese +n02124075 Egyptian cat +n02125311 cougar, puma, catamount, mountain lion, painter, panther, Felis concolor +n02127052 lynx, catamount +n02128385 leopard, Panthera pardus +n02128757 snow leopard, ounce, Panthera uncia +n02128925 jaguar, panther, Panthera onca, Felis onca +n02129165 lion, king of beasts, Panthera leo +n02129604 tiger, Panthera tigris +n02130308 cheetah, chetah, Acinonyx jubatus +n02132136 brown bear, bruin, Ursus arctos +n02133161 American black bear, black bear, Ursus americanus, Euarctos americanus +n02134084 ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus +n02134418 sloth bear, Melursus ursinus, Ursus ursinus +n02137549 mongoose +n02138441 meerkat, mierkat +n02165105 tiger beetle +n02165456 ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle +n02167151 ground beetle, carabid beetle +n02168699 long-horned beetle, longicorn, longicorn beetle +n02169497 leaf beetle, chrysomelid +n02172182 dung beetle +n02174001 rhinoceros beetle +n02177972 weevil +n02190166 fly +n02206856 bee +n02219486 ant, emmet, pismire +n02226429 grasshopper, hopper +n02229544 cricket +n02231487 walking stick, walkingstick, stick insect +n02233338 cockroach, roach +n02236044 mantis, mantid +n02256656 cicada, cicala +n02259212 leafhopper +n02264363 lacewing, lacewing fly +n02268443 dragonfly, darning needle, devil's darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk +n02268853 damselfly +n02276258 admiral +n02277742 ringlet, ringlet butterfly +n02279972 monarch, monarch butterfly, milkweed butterfly, Danaus plexippus +n02280649 cabbage butterfly +n02281406 sulphur butterfly, sulfur butterfly +n02281787 lycaenid, lycaenid butterfly +n02317335 starfish, sea star +n02319095 sea urchin +n02321529 sea cucumber, holothurian +n02325366 wood rabbit, cottontail, cottontail rabbit +n02326432 hare +n02328150 Angora, Angora rabbit +n02342885 hamster +n02346627 porcupine, hedgehog +n02356798 fox squirrel, eastern fox squirrel, Sciurus niger +n02361337 marmot +n02363005 beaver +n02364673 guinea pig, Cavia cobaya +n02389026 sorrel +n02391049 zebra +n02395406 hog, pig, grunter, squealer, Sus scrofa +n02396427 wild boar, boar, Sus scrofa +n02397096 warthog +n02398521 hippopotamus, hippo, river horse, Hippopotamus amphibius +n02403003 ox +n02408429 water buffalo, water ox, Asiatic buffalo, Bubalus bubalis +n02410509 bison +n02412080 ram, tup +n02415577 bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky Mountain sheep, Ovis canadensis +n02417914 ibex, Capra ibex +n02422106 hartebeest +n02422699 impala, Aepyceros melampus +n02423022 gazelle +n02437312 Arabian camel, dromedary, Camelus dromedarius +n02437616 llama +n02441942 weasel +n02442845 mink +n02443114 polecat, fitch, foulmart, foumart, Mustela putorius +n02443484 black-footed ferret, ferret, Mustela nigripes +n02444819 otter +n02445715 skunk, polecat, wood pussy +n02447366 badger +n02454379 armadillo +n02457408 three-toed sloth, ai, Bradypus tridactylus +n02480495 orangutan, orang, orangutang, Pongo pygmaeus +n02480855 gorilla, Gorilla gorilla +n02481823 chimpanzee, chimp, Pan troglodytes +n02483362 gibbon, Hylobates lar +n02483708 siamang, Hylobates syndactylus, Symphalangus syndactylus +n02484975 guenon, guenon monkey +n02486261 patas, hussar monkey, Erythrocebus patas +n02486410 baboon +n02487347 macaque +n02488291 langur +n02488702 colobus, colobus monkey +n02489166 proboscis monkey, Nasalis larvatus +n02490219 marmoset +n02492035 capuchin, ringtail, Cebus capucinus +n02492660 howler monkey, howler +n02493509 titi, titi monkey +n02493793 spider monkey, Ateles geoffroyi +n02494079 squirrel monkey, Saimiri sciureus +n02497673 Madagascar cat, ring-tailed lemur, Lemur catta +n02500267 indri, indris, Indri indri, Indri brevicaudatus +n02504013 Indian elephant, Elephas maximus +n02504458 African elephant, Loxodonta africana +n02509815 lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens +n02510455 giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca +n02514041 barracouta, snoek +n02526121 eel +n02536864 coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus kisutch +n02606052 rock beauty, Holocanthus tricolor +n02607072 anemone fish +n02640242 sturgeon +n02641379 gar, garfish, garpike, billfish, Lepisosteus osseus +n02643566 lionfish +n02655020 puffer, pufferfish, blowfish, globefish +n02666196 abacus +n02667093 abaya +n02669723 academic gown, academic robe, judge's robe +n02672831 accordion, piano accordion, squeeze box +n02676566 acoustic guitar +n02687172 aircraft carrier, carrier, flattop, attack aircraft carrier +n02690373 airliner +n02692877 airship, dirigible +n02699494 altar +n02701002 ambulance +n02704792 amphibian, amphibious vehicle +n02708093 analog clock +n02727426 apiary, bee house +n02730930 apron +n02747177 ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin +n02749479 assault rifle, assault gun +n02769748 backpack, back pack, knapsack, packsack, rucksack, haversack +n02776631 bakery, bakeshop, bakehouse +n02777292 balance beam, beam +n02782093 balloon +n02783161 ballpoint, ballpoint pen, ballpen, Biro +n02786058 Band Aid +n02787622 banjo +n02788148 bannister, banister, balustrade, balusters, handrail +n02790996 barbell +n02791124 barber chair +n02791270 barbershop +n02793495 barn +n02794156 barometer +n02795169 barrel, cask +n02797295 barrow, garden cart, lawn cart, wheelbarrow +n02799071 baseball +n02802426 basketball +n02804414 bassinet +n02804610 bassoon +n02807133 bathing cap, swimming cap +n02808304 bath towel +n02808440 bathtub, bathing tub, bath, tub +n02814533 beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon +n02814860 beacon, lighthouse, beacon light, pharos +n02815834 beaker +n02817516 bearskin, busby, shako +n02823428 beer bottle +n02823750 beer glass +n02825657 bell cote, bell cot +n02834397 bib +n02835271 bicycle-built-for-two, tandem bicycle, tandem +n02837789 bikini, two-piece +n02840245 binder, ring-binder +n02841315 binoculars, field glasses, opera glasses +n02843684 birdhouse +n02859443 boathouse +n02860847 bobsled, bobsleigh, bob +n02865351 bolo tie, bolo, bola tie, bola +n02869837 bonnet, poke bonnet +n02870880 bookcase +n02871525 bookshop, bookstore, bookstall +n02877765 bottlecap +n02879718 bow +n02883205 bow tie, bow-tie, bowtie +n02892201 brass, memorial tablet, plaque +n02892767 brassiere, bra, bandeau +n02894605 breakwater, groin, groyne, mole, bulwark, seawall, jetty +n02895154 breastplate, aegis, egis +n02906734 broom +n02909870 bucket, pail +n02910353 buckle +n02916936 bulletproof vest +n02917067 bullet train, bullet +n02927161 butcher shop, meat market +n02930766 cab, hack, taxi, taxicab +n02939185 caldron, cauldron +n02948072 candle, taper, wax light +n02950826 cannon +n02951358 canoe +n02951585 can opener, tin opener +n02963159 cardigan +n02965783 car mirror +n02966193 carousel, carrousel, merry-go-round, roundabout, whirligig +n02966687 carpenter's kit, tool kit +n02971356 carton +n02974003 car wheel +n02977058 cash machine, cash dispenser, automated teller machine, automatic teller machine, automated teller, automatic teller, ATM +n02978881 cassette +n02979186 cassette player +n02980441 castle +n02981792 catamaran +n02988304 CD player +n02992211 cello, violoncello +n02992529 cellular telephone, cellular phone, cellphone, cell, mobile phone +n02999410 chain +n03000134 chainlink fence +n03000247 chain mail, ring mail, mail, chain armor, chain armour, ring armor, ring armour +n03000684 chain saw, chainsaw +n03014705 chest +n03016953 chiffonier, commode +n03017168 chime, bell, gong +n03018349 china cabinet, china closet +n03026506 Christmas stocking +n03028079 church, church building +n03032252 cinema, movie theater, movie theatre, movie house, picture palace +n03041632 cleaver, meat cleaver, chopper +n03042490 cliff dwelling +n03045698 cloak +n03047690 clog, geta, patten, sabot +n03062245 cocktail shaker +n03063599 coffee mug +n03063689 coffeepot +n03065424 coil, spiral, volute, whorl, helix +n03075370 combination lock +n03085013 computer keyboard, keypad +n03089624 confectionery, confectionary, candy store +n03095699 container ship, containership, container vessel +n03100240 convertible +n03109150 corkscrew, bottle screw +n03110669 cornet, horn, trumpet, trump +n03124043 cowboy boot +n03124170 cowboy hat, ten-gallon hat +n03125729 cradle +n03126707 crane +n03127747 crash helmet +n03127925 crate +n03131574 crib, cot +n03133878 Crock Pot +n03134739 croquet ball +n03141823 crutch +n03146219 cuirass +n03160309 dam, dike, dyke +n03179701 desk +n03180011 desktop computer +n03187595 dial telephone, dial phone +n03188531 diaper, nappy, napkin +n03196217 digital clock +n03197337 digital watch +n03201208 dining table, board +n03207743 dishrag, dishcloth +n03207941 dishwasher, dish washer, dishwashing machine +n03208938 disk brake, disc brake +n03216828 dock, dockage, docking facility +n03218198 dogsled, dog sled, dog sleigh +n03220513 dome +n03223299 doormat, welcome mat +n03240683 drilling platform, offshore rig +n03249569 drum, membranophone, tympan +n03250847 drumstick +n03255030 dumbbell +n03259280 Dutch oven +n03271574 electric fan, blower +n03272010 electric guitar +n03272562 electric locomotive +n03290653 entertainment center +n03291819 envelope +n03297495 espresso maker +n03314780 face powder +n03325584 feather boa, boa +n03337140 file, file cabinet, filing cabinet +n03344393 fireboat +n03345487 fire engine, fire truck +n03347037 fire screen, fireguard +n03355925 flagpole, flagstaff +n03372029 flute, transverse flute +n03376595 folding chair +n03379051 football helmet +n03384352 forklift +n03388043 fountain +n03388183 fountain pen +n03388549 four-poster +n03393912 freight car +n03394916 French horn, horn +n03400231 frying pan, frypan, skillet +n03404251 fur coat +n03417042 garbage truck, dustcart +n03424325 gasmask, respirator, gas helmet +n03425413 gas pump, gasoline pump, petrol pump, island dispenser +n03443371 goblet +n03444034 go-kart +n03445777 golf ball +n03445924 golfcart, golf cart +n03447447 gondola +n03447721 gong, tam-tam +n03450230 gown +n03452741 grand piano, grand +n03457902 greenhouse, nursery, glasshouse +n03459775 grille, radiator grille +n03461385 grocery store, grocery, food market, market +n03467068 guillotine +n03476684 hair slide +n03476991 hair spray +n03478589 half track +n03481172 hammer +n03482405 hamper +n03483316 hand blower, blow dryer, blow drier, hair dryer, hair drier +n03485407 hand-held computer, hand-held microcomputer +n03485794 handkerchief, hankie, hanky, hankey +n03492542 hard disc, hard disk, fixed disk +n03494278 harmonica, mouth organ, harp, mouth harp +n03495258 harp +n03496892 harvester, reaper +n03498962 hatchet +n03527444 holster +n03529860 home theater, home theatre +n03530642 honeycomb +n03532672 hook, claw +n03534580 hoopskirt, crinoline +n03535780 horizontal bar, high bar +n03538406 horse cart, horse-cart +n03544143 hourglass +n03584254 iPod +n03584829 iron, smoothing iron +n03590841 jack-o'-lantern +n03594734 jean, blue jean, denim +n03594945 jeep, landrover +n03595614 jersey, T-shirt, tee shirt +n03598930 jigsaw puzzle +n03599486 jinrikisha, ricksha, rickshaw +n03602883 joystick +n03617480 kimono +n03623198 knee pad +n03627232 knot +n03630383 lab coat, laboratory coat +n03633091 ladle +n03637318 lampshade, lamp shade +n03642806 laptop, laptop computer +n03649909 lawn mower, mower +n03657121 lens cap, lens cover +n03658185 letter opener, paper knife, paperknife +n03661043 library +n03662601 lifeboat +n03666591 lighter, light, igniter, ignitor +n03670208 limousine, limo +n03673027 liner, ocean liner +n03676483 lipstick, lip rouge +n03680355 Loafer +n03690938 lotion +n03691459 loudspeaker, speaker, speaker unit, loudspeaker system, speaker system +n03692522 loupe, jeweler's loupe +n03697007 lumbermill, sawmill +n03706229 magnetic compass +n03709823 mailbag, postbag +n03710193 mailbox, letter box +n03710637 maillot +n03710721 maillot, tank suit +n03717622 manhole cover +n03720891 maraca +n03721384 marimba, xylophone +n03724870 mask +n03729826 matchstick +n03733131 maypole +n03733281 maze, labyrinth +n03733805 measuring cup +n03742115 medicine chest, medicine cabinet +n03743016 megalith, megalithic structure +n03759954 microphone, mike +n03761084 microwave, microwave oven +n03763968 military uniform +n03764736 milk can +n03769881 minibus +n03770439 miniskirt, mini +n03770679 minivan +n03773504 missile +n03775071 mitten +n03775546 mixing bowl +n03776460 mobile home, manufactured home +n03777568 Model T +n03777754 modem +n03781244 monastery +n03782006 monitor +n03785016 moped +n03786901 mortar +n03787032 mortarboard +n03788195 mosque +n03788365 mosquito net +n03791053 motor scooter, scooter +n03792782 mountain bike, all-terrain bike, off-roader +n03792972 mountain tent +n03793489 mouse, computer mouse +n03794056 mousetrap +n03796401 moving van +n03803284 muzzle +n03804744 nail +n03814639 neck brace +n03814906 necklace +n03825788 nipple +n03832673 notebook, notebook computer +n03837869 obelisk +n03838899 oboe, hautboy, hautbois +n03840681 ocarina, sweet potato +n03841143 odometer, hodometer, mileometer, milometer +n03843555 oil filter +n03854065 organ, pipe organ +n03857828 oscilloscope, scope, cathode-ray oscilloscope, CRO +n03866082 overskirt +n03868242 oxcart +n03868863 oxygen mask +n03871628 packet +n03873416 paddle, boat paddle +n03874293 paddlewheel, paddle wheel +n03874599 padlock +n03876231 paintbrush +n03877472 pajama, pyjama, pj's, jammies +n03877845 palace +n03884397 panpipe, pandean pipe, syrinx +n03887697 paper towel +n03888257 parachute, chute +n03888605 parallel bars, bars +n03891251 park bench +n03891332 parking meter +n03895866 passenger car, coach, carriage +n03899768 patio, terrace +n03902125 pay-phone, pay-station +n03903868 pedestal, plinth, footstall +n03908618 pencil box, pencil case +n03908714 pencil sharpener +n03916031 perfume, essence +n03920288 Petri dish +n03924679 photocopier +n03929660 pick, plectrum, plectron +n03929855 pickelhaube +n03930313 picket fence, paling +n03930630 pickup, pickup truck +n03933933 pier +n03935335 piggy bank, penny bank +n03937543 pill bottle +n03938244 pillow +n03942813 ping-pong ball +n03944341 pinwheel +n03947888 pirate, pirate ship +n03950228 pitcher, ewer +n03954731 plane, carpenter's plane, woodworking plane +n03956157 planetarium +n03958227 plastic bag +n03961711 plate rack +n03967562 plow, plough +n03970156 plunger, plumber's helper +n03976467 Polaroid camera, Polaroid Land camera +n03976657 pole +n03977966 police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria +n03980874 poncho +n03982430 pool table, billiard table, snooker table +n03983396 pop bottle, soda bottle +n03991062 pot, flowerpot +n03992509 potter's wheel +n03995372 power drill +n03998194 prayer rug, prayer mat +n04004767 printer +n04005630 prison, prison house +n04008634 projectile, missile +n04009552 projector +n04019541 puck, hockey puck +n04023962 punching bag, punch bag, punching ball, punchball +n04026417 purse +n04033901 quill, quill pen +n04033995 quilt, comforter, comfort, puff +n04037443 racer, race car, racing car +n04039381 racket, racquet +n04040759 radiator +n04041544 radio, wireless +n04044716 radio telescope, radio reflector +n04049303 rain barrel +n04065272 recreational vehicle, RV, R.V. +n04067472 reel +n04069434 reflex camera +n04070727 refrigerator, icebox +n04074963 remote control, remote +n04081281 restaurant, eating house, eating place, eatery +n04086273 revolver, six-gun, six-shooter +n04090263 rifle +n04099969 rocking chair, rocker +n04111531 rotisserie +n04116512 rubber eraser, rubber, pencil eraser +n04118538 rugby ball +n04118776 rule, ruler +n04120489 running shoe +n04125021 safe +n04127249 safety pin +n04131690 saltshaker, salt shaker +n04133789 sandal +n04136333 sarong +n04141076 sax, saxophone +n04141327 scabbard +n04141975 scale, weighing machine +n04146614 school bus +n04147183 schooner +n04149813 scoreboard +n04152593 screen, CRT screen +n04153751 screw +n04154565 screwdriver +n04162706 seat belt, seatbelt +n04179913 sewing machine +n04192698 shield, buckler +n04200800 shoe shop, shoe-shop, shoe store +n04201297 shoji +n04204238 shopping basket +n04204347 shopping cart +n04208210 shovel +n04209133 shower cap +n04209239 shower curtain +n04228054 ski +n04229816 ski mask +n04235860 sleeping bag +n04238763 slide rule, slipstick +n04239074 sliding door +n04243546 slot, one-armed bandit +n04251144 snorkel +n04252077 snowmobile +n04252225 snowplow, snowplough +n04254120 soap dispenser +n04254680 soccer ball +n04254777 sock +n04258138 solar dish, solar collector, solar furnace +n04259630 sombrero +n04263257 soup bowl +n04264628 space bar +n04265275 space heater +n04266014 space shuttle +n04270147 spatula +n04273569 speedboat +n04275548 spider web, spider's web +n04277352 spindle +n04285008 sports car, sport car +n04286575 spotlight, spot +n04296562 stage +n04310018 steam locomotive +n04311004 steel arch bridge +n04311174 steel drum +n04317175 stethoscope +n04325704 stole +n04326547 stone wall +n04328186 stopwatch, stop watch +n04330267 stove +n04332243 strainer +n04335435 streetcar, tram, tramcar, trolley, trolley car +n04336792 stretcher +n04344873 studio couch, day bed +n04346328 stupa, tope +n04347754 submarine, pigboat, sub, U-boat +n04350905 suit, suit of clothes +n04355338 sundial +n04355933 sunglass +n04356056 sunglasses, dark glasses, shades +n04357314 sunscreen, sunblock, sun blocker +n04366367 suspension bridge +n04367480 swab, swob, mop +n04370456 sweatshirt +n04371430 swimming trunks, bathing trunks +n04371774 swing +n04372370 switch, electric switch, electrical switch +n04376876 syringe +n04380533 table lamp +n04389033 tank, army tank, armored combat vehicle, armoured combat vehicle +n04392985 tape player +n04398044 teapot +n04399382 teddy, teddy bear +n04404412 television, television system +n04409515 tennis ball +n04417672 thatch, thatched roof +n04418357 theater curtain, theatre curtain +n04423845 thimble +n04428191 thresher, thrasher, threshing machine +n04429376 throne +n04435653 tile roof +n04442312 toaster +n04443257 tobacco shop, tobacconist shop, tobacconist +n04447861 toilet seat +n04456115 torch +n04458633 totem pole +n04461696 tow truck, tow car, wrecker +n04462240 toyshop +n04465501 tractor +n04467665 trailer truck, tractor trailer, trucking rig, rig, articulated lorry, semi +n04476259 tray +n04479046 trench coat +n04482393 tricycle, trike, velocipede +n04483307 trimaran +n04485082 tripod +n04486054 triumphal arch +n04487081 trolleybus, trolley coach, trackless trolley +n04487394 trombone +n04493381 tub, vat +n04501370 turnstile +n04505470 typewriter keyboard +n04507155 umbrella +n04509417 unicycle, monocycle +n04515003 upright, upright piano +n04517823 vacuum, vacuum cleaner +n04522168 vase +n04523525 vault +n04525038 velvet +n04525305 vending machine +n04532106 vestment +n04532670 viaduct +n04536866 violin, fiddle +n04540053 volleyball +n04542943 waffle iron +n04548280 wall clock +n04548362 wallet, billfold, notecase, pocketbook +n04550184 wardrobe, closet, press +n04552348 warplane, military plane +n04553703 washbasin, handbasin, washbowl, lavabo, wash-hand basin +n04554684 washer, automatic washer, washing machine +n04557648 water bottle +n04560804 water jug +n04562935 water tower +n04579145 whiskey jug +n04579432 whistle +n04584207 wig +n04589890 window screen +n04590129 window shade +n04591157 Windsor tie +n04591713 wine bottle +n04592741 wing +n04596742 wok +n04597913 wooden spoon +n04599235 wool, woolen, woollen +n04604644 worm fence, snake fence, snake-rail fence, Virginia fence +n04606251 wreck +n04612504 yawl +n04613696 yurt +n06359193 web site, website, internet site, site +n06596364 comic book +n06785654 crossword puzzle, crossword +n06794110 street sign +n06874185 traffic light, traffic signal, stoplight +n07248320 book jacket, dust cover, dust jacket, dust wrapper +n07565083 menu +n07579787 plate +n07583066 guacamole +n07584110 consomme +n07590611 hot pot, hotpot +n07613480 trifle +n07614500 ice cream, icecream +n07615774 ice lolly, lolly, lollipop, popsicle +n07684084 French loaf +n07693725 bagel, beigel +n07695742 pretzel +n07697313 cheeseburger +n07697537 hotdog, hot dog, red hot +n07711569 mashed potato +n07714571 head cabbage +n07714990 broccoli +n07715103 cauliflower +n07716358 zucchini, courgette +n07716906 spaghetti squash +n07717410 acorn squash +n07717556 butternut squash +n07718472 cucumber, cuke +n07718747 artichoke, globe artichoke +n07720875 bell pepper +n07730033 cardoon +n07734744 mushroom +n07742313 Granny Smith +n07745940 strawberry +n07747607 orange +n07749582 lemon +n07753113 fig +n07753275 pineapple, ananas +n07753592 banana +n07754684 jackfruit, jak, jack +n07760859 custard apple +n07768694 pomegranate +n07802026 hay +n07831146 carbonara +n07836838 chocolate sauce, chocolate syrup +n07860988 dough +n07871810 meat loaf, meatloaf +n07873807 pizza, pizza pie +n07875152 potpie +n07880968 burrito +n07892512 red wine +n07920052 espresso +n07930864 cup +n07932039 eggnog +n09193705 alp +n09229709 bubble +n09246464 cliff, drop, drop-off +n09256479 coral reef +n09288635 geyser +n09332890 lakeside, lakeshore +n09399592 promontory, headland, head, foreland +n09421951 sandbar, sand bar +n09428293 seashore, coast, seacoast, sea-coast +n09468604 valley, vale +n09472597 volcano +n09835506 ballplayer, baseball player +n10148035 groom, bridegroom +n10565667 scuba diver +n11879895 rapeseed +n11939491 daisy +n12057211 yellow lady's slipper, yellow lady-slipper, Cypripedium calceolus, Cypripedium parviflorum +n12144580 corn +n12267677 acorn +n12620546 hip, rose hip, rosehip +n12768682 buckeye, horse chestnut, conker +n12985857 coral fungus +n12998815 agaric +n13037406 gyromitra +n13040303 stinkhorn, carrion fungus +n13044778 earthstar +n13052670 hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa +n13054560 bolete +n13133613 ear, spike, capitulum +n15075141 toilet tissue, toilet paper, bathroom tissue \ No newline at end of file diff --git a/debian/README.Debian b/debian/README.Debian new file mode 100644 index 0000000..a678941 --- /dev/null +++ b/debian/README.Debian @@ -0,0 +1,8 @@ +bianbu-ai-support for Debian + +Please edit this to provide information specific to +this bianbu-ai-support Debian package. + + (Automatically generated by debmake Version 4.3.2) + + -- root <> Thu, 04 Jan 2024 20:25:23 +0800 diff --git a/debian/bianbu.conf b/debian/bianbu.conf new file mode 100644 index 0000000..7c743eb --- /dev/null +++ b/debian/bianbu.conf @@ -0,0 +1,4 @@ +[package] +upstream = False +targetsuite = mantic-spacemit + diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..d7d6cff --- /dev/null +++ b/debian/changelog @@ -0,0 +1,55 @@ +bianbu-ai-support (1.0.8) mantic-spacemit; urgency=medium + + [ bianbu-ci ] + * Sync change from bianbu-23.10/1.0.8 + + -- qinhongjie Thu, 24 Feb 2024 13:16:48 +0800 + +bianbu-ai-support (1.0.7) mantic-spacemit; urgency=medium + + [ bianbu-ci ] + * Sync change from bianbu-23.10/1.0.7 + + -- qinhongjie Thu, 1 Feb 2024 18:14:18 +0800 + +bianbu-ai-support (1.0.6) mantic-spacemit; urgency=medium + + [ bianbu-ci ] + * Sync change from bianbu-23.10/1.0.6 + + -- qinhongjie Thu, 26 Jan 2024 12:52:18 +0800 + +bianbu-ai-support (1.0.5) mantic-spacemit; urgency=medium + + [ bianbu-ci ] + * Sync change from bianbu-23.10/1.0.5 + + -- qinhongjie Thu, 25 Jan 2024 21:19:18 +0800 + +bianbu-ai-support (1.0.4) mantic-spacemit; urgency=medium + + [ bianbu-ci ] + * Sync change from bianbu-23.10/1.0.4 + + -- qinhongjie Thu, 19 Jan 2024 17:26:18 +0800 + +bianbu-ai-support (1.0.3) mantic-spacemit; urgency=medium + + [ bianbu-ci ] + * Sync change from bianbu-23.10/1.0.3 + + -- qinhongjie Thu, 18 Jan 2024 17:26:18 +0800 + +bianbu-ai-support (1.0.2) mantic-spacemit; urgency=medium + + [ bianbu-ci ] + * Sync change from bianbu-23.10/1.0.2 + + -- qinhongjie Tue, 16 Jan 2024 21:00:18 +0800 + +bianbu-ai-support (1.0.1) mantic-spacemit; urgency=medium + + * Initial for bianbu-23.10 + + -- root Thu, 04 Jan 2024 20:25:23 +0800 + diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..cd81e1d --- /dev/null +++ b/debian/control @@ -0,0 +1,15 @@ +Source: bianbu-ai-support +Section: Utils +Priority: optional +Maintainer: bianbu-ai-support +Build-Depends: cmake, debhelper-compat (= 12), onnxruntime, libopencv-dev +Standards-Version: 4.5.0 +Homepage: https://gitlab.dc.com:8443/bianbu/ai/support + +Package: bianbu-ai-support +Architecture: any +Multi-Arch: foreign +Depends: ${misc:Depends}, ${shlibs:Depends}, onnxruntime, libopencv-dev +Description: auto-generated package by debmake + This Debian binary package was auto-generated by the + debmake(1) command provided by the debmake package. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..83ef32d --- /dev/null +++ b/debian/copyright @@ -0,0 +1,73 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: bianbu-ai-support +Upstream-Contact: +Source: +# +# Please double check copyright with the licensecheck(1) command. + +Files: .gitlab-ci.yml + CMakeLists.txt + README.md + ci/dockerfile.riscv64 + ci/dockerfile.x86_64 + ci/test.sh + data/config/nanodet.json + data/config/yolov4.json + data/config/yolov6.json + data/imgs/bird.jpeg + data/imgs/cat.jpg + data/imgs/dog.jpg + data/imgs/person0.jpg + data/imgs/person1.jpg + data/imgs/person2.jpeg + data/labels/coco.txt + data/labels/synset.txt + demo/CMakeLists.txt + demo/README.md + demo/build.sh + demo/image_classification_demo.cc + demo/object_detection_demo.cc + demo/object_detection_stream_demo.cc + demo/object_detection_video_demo.cc + demo/utils/box_utils.h + demo/utils/check_utils.h + include/task/vision/image_classification_task.h + include/task/vision/image_classification_types.h + include/task/vision/object_detection_task.h + include/task/vision/object_detection_types.h + include/utils/time.h + include/utils/utils.h + src/CMakeLists.txt + src/core/engine.cc + src/core/engine.h + src/core/ort_wrapper.cc + src/core/ort_wrapper.h + src/processor/classification_postprocessor.cc + src/processor/classification_postprocessor.h + src/processor/classification_preprocessor.cc + src/processor/classification_preprocessor.h + src/processor/detection_postprocessor.cc + src/processor/detection_postprocessor.h + src/processor/detection_preprocessor.cc + src/processor/detection_preprocessor.h + src/processor/processor.h + src/task/core/base_task_api.h + src/task/vision/base_vision_task_api.h + src/task/vision/imageclassification/image_classification.cc + src/task/vision/imageclassification/image_classification.h + src/task/vision/imageclassification/image_classification_task.cc + src/task/vision/objectdetection/object_detection.cc + src/task/vision/objectdetection/object_detection.h + src/task/vision/objectdetection/object_detection_task.cc + src/tests/CMakeLists.txt + src/tests/json_test.cc + src/utils/cv2_utils.h + src/utils/json.hpp + src/utils/nms_utils.h + src/utils/utils.h +Copyright: __NO_COPYRIGHT_NOR_LICENSE__ +License: __NO_COPYRIGHT_NOR_LICENSE__ + +#---------------------------------------------------------------------------- +# Files marked as NO_LICENSE_TEXT_FOUND may be covered by the following +# license/copyright files. diff --git a/debian/postinst b/debian/postinst new file mode 100755 index 0000000..1f8ceef --- /dev/null +++ b/debian/postinst @@ -0,0 +1,64 @@ +#!/bin/bash + +set -e +#set -x + +export XDG_DATA_HOME=${XDG_DATA_HOME:-/usr/share/} + +function copy_install_to_desktop() { + if [ $# -ne 3 ]; then + return; + fi + local curFileName=$1 + local aiDesktopName=$2 + local curUserName=$3 + if [ -e "/usr/share/applications/${aiDesktopName}" ]; then + cp -f /usr/share/applications/${aiDesktopName} "${curFileName}/${gDesktopName}/${wpsDesktopName}" + if test $? -eq 0; then + chmod +x "${curFileName}/${gDesktopName}/${aiDesktopName}" + chown ${curUserName} "${curFileName}/${gDesktopName}/${aiDesktopName}" + fi + fi +} + +aiDesktop=( + "object-detection.desktop" + #"hand-tracker.desktop" + "pose-tracker.desktop" +) +function ai_config_desktop() { + gDesktopName="桌面" + if [ -d "/root/桌面" ]; then + gDesktopName="桌面" + elif [ -d "/root/Desktop" ]; then + gDesktopName="Desktop" + fi + + for FILENAME in /home/*; do + + if [ -f "${FILENAME}/.config/user-dirs.dirs" ]; then + if [ ! $HOME ]; then HOME=${FILENAME}; fi + source "${FILENAME}/.config/user-dirs.dirs" + if [ ! -d "${XDG_DESKTOP_DIR}" ]; then + mkdir -p "${XDG_DESKTOP_DIR}" >/dev/null 2>&1 || true + fi + gDesktopName="${XDG_DESKTOP_DIR//${HOME}\//}" + else + if [ -d "${FILENAME}/桌面" ]; then + gDesktopName="桌面" + elif [ -d "${FILENAME}/Desktop" ]; then + gDesktopName="Desktop" + fi + fi + + if [ -d "${FILENAME}/${gDesktopName}" ]; then + local curUserName=$(echo ${FILENAME} | awk '{print substr($FILENAME, 7, 32)}') + for desktop in "${aiDesktop[@]}"; do + rm -rf ${FILENAME}/${gDesktopName}/${desktop} + copy_install_to_desktop ${FILENAME} ${desktop} ${curUserName} + done + fi + done +} + +ai_config_desktop diff --git a/debian/postrm b/debian/postrm new file mode 100755 index 0000000..e250488 --- /dev/null +++ b/debian/postrm @@ -0,0 +1,40 @@ +#!/bin/bash + +ai_xdg_dirs=/usr/share +ai_xdg_dir= + +function ai_demo_init() { + set -e +} + +function ai_demo_remove() { + if [ -x /usr/bin/update-mime-database ] ; then + : #update-mime-database "${ai_xdg_dir}/mime" + fi + + if [ -x /usr/bin/update-desktop-database ] ; then + : #update-desktop-database -q "${ai_xdg_dir}/applications" + fi + + for HOMEDIR in /home/*; do + : + done +} + +function ai_demo_main() { + if [ $# -eq 0 ] ; then + return; + fi + + ai_demo_init + case $1 in + remove | upgrade ) shift; ai_demo_remove $@;; + purge ) ;; + abort-install ) ;; + abort-upgrade ) ;; + failed-upgrade ) ;; + esac +} + +args="$@" +ai_demo_main $@ diff --git a/debian/preinst b/debian/preinst new file mode 100755 index 0000000..a9bf588 --- /dev/null +++ b/debian/preinst @@ -0,0 +1 @@ +#!/bin/bash diff --git a/debian/prerm b/debian/prerm new file mode 100755 index 0000000..93507e0 --- /dev/null +++ b/debian/prerm @@ -0,0 +1,65 @@ +#!/bin/bash + +export XDG_DATA_HOME=${XDG_DATA_HOME:-/usr/share/} + +function ai_prerm_init() { + set -e +} + +aiDesktop=( + "object-detection.desktop" + "hand-tracker.desktop" + "pose-tracker.desktop" +) +function ai_prerm_uninstall_desktop() { + gDesktopName="桌面" + if [ -d "/root/桌面" ]; then + gDesktopName="桌面" + elif [ -d "/root/Desktop" ]; then + gDesktopName="Desktop" + fi + + #desktop + if [ -d "/root/${gDesktopName}" ]; then + for desktop in "${aiDesktop[@]}"; do + rm -rf /root/${gDesktopName}/${desktop} + done + fi + + for FILENAME in /home/*; do + if [ -f "${FILENAME}/.config/user-dirs.dirs" ]; then + source "${FILENAME}/.config/user-dirs.dirs" + if [ ! -d "${XDG_DESKTOP_DIR}" ]; then + mkdir -p "${XDG_DESKTOP_DIR}" >/dev/null 2>&1 || true + fi + gDesktopName="${XDG_DESKTOP_DIR//${HOME}\//}" + else + if [ -d "${FILENAME}/桌面" ]; then + gDesktopName="桌面" + elif [ -d "${FILENAME}/Desktop" ]; then + gDesktopName="Desktop" + fi + fi + + for desktop in "${aiDesktop[@]}"; do + rm -rf "${FILENAME}/${gDesktopName}/${desktop}" + done + rm -rf ${FILENAME}/.config/bianbu-ai-support + done +} + +function ai_prerm_main() { + if [ $# -eq 0 ]; then + return; + fi + + ai_prerm_init + case $1 in + remove ) shift; ai_prerm_uninstall_desktop $@;; + upgrade ) shift;; + failed-upgrade ) ;; + esac +} + +args="$@" +ai_prerm_main $@ diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..a5d8445 --- /dev/null +++ b/debian/rules @@ -0,0 +1,15 @@ +#!/usr/bin/make -f +# You must remove unused comment lines for the released package. +#export DH_VERBOSE = 1 +#export DEB_BUILD_MAINT_OPTIONS = hardening=+all +#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic +#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed + +%: + dh $@ + +override_dh_auto_configure: + dh_auto_configure -- -DORT_HOME=/usr -DDEMO=ON + +override_dh_shlibdeps: + dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..89ae9db --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (native) diff --git a/debian/source/local-options b/debian/source/local-options new file mode 100644 index 0000000..00131ee --- /dev/null +++ b/debian/source/local-options @@ -0,0 +1,2 @@ +#abort-on-upstream-changes +#unapply-patches diff --git a/debian/watch b/debian/watch new file mode 100644 index 0000000..76575dc --- /dev/null +++ b/debian/watch @@ -0,0 +1,2 @@ +# You must remove unused comment lines for the released package. +version=3 diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt new file mode 100644 index 0000000..b81db54 --- /dev/null +++ b/demo/CMakeLists.txt @@ -0,0 +1,86 @@ +cmake_minimum_required(VERSION 3.10) + +project(bianbuai-demo) + +set(CMAKE_CXX_STANDARD 14) +#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive") + +if (WIN32) + set(ext_src_pattern + "utils/win_getopt/mb/*.cc") + file(GLOB ext_src CONFIGURE_DEPENDS ${ext_src_pattern}) + include_directories("utils/win_getopt/mb/include") +else() + #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror") +endif() + +# TODO: update cc files with '#ifndef NDEBUG' +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG") + +# To find OpenCV, one may need to set OpenCV_DIR variable to the +# absolute path to the directory containing OpenCVConfig.cmake file. +# Otherwise, try to set OPENCV_INC and OPENCV_LIB variables via the +# command line or GUI. +if ((NOT DEFINED OPENCV_INC OR OPENCV_INC STREQUAL "") OR ((NOT DEFINED OPENCV_LIB OR OPENCV_LIB STREQUAL ""))) +find_package(OpenCV REQUIRED COMPONENTS core imgproc imgcodecs videoio highgui) +if (OpenCV_FOUND) + if (NOT DEFINED OPENCV_INC OR OPENCV_INC STREQUAL "") + set(OPENCV_INC "${OpenCV_INCLUDE_DIRS}") + endif() + if (NOT DEFINED OPENCV_LIB OR OPENCV_LIB STREQUAL "") + get_target_property(OpenCV_LIB_PATH opencv_core LOCATION) + get_filename_component(OPENCV_LIB ${OpenCV_LIB_PATH} DIRECTORY) + set(OPENCV_LIBS ${OpenCV_LIBS}) + endif() +endif() +endif() + +# Check Required Env +if (NOT DEFINED BIANBUAI_HOME OR BIANBUAI_HOME STREQUAL "") + message(FATAL_ERROR "Env 'BIANBUAI_HOME' not defined for platform ${CMAKE_GENERATOR_PLATFORM}") +endif() +if (NOT DEFINED OPENCV_INC OR OPENCV_INC STREQUAL "") + message(FATAL_ERROR "OpenCV include dirs not found for platform ${CMAKE_GENERATOR_PLATFORM}") +endif() +if (NOT DEFINED OPENCV_LIB OR OPENCV_LIB STREQUAL "") + message(FATAL_ERROR "OpenCV library dirs not found for platform ${CMAKE_GENERATOR_PLATFORM}") +endif() +if (NOT DEFINED ORT_HOME) + if (EXISTS ${BIANBUAI_HOME}/lib/3rdparty/onnxruntime) + set(ORT_HOME ${BIANBUAI_HOME}/lib/3rdparty/onnxruntime) + else() + message(FATAL_ERROR "Env 'ORT_HOME' not defined and OnnxRuntime library may not found for platform ${CMAKE_GENERATOR_PLATFORM}") + endif() +endif() + +include_directories(${OPENCV_INC} ${BIANBUAI_HOME}/include/bianbuai) + +if (NOT WIN32) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath-link,${BIANBUAI_HOME}/lib:${OPENCV_LIB}:${OPENCV_LIB}/3rdparty:${ORT_HOME}/lib") +endif() +set(TARGET_EXE_LINKER_FLAGS "-Wl,--as-needed") +link_directories(${BIANBUAI_HOME}/lib ${ORT_HOME}/lib ${OPENCV_LIB} ${OPENCV_LIB}/3rdparty) + +add_executable(classification_demo image_classification_demo.cc ${ext_src}) +target_link_libraries(classification_demo PUBLIC bianbuai opencv_core opencv_imgcodecs) + +add_executable(detection_demo object_detection_demo.cc ${ext_src}) +target_link_libraries(detection_demo PUBLIC bianbuai opencv_core opencv_imgproc opencv_imgcodecs) + +add_executable(detection_video_demo object_detection_video_demo.cc ${ext_src}) +target_link_libraries(detection_video_demo PUBLIC bianbuai opencv_core opencv_imgproc opencv_videoio opencv_highgui) + +find_package(Threads REQUIRED) +add_executable(detection_stream_demo object_detection_stream_demo.cc ${ext_src}) +target_link_libraries(detection_stream_demo PUBLIC bianbuai Threads::Threads opencv_core opencv_imgproc opencv_videoio opencv_imgcodecs opencv_highgui) + +add_executable(estimation_demo pose_estimation_demo.cc ${ext_src}) +target_link_libraries(estimation_demo PUBLIC bianbuai opencv_core opencv_imgproc opencv_imgcodecs) + +add_executable(tracker_stream_demo pose_tracker_stream_demo.cc ${ext_src}) +target_link_libraries(tracker_stream_demo PUBLIC bianbuai Threads::Threads opencv_core opencv_imgproc opencv_videoio opencv_imgcodecs opencv_highgui) + +install(TARGETS detection_demo classification_demo detection_stream_demo detection_video_demo estimation_demo tracker_stream_demo + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) diff --git a/demo/README.md b/demo/README.md new file mode 100644 index 0000000..f4d178e --- /dev/null +++ b/demo/README.md @@ -0,0 +1,49 @@ +# User Guide + +## Quick Build + +```bash +# Note: update the following settings if necessary +SDK=${PATH_TO_SPACEMIT_AI_SDK} # e.g. /opt/spacemit-ai-sdk.v0.5.0 + +# For cross compilation, try: +CROSS_TOOL=$SDK/spacemit-gcc/bin/riscv64-unknown-linux-gnu- +SYSROOT=$SDK/spacemit-gcc/sysroot +BIANBUAI_HOME=$SDK/bianbu-ai-support +ORT_HOME=$SDK/spacemit-ort +OPENCV_DIR=$SDK/bianbu-ai-support/lib/3rdparty/opencv4/lib/cmake/opencv4 + +# For native building, one may need to install opencv first, then try: +#CROSS_TOOL= +#SYSROOT= +#BIANBUAI_HOME=$SDK/bianbu-ai-support +#ORT_HOME=${PATH_TO_OFFICIAL_ONNXRUNTIME_RELEASE} +#OPENCV_DIR= + +mkdir build && pushd build +cmake .. -DBIANBUAI_HOME=${BIANBUAI_HOME} -DORT_HOME=${ORT_HOME} -DOpenCV_DIR=${OPENCV_DIR} -DCMAKE_C_COMPILER=${CROSS_TOOL}gcc -DCMAKE_CXX_COMPILER=${CROSS_TOOL}g++ -DCMAKE_SYSROOT=${SYSROOT} +make -j4 +popd +``` + +## Quick Test + +```bash +# Add qemu settings if necessary(e.g. run riscv64 demo on x86_64). +QEMU_CMD="$SDK/qemu/bin/qemu-riscv64 -L $SYSROOT" +# For native test, just let: +#QEMU_CMD= + +# Smoke test with image classification +env LD_LIBRARY_PATH=${ORT_HOME}/lib:$LD_LIBRARY_PATH ${QEMU_CMD} \ + build/classification_demo data/models/squeezenet1.1-7.onnx data/labels/synset.txt data/imgs/dog.jpg + +# Smoke test with object detection +env LD_LIBRARY_PATH=${ORT_HOME}/lib:$LD_LIBRARY_PATH ${QEMU_CMD} \ + build/detection_demo data/models/nanodet-plus-m_320.onnx data/imgs/person0.jpg result0.jpg data/labels/coco.txt +``` + +* Model List + +4f22f9a64ab9612ca4372a0343b3879a [data/models/nanodet-plus-m_320.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/nanodet-plus-m_320.onnx) +497ad0774f4e0b59e4f2c77ae88fcdfc [data/models/squeezenet1.1-7.onnx](https://github.com/onnx/models/blob/main/archive/vision/classification/squeezenet/model/squeezenet1.1-7.onnx) diff --git a/demo/build.sh b/demo/build.sh new file mode 100644 index 0000000..92a1f13 --- /dev/null +++ b/demo/build.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# +# Author: hongjie.qin@spacemit.com +# Brief: Build demos and run smoke test. +# + +set -e + +# Note: update the following settings if necessary +_NAME=bianbu # cuspace +SDK=$(dirname $(which ${_NAME})) #$(dirname ${BASH_SOURCE[0]}) + +function config_native() { + BIANBUAI_HOME=$SDK/bianbu-ai-support + # Plz update the following settings !!! + ORT_HOME=${PATH_TO_OFFICIAL_ONNXRUNTIME_RELEASE} +} + +function config_x86_riscv64() { + CROSS_TOOL=$SDK/spacemit-gcc/bin/riscv64-unknown-linux-gnu- + SYSROOT=$SDK/spacemit-gcc/sysroot + BIANBUAI_HOME=$SDK/bianbu-ai-support + ORT_HOME=$SDK/spacemit-ort # cuspace-ai + OPENCV_DIR=$SDK/bianbu-ai-support/lib/3rdparty/opencv4/lib/cmake/opencv4 + QEMU_CMD="$SDK/spacemit-qemu/bin/qemu-riscv64 -L $SYSROOT" +} + +# config +if [[ $@ =~ "--native" ]]; then + config_native +else + config_x86_riscv64 +fi + +function build() { + mkdir build && pushd build + cmake .. -DBIANBUAI_HOME=${BIANBUAI_HOME} -DORT_HOME=${ORT_HOME} -DOpenCV_DIR=${OPENCV_DIR} -DCMAKE_C_COMPILER=${CROSS_TOOL}gcc -DCMAKE_CXX_COMPILER=${CROSS_TOOL}g++ -DCMAKE_SYSROOT=${SYSROOT} + make -j4 + popd + echo "[INFO] Building demos done." +} +if [[ ! -d build ]]; then + build +else + cd build && make && cd .. +fi + +task_prepare=( + "if [[ ! -d data && -d ../data ]]; then ln -sf ../data .; fi" + "if [[ ! -d data ]]; then echo '[Error] Can not find data directory!'; exit 0; fi" + "mkdir -p data/models" + # TODO: add md5sum checking + "if [[ ! -f data/models/squeezenet1.1-7.onnx ]]; then wget https://media.githubusercontent.com/media/onnx/models/main/validated/vision/classification/squeezenet/model/squeezenet1.1-7.onnx -O data/models/squeezenet1.1-7.onnx; fi" + "if [[ ! -f data/models/nanodet-plus-m_320.onnx ]]; then wget https://bj.bcebos.com/paddlehub/fastdeploy/nanodet-plus-m_320.onnx -O data/models/nanodet-plus-m_320.onnx; fi" +) +task_classification=( + "build/classification_demo data/models/squeezenet1.1-7.onnx data/labels/synset.txt data/imgs/dog.jpg" +) +task_detection=( + "build/detection_demo data/models/nanodet-plus-m_320.onnx data/labels/coco.txt data/imgs/person0.jpg result0.jpg" +) +function smoke_test() { + # preparation(e.g. download models) + echo "[INFO] Prepare ..." + for cmd in "${task_prepare[@]}"; do eval "$cmd"; done + # image classification task test + echo "[INFO] Smoke test with image classification task ..." + for cmd in "${task_classification[@]}"; do + echo "[INFO] Run: $cmd" + env LD_LIBRARY_PATH=${ORT_HOME}/lib:$LD_LIBRARY_PATH ${QEMU_CMD} $cmd + done + # object detection task test + echo "[INFO] Smoke test with object detection task ..." + for cmd in "${task_detection[@]}"; do + echo "[INFO] Run: $cmd" + env LD_LIBRARY_PATH=${ORT_HOME}/lib:$LD_LIBRARY_PATH ${QEMU_CMD} $cmd + done +} + +if [[ "$@" =~ "--test" ]]; then + smoke_test +else + echo "[INFO] Try '${BASH_SOURCE[0]} $@ --test' to run the demos." +fi diff --git a/demo/dataloader.hpp b/demo/dataloader.hpp new file mode 100644 index 0000000..0cb0ad0 --- /dev/null +++ b/demo/dataloader.hpp @@ -0,0 +1,194 @@ +#ifndef SUPPORT_DEMO_DATALOADER_HPP_ +#define SUPPORT_DEMO_DATALOADER_HPP_ + +#include // for: std::isdigit +#include +#include +#include +#include +/* opencv header files */ +#include "opencv2/opencv.hpp" +/* bianbu-ai-support header files */ +#include "utils/utils.h" + +class DataLoader { + public: + DataLoader(const int& resize_height, const int& resize_width) { + enable = true; + resize_height_ = resize_height; + resize_width_ = resize_width; + preview_fps_ = 0; + detection_fps_ = 0; + } + ~DataLoader() {} + bool ifenable() { return enable; } + void set_disable() { enable = false; } + void set_preview_fps(int preview_fps) { preview_fps_ = preview_fps; } + void set_detection_fps(int detection_fps) { detection_fps_ = detection_fps; } + int get_preview_fps() { return preview_fps_; } + int get_detection_fps() { return detection_fps_; } + int get_resize_height() { return resize_height_; } + int get_resize_width() { return resize_width_; } + virtual cv::Mat fetch_frame() = 0; + virtual cv::Mat peek_frame() = 0; + + private: + bool enable; + int resize_height_; + int resize_width_; + int preview_fps_; + int detection_fps_; +}; + +// 独占式 +class ExclusiveDataLoader : public DataLoader { + public: + ExclusiveDataLoader(const int& resize_height, const int& resize_width) + : DataLoader(resize_height, resize_width) {} + ~ExclusiveDataLoader() {} + int init(const std::string& path) { + capture_.open(path); + if (capture_.isOpened()) { + return 0; + } else { + std::cout << "Open video capture failed" << std::endl; + return -1; + } + } + int init(const int camera_id) { + capture_.open(camera_id); + if (capture_.isOpened()) { + return 0; + } else { + std::cout << "Open camera capture failed" << std::endl; + return -1; + } + } + cv::Mat fetch_frame() { + cv::Mat frame; + capture_.read(frame); + return frame; + } + cv::Mat peek_frame() { return fetch_frame(); } + + private: + cv::VideoCapture capture_; +}; + +#ifndef _WIN32 + +#include +#include +#include +#include //for close + +static bool is_valid_camera(const std::string& path) { + int fd = open(path.c_str(), O_RDWR); + if (fd == -1) { + return false; + } + struct v4l2_capability cap; + if (ioctl(fd, VIDIOC_QUERYCAP, &cap) == -1) { + close(fd); + return false; + } + close(fd); + return (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) != 0; +} + +#endif + +inline bool isNumber(const std::string& str) { + for (char const& c : str) { + if (std::isdigit(c) == 0) { + return false; + } + } + return true; +} + +// 共享式 +class SharedDataLoader : public DataLoader { + public: + SharedDataLoader(const int& resize_height, const int& resize_width) + : DataLoader(resize_height, resize_width) {} + ~SharedDataLoader() {} + + int init(const std::string& path) { + if (isNumber(path)) { + return init(std::stoi(path)); + } + capture_.open(path); + if (capture_.isOpened()) { + int width = 1280; + int height = 720; + capture_.set(cv::CAP_PROP_FRAME_WIDTH, width); + capture_.set(cv::CAP_PROP_FRAME_HEIGHT, height); + return 0; + } else { + std::cout << "Open video capture failed" << std::endl; + return -1; + } + } + + int init(int camera_id) { +#ifndef _WIN32 + capture_.open(camera_id); + if (!capture_.isOpened()) { + std::cout + << "Open camera capture failed, try to figure out right camera id" + << std::endl; + std::string path = "/dev/video"; + for (int i = 0; i <= 100; ++i) { + std::string device_path = path + std::to_string(i); + if (is_valid_camera(device_path)) { + capture_.open(i); + if (capture_.isOpened()) { + break; + } + } + } + } +#else + capture_.open(camera_id); +#endif + if (capture_.isOpened()) { + int width = 640; + int height = 480; + capture_.set(cv::CAP_PROP_FRAME_WIDTH, width); + capture_.set(cv::CAP_PROP_FRAME_HEIGHT, height); + return 0; + } else { + std::cout << "Open camera capture failed" << std::endl; + return -1; + } + } + + cv::Mat fetch_frame() { + cv::Mat frame, temp; + capture_.read(frame); + if (!frame.empty()) { + resize_unscale(frame, temp, get_resize_height(), get_resize_width()); + } + frame_mutex_.lock(); + frame_ = temp.clone(); + frame_mutex_.unlock(); + return frame; + } + cv::Mat peek_frame() { + cv::Mat frame; + frame_mutex_.lock(); + frame = frame_.clone(); // 深拷贝 + frame_mutex_.unlock(); + return frame; + } + + private: + std::shared_ptr frame; + cv::Mat frame_; + std::mutex frame_mutex_; + cv::VideoCapture capture_; + std::queue frame_queue_; +}; + +#endif // SUPPORT_DEMO_DATALOADER_HPP_ diff --git a/demo/image_classification_demo.cc b/demo/image_classification_demo.cc new file mode 100644 index 0000000..f3e1dcd --- /dev/null +++ b/demo/image_classification_demo.cc @@ -0,0 +1,54 @@ +#include + +#include "task/vision/image_classification_task.h" +#include "utils/check_utils.h" +#include "utils/time.h" +#include "utils/utils.h" + +int main(int argc, char* argv[]) { + std::string filePath, labelFilepath, imageFilepath; + if (argc == 4) { + filePath = argv[1]; + labelFilepath = argv[2]; + imageFilepath = argv[3]; + } else if (argc > 4) { + filePath = argv[1]; + labelFilepath = argv[2]; + imageFilepath = argv[3]; + if (!checkImageFileExtension(imageFilepath)) { + std::cout << "[ ERROR ] The ImageFilepath is not correct. Make sure you " + "are setting the path to an imgae file (.jpg/.jpeg/.png)" + << std::endl; + return -1; + } + if (!exists_check(imageFilepath)) { + std::cout << "[ ERROR ] The Image File does not exist. Make sure you are " + "setting the correct path to the file" + << std::endl; + return -1; + } + } else { + std::cout << "run with " << argv[0] + << " " + << std::endl; + return -1; + } + cv::Mat imgRaw; + std::unique_ptr imageclassification = + std::unique_ptr( + new imageClassificationTask(filePath, labelFilepath)); +#ifdef DEBUG + std::cout << "." << std::endl; +#endif + { +#ifdef DEBUG + TimeWatcher t("|-- Load input data"); +#endif + imgRaw = cv::imread(imageFilepath); + } + if (!imageclassification->getInitFlag()) { + ImageClassificationResult result = imageclassification->Classify(imgRaw); + std::cout << "classify result: " << result.label_text << std::endl; + } + return 0; +} diff --git a/demo/object_detection.hpp b/demo/object_detection.hpp new file mode 100644 index 0000000..d7e671c --- /dev/null +++ b/demo/object_detection.hpp @@ -0,0 +1,28 @@ +#ifndef SUPPORT_DEMO_OBJECT_DETECTION_HPP_ +#define SUPPORT_DEMO_OBJECT_DETECTION_HPP_ + +#include +#include + +#include "opencv2/opencv.hpp" +#include "task/vision/object_detection_types.h" + +inline void draw_boxes_inplace(cv::Mat &mat_inplace, + const std::vector &boxes) { + if (boxes.empty()) { + return; + } + for (const auto &box : boxes) { + if (box.flag) { + cv::rectangle(mat_inplace, box.rect(), cv::Scalar(255, 255, 0), 2); + if (box.label_text) { + std::string label_text(box.label_text); + label_text = label_text + ":" + std::to_string(box.score).substr(0, 4); + cv::putText(mat_inplace, label_text, box.tl(), cv::FONT_HERSHEY_SIMPLEX, + .5f, cv::Scalar(0, 69, 255), 1); + } + } + } +} + +#endif // SUPPORT_DEMO_OBJECT_DETECTION_HPP_ diff --git a/demo/object_detection_demo.cc b/demo/object_detection_demo.cc new file mode 100644 index 0000000..874462d --- /dev/null +++ b/demo/object_detection_demo.cc @@ -0,0 +1,144 @@ +#include // for: setprecision +#include + +#include "object_detection.hpp" +#include "task/vision/object_detection_task.h" +#include "utils/check_utils.h" +#include "utils/time.h" +#include "utils/utils.h" + +int main(int argc, char* argv[]) { + std::vector resultBoxes; + std::string filePath, modelFilepath, imageFilepath, saveImgpath, + labelFilepath, configFilepath; + cv::Mat imgRaw; +#ifdef DEBUG + std::cout << "." << std::endl; +#endif + if (argc == 4) { + filePath = argv[1]; + imageFilepath = argv[2]; + saveImgpath = argv[3]; + if (!checkImageFileExtension(imageFilepath) || + !checkImageFileExtension(saveImgpath)) { + std::cout << "[ ERROR ] The ImageFilepath is not correct. Make sure you " + "are setting the path to an imgae file (.jpg/.jpeg/.png)" + << std::endl; + return -1; + } + if (!exists_check(imageFilepath)) { + std::cout << "[ ERROR ] The Image File does not exist. Make sure you are " + "setting the correct path to the file" + << std::endl; + return -1; + } + { +#ifdef DEBUG + TimeWatcher t("|-- Load input data"); +#endif + imgRaw = cv::imread(imageFilepath); + } + std::unique_ptr objectdetectiontask = + std::unique_ptr(new objectDetectionTask(filePath)); + resultBoxes = objectdetectiontask->Detect(imgRaw).result_bboxes; + { +#ifdef DEBUG + TimeWatcher t("|-- Output result"); +#endif + for (int i = 0; i < static_cast(resultBoxes.size()); i++) { + if (resultBoxes[i].flag) { + std::cout << "bbox[" << std::setw(2) << i << "]" + << " " + << "x1y1x2y2: " + << "(" << std::setw(4) << resultBoxes[i].x1 << "," + << std::setw(4) << resultBoxes[i].y1 << "," << std::setw(4) + << resultBoxes[i].x2 << "," << std::setw(4) + << resultBoxes[i].y2 << ")" + << ", " + << "score: " << std::fixed << std::setprecision(3) + << std::setw(4) << resultBoxes[i].score << ", " + << "label_text: " << resultBoxes[i].label_text << std::endl; + } + } + } + { +#ifdef DEBUG + TimeWatcher t("|-- Box drawing"); +#endif + draw_boxes_inplace(imgRaw, resultBoxes); + } + + cv::imwrite(saveImgpath, imgRaw); + // cv::imshow("detected.jpg",imgRaw); + // cv::waitKey(0); + } else if (argc == 5) { + filePath = argv[1]; + labelFilepath = argv[2]; + imageFilepath = argv[3]; + saveImgpath = argv[4]; + if (!checkImageFileExtension(imageFilepath) || + !checkImageFileExtension(saveImgpath)) { + std::cout << "[ ERROR ] The ImageFilepath is not correct. Make sure you " + "are setting the path to an imgae file (.jpg/.jpeg/.png)" + << std::endl; + return -1; + } + if (!exists_check(imageFilepath)) { + std::cout << "[ ERROR ] The Image File does not exist. Make sure you are " + "setting the correct path to the file" + << std::endl; + return -1; + } + { +#ifdef DEBUG + TimeWatcher t("|-- Load input data"); +#endif + imgRaw = cv::imread(imageFilepath); + } + std::unique_ptr objectdetectiontask = + std::unique_ptr( + new objectDetectionTask(filePath, labelFilepath)); + if (objectdetectiontask->getInitFlag() != 0) { + return -1; + } + resultBoxes = objectdetectiontask->Detect(imgRaw).result_bboxes; + { +#ifdef DEBUG + TimeWatcher t("|-- Output result"); +#endif + for (int i = 0; i < static_cast(resultBoxes.size()); i++) { + if (resultBoxes[i].flag) { + std::cout << "bbox[" << std::setw(2) << i << "]" + << " " + << "x1y1x2y2: " + << "(" << std::setw(4) << resultBoxes[i].x1 << "," + << std::setw(4) << resultBoxes[i].y1 << "," << std::setw(4) + << resultBoxes[i].x2 << "," << std::setw(4) + << resultBoxes[i].y2 << ")" + << ", " + << "score: " << std::fixed << std::setprecision(3) + << std::setw(4) << resultBoxes[i].score << ", " + << "label_text: " << resultBoxes[i].label_text << std::endl; + } + } + } + { +#ifdef DEBUG + TimeWatcher t("|-- Box drawing"); +#endif + draw_boxes_inplace(imgRaw, resultBoxes); + } + + cv::imwrite(saveImgpath, imgRaw); + // cv::imshow("detected.jpg",imgRaw); + // cv::waitKey(0); + } else { + std::cout + << "run with " << argv[0] + << " or " + << argv[0] << " " + << std::endl; + return -1; + } + return 0; +} diff --git a/demo/object_detection_stream_demo.cc b/demo/object_detection_stream_demo.cc new file mode 100644 index 0000000..f0177ff --- /dev/null +++ b/demo/object_detection_stream_demo.cc @@ -0,0 +1,268 @@ +#include +#include +#include // for: getopt + +#include // for: swap +#include +#include +#include +#include +#include +#include +#include + +#include "dataloader.hpp" +#include "object_detection.hpp" +#include "opencv2/opencv.hpp" +#include "task/vision/object_detection_task.h" +#ifdef DEBUG +#include "utils/time.h" +#endif + +#include "utils/utils.h" + +class Detector { + public: + explicit Detector(const std::string& filePath) { filePath_ = filePath; } + ~Detector() {} + // 初始化/反初始化 + int init() { + objectdetectiontask_ = std::unique_ptr( + new objectDetectionTask(filePath_)); + return get_init_flag(); + } + + int uninit() { return 0; } + + // 推理 + int infer(cv::Mat frame) { + if (frame.empty()) { + return -1; + } + ObjectDetectionResult objs_temp = objectdetectiontask_->Detect(frame); + objs_mutex_.lock(); + objs_array_.push(objs_temp); // 直接替换掉当前的 objs_array_ + objs_mutex_.unlock(); + return objs_array_.size(); + } + + // 查询检测结果 + int detected() { return objs_array_.size(); } + int get_init_flag() { return objectdetectiontask_->getInitFlag(); } + // 移走检测结果 + ObjectDetectionResult get_object() { + ObjectDetectionResult objs_moved; + objs_mutex_.lock(); + objs_moved = objs_array_.back(); + std::queue empty; + std::swap(empty, objs_array_); + objs_mutex_.unlock(); + return objs_moved; + } + + private: + std::mutex objs_mutex_; + std::queue objs_array_; + std::unique_ptr objectdetectiontask_; + std::string filePath_; +}; + +// 检测线程 +void Detection(DataLoader& dataloader, Detector& detector) { + if (detector.init() != 0) { + std::cout << "[ERROR] detector init error" << std::endl; + dataloader.set_disable(); + } + cv::Mat frame; + while (dataloader.ifenable()) { + auto start = std::chrono::steady_clock::now(); + frame = dataloader.peek_frame(); // 取(拷贝)一帧数据 + if ((frame).empty()) { + dataloader.set_disable(); + continue; + } + int flag = detector.infer(frame); // 推理并保存检测结果 + auto end = std::chrono::steady_clock::now(); + auto detection_duration = + std::chrono::duration_cast(end - start); + dataloader.set_detection_fps(1000 / (detection_duration.count())); + if (flag == -1) { + std::cout << "[Error] infer frame failed" << std::endl; + break; // 摄像头结束拍摄或者故障 + } + } + std::cout << "detection thread quit" << std::endl; +} + +// 预览线程 +void Preview(DataLoader& dataloader, Detector& detector) { + cv::Mat frame; + ObjectDetectionResult objs; + auto now = std::chrono::steady_clock::now(); + objs.timestamp = now; + int count = 0; + int dur = 0; + int enable_show = 1; + const char* showfps = getenv("SHOWFPS"); + const char* show = getenv("SHOW"); + if (show && strcmp(show, "-1") == 0) { + enable_show = -1; + } + while (dataloader.ifenable()) { + auto start = std::chrono::steady_clock::now(); + frame = dataloader.fetch_frame(); // 取(搬走)一帧数据 + if ((frame).empty()) { + dataloader.set_disable(); + break; + } + if (detector.detected()) // 判断原因: detector.detected 不用锁, + // detector.get_object 需要锁; + { + // 是否有检测结果 + objs = detector.get_object(); // 取(搬走)检测结果(移动赋值) + if (objs.result_bboxes.size()) { + int input_height = dataloader.get_resize_height(); + int input_width = dataloader.get_resize_width(); + int img_height = frame.rows; + int img_width = frame.cols; + float resize_ratio = std::min( + static_cast(input_height) / static_cast(img_height), + static_cast(input_width) / static_cast(img_width)); + float dw = (input_width - resize_ratio * img_width) / 2; + float dh = (input_height - resize_ratio * img_height) / 2; + for (int i = 0; i < static_cast(objs.result_bboxes.size()); i++) { + objs.result_bboxes[i].x1 = + (objs.result_bboxes[i].x1 - dw) / resize_ratio; + objs.result_bboxes[i].x2 = + (objs.result_bboxes[i].x2 - dw) / resize_ratio; + objs.result_bboxes[i].y1 = + (objs.result_bboxes[i].y1 - dh) / resize_ratio; + objs.result_bboxes[i].y2 = + (objs.result_bboxes[i].y2 - dh) / resize_ratio; + } + } + { +#ifdef DEBUG + TimeWatcher t("|-- Output result"); +#endif + for (int i = 0; i < static_cast(objs.result_bboxes.size()); i++) { + if (objs.result_bboxes[i].flag) { + std::cout << "bbox[" << std::setw(2) << i << "]" + << " " + << "x1y1x2y2: " + << "(" << std::setw(4) << objs.result_bboxes[i].x1 << "," + << std::setw(4) << objs.result_bboxes[i].y1 << "," + << std::setw(4) << objs.result_bboxes[i].x2 << "," + << std::setw(4) << objs.result_bboxes[i].y2 << ")" + << ", " + << "score: " << std::fixed << std::setprecision(3) + << std::setw(4) << objs.result_bboxes[i].score << ", " + << "label_text: " << objs.result_bboxes[i].label_text + << std::endl; + } + } + } + } + // 调用 detector.detected 和 detector.get_object 期间, + // 检测结果依然可能被刷新 + now = std::chrono::steady_clock::now(); + auto duration = std::chrono::duration_cast( + now - objs.timestamp); + if (duration.count() < 1000) { + draw_boxes_inplace((frame), objs.result_bboxes); // 画框 + } + int preview_fps = dataloader.get_preview_fps(); + int detection_fps = dataloader.get_detection_fps(); + if (showfps != nullptr) { + cv::putText(frame, "preview fps: " + std::to_string(preview_fps), + cv::Point(0, 15), cv::FONT_HERSHEY_SIMPLEX, 0.5f, + cv::Scalar(0, 255, 0), 1, cv::LINE_AA); + cv::putText(frame, "detection fps: " + std::to_string(detection_fps), + cv::Point(500, 15), cv::FONT_HERSHEY_SIMPLEX, 0.5f, + cv::Scalar(0, 255, 0), 1, cv::LINE_AA); + } + if (enable_show != -1) { + cv::imshow("Detection", (frame)); + cv::waitKey(10); + } + auto end = std::chrono::steady_clock::now(); + auto preview_duration = + std::chrono::duration_cast(end - start); + count++; + dur = dur + preview_duration.count(); + if (dur >= 1000) { + dataloader.set_preview_fps(count); + dur = 0; + count = 0; + } + if (enable_show != -1) { + if (cv::getWindowProperty("Detection", cv::WND_PROP_VISIBLE) < 1) { + dataloader.set_disable(); + break; + } + } + } + std::cout << "preview thread quit" << std::endl; + if (enable_show != -1) { + cv::destroyAllWindows(); + } +} + +#ifndef _WIN32 +void setThreadName(std::thread& thread, const char* name) { + pthread_setname_np(thread.native_handle(), name); +} +#endif + +int main(int argc, char* argv[]) { + std::string filePath, input, inputType; + int resize_height{320}, resize_width{320}; + if (argc == 4) { + filePath = argv[1]; + input = argv[2]; + inputType = argv[3]; + } else if (argc > 4) { + filePath = argv[1]; + input = argv[2]; + inputType = argv[3]; + int o; + const char* optstring = "w:h:"; + while ((o = getopt(argc, argv, optstring)) != -1) { + switch (o) { + case 'w': + resize_width = atoi(optarg); + break; + case 'h': + resize_height = atoi(optarg); + break; + case '?': + std::cout << "[ERROR] Unsupported usage" << std::endl; + break; + } + } + } else { + std::cout + << "run with " << argv[0] + << " (video " + "or cameraId) option(-h ) option(-w )" + << std::endl; + return -1; + } + Detector detector{filePath}; + SharedDataLoader dataloader{resize_height, resize_width}; + if (dataloader.init(input) != 0) { + std::cout << "[ERROR] dataloader init error" << std::endl; + return -1; + } + + std::thread t1(Preview, std::ref(dataloader), std::ref(detector)); + // std::this_thread::sleep_for(std::chrono::seconds(5)); + std::thread t2(Detection, std::ref(dataloader), std::ref(detector)); +#ifndef _WIN32 + setThreadName(t1, "PreviewThread"); + setThreadName(t2, "DetectionThread"); +#endif + t1.join(); + t2.join(); + return 0; +} diff --git a/demo/object_detection_video_demo.cc b/demo/object_detection_video_demo.cc new file mode 100644 index 0000000..f49075d --- /dev/null +++ b/demo/object_detection_video_demo.cc @@ -0,0 +1,93 @@ +#include + +#include "object_detection.hpp" +#include "task/vision/object_detection_task.h" +#ifdef DEBUG +#include "utils/time.h" +#endif + +#include "utils/utils.h" +int DetectVideo(const std::string &filepath, const std::string &videoPath, + const std::string &srcPath) { + std::unique_ptr objectdetectiontask = + std::unique_ptr(new objectDetectionTask(filepath)); + if (objectdetectiontask->getInitFlag() != 0) { + return -1; + } + cv::VideoCapture capture(videoPath); + if (!capture.isOpened()) { + std::cout << "Open video capture failed" << std::endl; + return -1; + } + cv::Mat frame; + if (!capture.read(frame)) { + std::cout << "Read frame failed" << std::endl; + return -1; + } + double rate = capture.get(cv::CAP_PROP_FPS); + int delay = 1000 / rate; + int fps = rate; + int frameWidth = frame.rows; + int frameHeight = frame.cols; + cv::VideoWriter writer(srcPath, cv::VideoWriter::fourcc('D', 'I', 'V', 'X'), + fps, cv::Size(frameHeight, frameWidth), 1); + while (true) { + capture >> frame; + if (frame.empty()) { + break; + } + std::vector resultBoxes = + objectdetectiontask->Detect(frame).result_bboxes; + { +#ifdef DEBUG + TimeWatcher t("|-- Output result"); +#endif + for (int i = 0; i < static_cast(resultBoxes.size()); i++) { + if (resultBoxes[i].flag) { + std::cout << "bbox[" << std::setw(2) << i << "]" + << " " + << "x1y1x2y2: " + << "(" << std::setw(4) << resultBoxes[i].x1 << "," + << std::setw(4) << resultBoxes[i].y1 << "," << std::setw(4) + << resultBoxes[i].x2 << "," << std::setw(4) + << resultBoxes[i].y2 << ")" + << ", " + << "score: " << std::fixed << std::setprecision(3) + << std::setw(4) << resultBoxes[i].score << ", " + << "label_text: " << resultBoxes[i].label_text << std::endl; + } + } + } + draw_boxes_inplace(frame, resultBoxes); + writer.write(frame); + cv::waitKey( + delay); // 因为图像处理需要消耗一定时间,所以图片展示速度比保存视频要慢 + // cv::imshow("Detection", frame); + } + capture.release(); + writer.release(); + return 0; +} + +int main(int argc, char *argv[]) { + std::string filepath, videoFilepath, dstFilepath; +#ifdef DEBUG + std::cout << "." << std::endl; +#endif + if (argc == 4) { + filepath = argv[1]; + videoFilepath = argv[2]; + dstFilepath = argv[3]; + int flag = DetectVideo(filepath, videoFilepath, dstFilepath); + if (flag != 0) { + std::cout << "[Error] Detect fail" << std::endl; + } + } else { + std::cout << "run with " << argv[0] + << " " + " (end with .avi)" + << std::endl; + return -1; + } + return 0; +} diff --git a/demo/pose_estimation.hpp b/demo/pose_estimation.hpp new file mode 100644 index 0000000..09de60b --- /dev/null +++ b/demo/pose_estimation.hpp @@ -0,0 +1,31 @@ +#ifndef SUPPORT_DEMO_POSE_ESTIMATION_HPP_ +#define SUPPORT_DEMO_POSE_ESTIMATION_HPP_ + +#include // for std::string +#include // for std::pair +#include + +#include "opencv2/opencv.hpp" +#include "task/vision/pose_estimation_types.h" + +inline void draw_points_inplace(cv::Mat &img, + const std::vector &points) { + std::vector> coco_17_joint_links = { + {0, 1}, {0, 2}, {1, 3}, {2, 4}, {5, 7}, {7, 9}, + {6, 8}, {8, 10}, {5, 6}, {5, 11}, {6, 12}, {11, 12}, + {11, 13}, {13, 15}, {12, 14}, {14, 16}}; + for (size_t i = 0; i < points.size(); ++i) { + cv::circle(img, cv::Point(points[i].x, points[i].y), 2, + cv::Scalar{0, 0, 255}, 2, cv::LINE_AA); + } + for (size_t i = 0; i < coco_17_joint_links.size(); ++i) { + std::pair joint_links = coco_17_joint_links[i]; + cv::line( + img, + cv::Point(points[joint_links.first].x, points[joint_links.first].y), + cv::Point(points[joint_links.second].x, points[joint_links.second].y), + cv::Scalar{0, 255, 0}, 2, cv::LINE_AA); + } +} + +#endif // SUPPORT_DEMO_POSE_ESTIMATION_HPP_ diff --git a/demo/pose_estimation_demo.cc b/demo/pose_estimation_demo.cc new file mode 100644 index 0000000..1a9a800 --- /dev/null +++ b/demo/pose_estimation_demo.cc @@ -0,0 +1,106 @@ +#include // for: setprecision +#include + +#include "task/vision/object_detection_task.h" +#include "task/vision/pose_estimation_task.h" +#include "utils/check_utils.h" +#include "utils/time.h" +#include "utils/utils.h" + +int main(int argc, char* argv[]) { + std::vector> coco_17_joint_links = { + {0, 1}, {0, 2}, {1, 3}, {2, 4}, {5, 7}, {7, 9}, + {6, 8}, {8, 10}, {5, 6}, {5, 11}, {6, 12}, {11, 12}, + {11, 13}, {13, 15}, {12, 14}, {14, 16}}; + std::vector resultPoints; + std::vector resultBoxes; + std::string detFilePath, poseFilePath, imageFilepath, saveImgpath; + cv::Mat imgRaw, img; +#ifdef DEBUG + std::cout << "." << std::endl; +#endif + if (argc == 5) { + detFilePath = argv[1]; + poseFilePath = argv[2]; + imageFilepath = argv[3]; + saveImgpath = argv[4]; + if (!checkImageFileExtension(imageFilepath) || + !checkImageFileExtension(saveImgpath)) { + std::cout << "[ ERROR ] The ImageFilepath is not correct. Make sure you " + "are setting the path to an imgae file (.jpg/.jpeg/.png)" + << std::endl; + return -1; + } + if (!exists_check(imageFilepath)) { + std::cout << "[ ERROR ] The Image File does not exist. Make sure you are " + "setting the correct path to the file" + << std::endl; + return -1; + } + { +#ifdef DEBUG + TimeWatcher t("|-- Load input data"); +#endif + imgRaw = cv::imread(imageFilepath); + resize_unscale(imgRaw, img, 320, 320); + } + std::unique_ptr objectdetectiontask = + std::unique_ptr( + new objectDetectionTask(detFilePath)); + if (objectdetectiontask->getInitFlag() != 0) { + return -1; + } + resultBoxes = objectdetectiontask->Detect(img).result_bboxes; + std::unique_ptr poseestimationtask = + std::unique_ptr( + new poseEstimationTask(poseFilePath)); + if (poseestimationtask->getInitFlag() != 0) { + return -1; + } + Boxi box; + for (int i = 0; i < static_cast(resultBoxes.size()); i++) { + box = resultBoxes[i]; + if (box.label != 0) { + continue; + } + resultPoints = poseestimationtask->Estimate(img, box).result_points; + if (resultPoints.size()) { + int input_height = 320; + int input_width = 320; + int img_height = imgRaw.rows; + int img_width = imgRaw.cols; + float resize_ratio = std::min( + static_cast(input_height) / static_cast(img_height), + static_cast(input_width) / static_cast(img_width)); + float dw = (input_width - resize_ratio * img_width) / 2; + float dh = (input_height - resize_ratio * img_height) / 2; + for (int i = 0; i < static_cast(resultPoints.size()); i++) { + resultPoints[i].x = (resultPoints[i].x - dw) / resize_ratio; + resultPoints[i].y = (resultPoints[i].y - dh) / resize_ratio; + } + } + for (int i = 0; i < static_cast(resultPoints.size()); ++i) { + cv::circle(imgRaw, cv::Point(resultPoints[i].x, resultPoints[i].y), 2, + cv::Scalar{0, 0, 255}, 2, cv::LINE_AA); + } + + for (int i = 0; i < static_cast(coco_17_joint_links.size()); ++i) { + std::pair joint_links = coco_17_joint_links[i]; + cv::line(imgRaw, + cv::Point(resultPoints[joint_links.first].x, + resultPoints[joint_links.first].y), + cv::Point(resultPoints[joint_links.second].x, + resultPoints[joint_links.second].y), + cv::Scalar{0, 255, 0}, 2, cv::LINE_AA); + } + } + cv::imwrite(saveImgpath, imgRaw); + } else { + std::cout << "run with " << argv[0] + << " " + " " + << std::endl; + return -1; + } + return 0; +} diff --git a/demo/pose_tracker_stream_demo.cc b/demo/pose_tracker_stream_demo.cc new file mode 100644 index 0000000..86c4f25 --- /dev/null +++ b/demo/pose_tracker_stream_demo.cc @@ -0,0 +1,275 @@ +#include +#include +#include // for: getopt + +#include // for: swap +#include +#include +#include +#include +#include +#include +#include + +#include "dataloader.hpp" +#include "opencv2/opencv.hpp" +#include "pose_estimation.hpp" +#include "task/vision/object_detection_task.h" +#include "task/vision/pose_estimation_task.h" +#ifdef DEBUG +#include "utils/time.h" +#endif + +#include "utils/utils.h" + +class Tracker { + public: + Tracker(const std::string& detFilePath, const std::string& poseFilePath) { + detFilePath_ = detFilePath; + poseFilePath_ = poseFilePath; + } + ~Tracker() {} + // 初始化/反初始化 + int init() { + objectdetectiontask_ = std::unique_ptr( + new objectDetectionTask(detFilePath_)); + poseestimationtask_ = std::unique_ptr( + new poseEstimationTask(poseFilePath_)); + return get_init_flag(); + } + + int get_init_flag() { + return (objectdetectiontask_->getInitFlag() || + poseestimationtask_->getInitFlag()); + } + + int uninit() { return 0; } + + // 推理 + int infer(cv::Mat frame) { + if (frame.empty()) { + return -1; + } + ObjectDetectionResult objs_temp = objectdetectiontask_->Detect(frame); + int count{0}, flag{0}; + for (count = 0; count < static_cast(objs_temp.result_bboxes.size()); + count++) { + if (objs_temp.result_bboxes[count].label == 0) { + flag = 1; + break; + } + } + if (flag) { + PoseEstimationResult poses_temp = + poseestimationtask_->Estimate(frame, objs_temp.result_bboxes[count]); + poses_mutex_.lock(); + poses_array_.push(poses_temp); // 直接替换掉当前的 objs_array_ + poses_mutex_.unlock(); + return poses_array_.size(); + } else { + return 0; + } + } + + // 查询检测结果 + int estimated() { return poses_array_.size(); } + + // 移走检测结果 + struct PoseEstimationResult get_pose() { + struct PoseEstimationResult poses_moved; + poses_mutex_.lock(); + poses_moved = poses_array_.back(); + std::queue empty; + std::swap(empty, poses_array_); + poses_mutex_.unlock(); + return poses_moved; + } + + private: + std::mutex poses_mutex_; + std::queue poses_array_; + std::unique_ptr objectdetectiontask_; + std::unique_ptr poseestimationtask_; + std::string poseFilePath_; + std::string detFilePath_; + std::string labelFilepath_; +}; + +// 检测线程 +void Track(DataLoader& dataloader, Tracker& tracker) { + if (tracker.init() != 0) { + std::cout << "[ERROR] tracker init error" << std::endl; + return; + } + cv::Mat frame; + while (dataloader.ifenable()) { + auto start = std::chrono::steady_clock::now(); + frame = dataloader.peek_frame(); // 取(拷贝)一帧数据 + if ((frame).empty()) { + dataloader.set_disable(); + continue; + } + int flag = tracker.infer(frame); // 推理并保存检测结果 + auto end = std::chrono::steady_clock::now(); + auto detection_duration = + std::chrono::duration_cast(end - start); + dataloader.set_detection_fps(1000 / (detection_duration.count())); + if (flag == 0) { + std::cout << "[Warning] unable to catch person" << std::endl; // 无人 + } + if (flag == -1) { + std::cout << "[Error] infer frame failed" << std::endl; + break; // 摄像头结束拍摄或者故障 + } + } + std::cout << "track thread quit" << std::endl; +} + +// 预览线程 +void Preview(DataLoader& dataloader, Tracker& tracker) { + cv::Mat frame; + PoseEstimationResult poses; + auto now = std::chrono::steady_clock::now(); + poses.timestamp = now; + int count = 0; + int dur = 0; + int enable_show = 1; + const char* showfps = getenv("SHOWFPS"); + const char* show = getenv("SHOW"); + if (show && strcmp(show, "-1") == 0) { + enable_show = -1; + } + while (dataloader.ifenable()) { + auto start = std::chrono::steady_clock::now(); + frame = dataloader.fetch_frame(); // 取(搬走)一帧数据 + if ((frame).empty()) { + dataloader.set_disable(); + break; + } + if (tracker.estimated()) // 判断原因: detector.detected 不用锁, + // detector.get_object 需要锁; + { + // 是否有检测结果 + poses = tracker.get_pose(); // 取(搬走)检测结果(移动赋值) + if (poses.result_points.size()) { + int input_height = dataloader.get_resize_height(); + int input_width = dataloader.get_resize_width(); + int img_height = frame.rows; + int img_width = frame.cols; + float resize_ratio = std::min( + static_cast(input_height) / static_cast(img_height), + static_cast(input_width) / static_cast(img_width)); + float dw = (input_width - resize_ratio * img_width) / 2; + float dh = (input_height - resize_ratio * img_height) / 2; + for (int i = 0; i < static_cast(poses.result_points.size()); i++) { + poses.result_points[i].x = + (poses.result_points[i].x - dw) / resize_ratio; + poses.result_points[i].y = + (poses.result_points[i].y - dh) / resize_ratio; + } + } + } + // 调用 detector.detected 和 detector.get_object 期间, + // 检测结果依然可能被刷新 + now = std::chrono::steady_clock::now(); + auto duration = std::chrono::duration_cast( + now - poses.timestamp); + if (duration.count() < 1000 && poses.result_points.size()) { + draw_points_inplace((frame), poses.result_points); // 画框 + } + int preview_fps = dataloader.get_preview_fps(); + int detection_fps = dataloader.get_detection_fps(); + if (showfps != nullptr) { + cv::putText(frame, "preview fps: " + std::to_string(preview_fps), + cv::Point(0, 15), cv::FONT_HERSHEY_SIMPLEX, 0.5f, + cv::Scalar(0, 255, 0), 1, cv::LINE_AA); + cv::putText(frame, "detection fps: " + std::to_string(detection_fps), + cv::Point(500, 15), cv::FONT_HERSHEY_SIMPLEX, 0.5f, + cv::Scalar(0, 255, 0), 1, cv::LINE_AA); + } + if (enable_show != -1) { + cv::imshow("Track", (frame)); + cv::waitKey(10); + } + auto end = std::chrono::steady_clock::now(); + auto preview_duration = + std::chrono::duration_cast(end - start); + count++; + dur = dur + preview_duration.count(); + if (dur >= 1000) { + dataloader.set_preview_fps(count); + dur = 0; + count = 0; + } + if (enable_show != -1) { + if (cv::getWindowProperty("Track", cv::WND_PROP_VISIBLE) < 1) { + dataloader.set_disable(); + break; + } + } + } + std::cout << "preview thread quit" << std::endl; + if (enable_show != -1) { + cv::destroyAllWindows(); + } +} + +#ifndef _WIN32 +void setThreadName(std::thread& thread, const char* name) { + pthread_setname_np(thread.native_handle(), name); +} +#endif + +int main(int argc, char* argv[]) { + std::string detFilePath, poseFilePath, input, inputType; + int resize_height{320}, resize_width{320}; + if (argc == 5) { + detFilePath = argv[1]; + poseFilePath = argv[2]; + input = argv[3]; + inputType = argv[4]; + } else if (argc > 5) { + detFilePath = argv[1]; + poseFilePath = argv[2]; + input = argv[3]; + inputType = argv[4]; + int o; + const char* optstring = "w:h:"; + while ((o = getopt(argc, argv, optstring)) != -1) { + switch (o) { + case 'w': + resize_width = atoi(optarg); + break; + case 'h': + resize_height = atoi(optarg); + break; + case '?': + std::cout << "[ERROR] Unsupported usage" << std::endl; + break; + } + } + } else { + std::cout << "run with " << argv[0] + << " (video or " + "cameraId option(-h ) option(-w )" + << std::endl; + return -1; + } + Tracker tracker{detFilePath, poseFilePath}; + SharedDataLoader dataloader{resize_height, resize_width}; + if (dataloader.init(input) != 0) { + std::cout << "[ERROR] dataloader init error" << std::endl; + return -1; + } + + std::thread t1(Preview, std::ref(dataloader), std::ref(tracker)); + // std::this_thread::sleep_for(std::chrono::seconds(5)); + std::thread t2(Track, std::ref(dataloader), std::ref(tracker)); +#ifndef _WIN32 + setThreadName(t1, "PreviewThread"); + setThreadName(t2, "TrackerThread"); +#endif + t1.join(); + t2.join(); + return 0; +} diff --git a/demo/utils/check_utils.h b/demo/utils/check_utils.h new file mode 100644 index 0000000..cdd533c --- /dev/null +++ b/demo/utils/check_utils.h @@ -0,0 +1,23 @@ +#ifndef SUPPORT_DEMO_UTILS_CHECK_UTILS_H_ +#define SUPPORT_DEMO_UTILS_CHECK_UTILS_H_ +#include +#include +#include +#include + +static bool checkImageFileExtension(const std::string& filename) { + size_t pos = filename.rfind('.'); + if (filename.empty()) { + std::cout << "[ ERROR ] The Image file path is empty" << std::endl; + return false; + } + if (pos == std::string::npos) return false; + std::string ext = filename.substr(pos + 1); + if (ext == "jpeg" || ext == "jpg" || ext == "png") { + return true; + } else { + return false; + } +} + +#endif // SUPPORT_DEMO_UTILS_CHECK_UTILS_H_ diff --git a/demo/utils/win_getopt/mb/getopt.cc b/demo/utils/win_getopt/mb/getopt.cc new file mode 100644 index 0000000..ddd31ce --- /dev/null +++ b/demo/utils/win_getopt/mb/getopt.cc @@ -0,0 +1,117 @@ +/* $NetBSD: getopt.c,v 1.29 2014/06/05 22:00:22 christos Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1987, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include + +int opterr = 1, /* if error message should be printed */ + optind = 1, /* index into parent argv vector */ + optopt, /* character checked for validity */ + optreset; /* reset getopt */ +char* optarg; /* argument associated with option */ + +#define BADCH (int)'?' +#define BADARG (int)':' +#define EMSG "" + +/* + * getopt -- + * Parse argc/argv argument vector. + */ +int getopt(int nargc, char* const nargv[], const char* ostr) { + static char* place = EMSG; /* option letter processing */ + char* oli; /* option letter list index */ + + if (optreset || *place == 0) { /* update scanning pointer */ + optreset = 0; + place = nargv[optind]; + if (optind >= nargc || *place++ != '-') { + /* Argument is absent or is not an option */ + place = EMSG; + return (-1); + } + optopt = *place++; + if (optopt == '-' && *place == 0) { + /* "--" => end of options */ + ++optind; + place = EMSG; + return (-1); + } + if (optopt == 0) { + /* Solitary '-', treat as a '-' option + if the program (eg su) is looking for it. */ + place = EMSG; + if (strchr(ostr, '-') == NULL) return (-1); + optopt = '-'; + } + } else + optopt = *place++; + + /* See if option letter is one the caller wanted... */ + if (optopt == ':' || (oli = (char*)strchr(ostr, optopt)) == NULL) { + if (*place == 0) ++optind; + if (opterr && *ostr != ':') (void)fprintf(stderr, "illegal option -- %c\n", optopt); + return (BADCH); + } + + /* Does this option need an argument? */ + if (oli[1] != ':') { + /* don't need argument */ + optarg = NULL; + if (*place == 0) ++optind; + } else { + /* Option-argument is either the rest of this argument or the + entire next argument. */ + if (*place) + optarg = place; + else if (oli[2] == ':') + /* + * GNU Extension, for optional arguments if the rest of + * the argument is empty, we return NULL + */ + optarg = NULL; + else if (nargc > ++optind) + optarg = nargv[optind]; + else { + /* option-argument absent */ + place = EMSG; + if (*ostr == ':') return (BADARG); + if (opterr) (void)fprintf(stderr, "option requires an argument -- %c\n", optopt); + return (BADCH); + } + place = EMSG; + ++optind; + } + return (optopt); /* return option letter */ +} \ No newline at end of file diff --git a/demo/utils/win_getopt/mb/include/getopt.h b/demo/utils/win_getopt/mb/include/getopt.h new file mode 100644 index 0000000..6477ee9 --- /dev/null +++ b/demo/utils/win_getopt/mb/include/getopt.h @@ -0,0 +1,42 @@ +/* $NetBSD: getopt.c,v 1.29 2014/06/05 22:00:22 christos Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1987, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#pragma once + +extern int opterr, /* if error message should be printed */ + optind, /* index into parent argv vector */ + optopt, /* character checked for validity */ + optreset; /* reset getopt */ +extern char* optarg; /* argument associated with option */ + +int getopt(int nargc, char* const nargv[], const char* ostr); diff --git a/demo/utils/win_getopt/mb/include/unistd.h b/demo/utils/win_getopt/mb/include/unistd.h new file mode 100644 index 0000000..0a1da04 --- /dev/null +++ b/demo/utils/win_getopt/mb/include/unistd.h @@ -0,0 +1,5 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#pragma once +#include "getopt.h" diff --git a/demo/utils/win_getopt/wide/getopt.cc b/demo/utils/win_getopt/wide/getopt.cc new file mode 100644 index 0000000..22de6e7 --- /dev/null +++ b/demo/utils/win_getopt/wide/getopt.cc @@ -0,0 +1,117 @@ +/* $NetBSD: getopt.c,v 1.29 2014/06/05 22:00:22 christos Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1987, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include + +int opterr = 1, /* if error message should be printed */ + optind = 1, /* index into parent argv vector */ + optopt, /* character checked for validity */ + optreset; /* reset getopt */ +const wchar_t* optarg; /* argument associated with option */ + +#define BADCH (int)L'?' +#define BADARG (int)L':' +#define EMSG L"" + +/* + * getopt -- + * Parse argc/argv argument vector. + */ +int getopt(int nargc, wchar_t* const nargv[], const wchar_t* ostr) { + static const wchar_t* place = EMSG; /* option letter processing */ + wchar_t* oli; /* option letter list index */ + + if (optreset || *place == 0) { /* update scanning pointer */ + optreset = 0; + place = nargv[optind]; + if (optind >= nargc || *place++ != L'-') { + /* Argument is absent or is not an option */ + place = EMSG; + return (-1); + } + optopt = *place++; + if (optopt == L'-' && *place == 0) { + /* "--" => end of options */ + ++optind; + place = EMSG; + return (-1); + } + if (optopt == 0) { + /* Solitary '-', treat as a '-' option + if the program (eg su) is looking for it. */ + place = EMSG; + if (wcschr(ostr, L'-') == NULL) return (-1); + optopt = '-'; + } + } else + optopt = *place++; + + /* See if option letter is one the caller wanted... */ + if (optopt == L':' || (oli = (wchar_t*)wcschr(ostr, (wchar_t)optopt)) == NULL) { + if (*place == 0) ++optind; + if (opterr && *ostr != L':') (void)fprintf(stderr, "illegal option -- %c\n", optopt); + return (BADCH); + } + + /* Does this option need an argument? */ + if (oli[1] != L':') { + /* don't need argument */ + optarg = NULL; + if (*place == 0) ++optind; + } else { + /* Option-argument is either the rest of this argument or the + entire next argument. */ + if (*place) + optarg = place; + else if (oli[2] == L':') + /* + * GNU Extension, for optional arguments if the rest of + * the argument is empty, we return NULL + */ + optarg = NULL; + else if (nargc > ++optind) + optarg = nargv[optind]; + else { + /* option-argument absent */ + place = EMSG; + if (*ostr == L':') return (BADARG); + if (opterr) (void)fprintf(stderr, "option requires an argument -- %c\n", optopt); + return (BADCH); + } + place = EMSG; + ++optind; + } + return (optopt); /* return option letter */ +} \ No newline at end of file diff --git a/demo/utils/win_getopt/wide/include/getopt.h b/demo/utils/win_getopt/wide/include/getopt.h new file mode 100644 index 0000000..4e37bc0 --- /dev/null +++ b/demo/utils/win_getopt/wide/include/getopt.h @@ -0,0 +1,42 @@ +/* $NetBSD: getopt.c,v 1.29 2014/06/05 22:00:22 christos Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1987, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#pragma once + +extern int opterr, /* if error message should be printed */ + optind, /* index into parent argv vector */ + optopt, /* character checked for validity */ + optreset; /* reset getopt */ +extern const wchar_t* optarg; /* argument associated with option */ + +int getopt(int nargc, wchar_t* const nargv[], const wchar_t* ostr); diff --git a/include/task/vision/image_classification_task.h b/include/task/vision/image_classification_task.h new file mode 100644 index 0000000..52f8ace --- /dev/null +++ b/include/task/vision/image_classification_task.h @@ -0,0 +1,24 @@ +#ifndef SUPPORT_INCLUDE_TASK_VISION_IMAGE_CLASSIFICATION_TASK_H_ +#define SUPPORT_INCLUDE_TASK_VISION_IMAGE_CLASSIFICATION_TASK_H_ + +#include // for: shared_ptr +#include + +#include "opencv2/opencv.hpp" +#include "task/vision/image_classification_types.h" + +class imageClassificationTask { + public: + imageClassificationTask(const std::string& filePath, + const std::string& labelFilepath); + ~imageClassificationTask() = default; + ImageClassificationResult Classify(const cv::Mat& img_raw); + int getInitFlag(); + + private: + class impl; + std::shared_ptr pimpl_; + int init_flag_; +}; + +#endif // SUPPORT_INCLUDE_TASK_VISION_IMAGE_CLASSIFICATION_TASK_H_ diff --git a/include/task/vision/image_classification_types.h b/include/task/vision/image_classification_types.h new file mode 100644 index 0000000..2b6e355 --- /dev/null +++ b/include/task/vision/image_classification_types.h @@ -0,0 +1,12 @@ +#ifndef SUPPORT_INCLUDE_TASK_VISION_IMAGE_CLASSIFICATION_TYPES_H_ +#define SUPPORT_INCLUDE_TASK_VISION_IMAGE_CLASSIFICATION_TYPES_H_ + +#include +#include + +struct ImageClassificationResult { + std::string label_text; + int label; + float score; +}; +#endif // SUPPORT_INCLUDE_TASK_VISION_IMAGE_CLASSIFICATION_TYPES_H_ diff --git a/include/task/vision/object_detection_task.h b/include/task/vision/object_detection_task.h new file mode 100644 index 0000000..33ff43e --- /dev/null +++ b/include/task/vision/object_detection_task.h @@ -0,0 +1,30 @@ +#ifndef SUPPORT_INCLUDE_TASK_VISION_OBJECT_DETECTION_TASK_H_ +#define SUPPORT_INCLUDE_TASK_VISION_OBJECT_DETECTION_TASK_H_ + +#include // for: shared_ptr +#include +#include //for: vector + +#include "opencv2/opencv.hpp" +#include "task/vision/object_detection_types.h" + +class objectDetectionTask { + public: + objectDetectionTask(const std::string &filePath, + const std::string &labelFilepath); + explicit objectDetectionTask(const std::string &filePath); + ~objectDetectionTask() = default; + ObjectDetectionResult Detect(const cv::Mat &raw_img); + ObjectDetectionResult Detect( + const std::vector> &input_tensors, + const int img_height, const int img_width); + std::vector> Process(const cv::Mat &img_raw); + int getInitFlag(); + + private: + class impl; + std::shared_ptr pimpl_; + int init_flag_; +}; + +#endif // SUPPORT_INCLUDE_TASK_VISION_OBJECT_DETECTION_TASK_H_ diff --git a/include/task/vision/object_detection_types.h b/include/task/vision/object_detection_types.h new file mode 100644 index 0000000..358f7b1 --- /dev/null +++ b/include/task/vision/object_detection_types.h @@ -0,0 +1,165 @@ +#ifndef SUPPORT_INCLUDE_TASK_VISION_OBJECT_DETECTION_TYPES_H_ +#define SUPPORT_INCLUDE_TASK_VISION_OBJECT_DETECTION_TYPES_H_ + +#include +#include // for numeric_limits<> +#include +#include + +#include "opencv2/opencv.hpp" + +template +static inline void __assert_type() { + static_assert( + std::is_pod<_T1>::value && std::is_pod<_T2>::value && + std::is_floating_point<_T2>::value && + (std::is_integral<_T1>::value || std::is_floating_point<_T1>::value), + "not support type."); +} // only support for some specific types. check at compile-time. + +// bounding box. +template +struct BoundingBoxType { + typedef T1 value_type; + typedef T2 score_type; + value_type x1; + value_type y1; + value_type x2; + value_type y2; + score_type score; + const char *label_text; + unsigned int label; // for general object detection. + bool flag; // future use. + // convert type. + template + BoundingBoxType convert_type() const; + + template + value_type iou_of(const BoundingBoxType &other) const; + + value_type width() const; + + value_type height() const; + + value_type area() const; + + cv::Rect rect() const; + + cv::Point2i tl() const; + + cv::Point2i bl() const; + + cv::Point2i rb() const; + + BoundingBoxType() + : x1(static_cast(0)), + y1(static_cast(0)), + x2(static_cast(0)), + y2(static_cast(0)), + score(static_cast(0)), + label_text(nullptr), + label(0), + flag(false) { + __assert_type(); + } +}; // End BoundingBox. + +typedef BoundingBoxType Boxi; +typedef BoundingBoxType Boxf; +typedef BoundingBoxType Boxd; + +/* implementation for 'BoundingBox'. */ +template +template +inline BoundingBoxType BoundingBoxType::convert_type() const { + typedef O1 other_value_type; + typedef O2 other_score_type; + __assert_type(); + __assert_type(); + BoundingBoxType other; + other.x1 = static_cast(x1); + other.y1 = static_cast(y1); + other.x2 = static_cast(x2); + other.y2 = static_cast(y2); + other.score = static_cast(score); + other.label_text = label_text; + other.label = label; + other.flag = flag; + return other; +} + +template +template +inline typename BoundingBoxType::value_type +BoundingBoxType::iou_of(const BoundingBoxType &other) const { + BoundingBoxType tbox = + other.template convert_type(); + value_type inner_x1 = x1 > tbox.x1 ? x1 : tbox.x1; + value_type inner_y1 = y1 > tbox.y1 ? y1 : tbox.y1; + value_type inner_x2 = x2 < tbox.x2 ? x2 : tbox.x2; + value_type inner_y2 = y2 < tbox.y2 ? y2 : tbox.y2; + value_type inner_h = inner_y2 - inner_y1 + static_cast(1.0f); + value_type inner_w = inner_x2 - inner_x1 + static_cast(1.0f); + if (inner_h <= static_cast(0.f) || + inner_w <= static_cast(0.f)) + return std::numeric_limits::min(); + value_type inner_area = inner_h * inner_w; + return static_cast(inner_area / + (area() + tbox.area() - inner_area)); +} + +template +inline cv::Rect BoundingBoxType::rect() const { + __assert_type(); + auto boxi = this->template convert_type(); + return cv::Rect(boxi.x1, boxi.y1, boxi.width(), boxi.height()); +} + +template +inline cv::Point2i BoundingBoxType::tl() const { + __assert_type(); + auto boxi = this->template convert_type(); + return cv::Point2i(boxi.x1, boxi.y1 + 10); +} + +template +inline cv::Point2i BoundingBoxType::bl() const { + __assert_type(); + auto boxi = this->template convert_type(); + return cv::Point2i(boxi.x1, boxi.y2); +} + +template +inline cv::Point2i BoundingBoxType::rb() const { + __assert_type(); + auto boxi = this->template convert_type(); + return cv::Point2i(boxi.x2, boxi.y2); +} + +template +inline typename BoundingBoxType::value_type +BoundingBoxType::width() const { + __assert_type(); + return (x2 - x1 + static_cast(1)); +} + +template +inline typename BoundingBoxType::value_type +BoundingBoxType::height() const { + __assert_type(); + return (y2 - y1 + static_cast(1)); +} + +template +inline typename BoundingBoxType::value_type +BoundingBoxType::area() const { + __assert_type(); + return std::abs(width() * height()); +} + +struct ObjectDetectionResult { + std::vector result_bboxes; + std::chrono::time_point< std::chrono::steady_clock > timestamp; +}; + +#endif // SUPPORT_INCLUDE_TASK_VISION_OBJECT_DETECTION_TYPES_H_ diff --git a/include/task/vision/pose_estimation_task.h b/include/task/vision/pose_estimation_task.h new file mode 100644 index 0000000..e96232f --- /dev/null +++ b/include/task/vision/pose_estimation_task.h @@ -0,0 +1,24 @@ +#ifndef SUPPORT_INCLUDE_TASK_VISION_POSE_ESTIMATION_TASK_H_ +#define SUPPORT_INCLUDE_TASK_VISION_POSE_ESTIMATION_TASK_H_ + +#include // for: shared_ptr +#include + +#include "opencv2/opencv.hpp" +#include "task/vision/object_detection_types.h" +#include "task/vision/pose_estimation_types.h" + +class poseEstimationTask { + public: + explicit poseEstimationTask(const std::string &filePath); + ~poseEstimationTask() = default; + int getInitFlag(); + PoseEstimationResult Estimate(const cv::Mat &raw_img, const Boxi &box); + + private: + class impl; + std::shared_ptr pimpl_; + int init_flag_; +}; + +#endif // SUPPORT_INCLUDE_TASK_VISION_POSE_ESTIMATION_TASK_H_ diff --git a/include/task/vision/pose_estimation_types.h b/include/task/vision/pose_estimation_types.h new file mode 100644 index 0000000..c7cc4df --- /dev/null +++ b/include/task/vision/pose_estimation_types.h @@ -0,0 +1,26 @@ +#ifndef SUPPORT_INCLUDE_TASK_VISION_POSE_ESTIMATION_TYPES_H_ +#define SUPPORT_INCLUDE_TASK_VISION_POSE_ESTIMATION_TYPES_H_ + +#include //for chrono +#include //for vector + +struct PosePoint { + int x; + int y; + float score; + + PosePoint() { + x = 0; + y = 0; + score = 0.0; + } +}; + +typedef PosePoint Vector2D; + +struct PoseEstimationResult { + std::vector result_points; + std::chrono::time_point< std::chrono::steady_clock > timestamp; +}; + +#endif // SUPPORT_INCLUDE_TASK_VISION_POSE_ESTIMATION_TYPES_H_ diff --git a/include/utils/time.h b/include/utils/time.h new file mode 100644 index 0000000..0166b0b --- /dev/null +++ b/include/utils/time.h @@ -0,0 +1,30 @@ +#ifndef SUPPORT_INCLUDE_UTILS_TIME_H_ +#define SUPPORT_INCLUDE_UTILS_TIME_H_ + +#include +#include +#include +#include + +class TimeWatcher { + public: + TimeWatcher(const std::string& name) : msg_(name) { + start_ = std::chrono::steady_clock::now(); + } + int64_t DurationWithMicroSecond() { + return std::chrono::duration_cast(end_ - start_) + .count(); + } + ~TimeWatcher() { + end_ = std::chrono::steady_clock::now(); + std::cout << msg_ << " consumes " << std::fixed << std::setprecision(0) + << DurationWithMicroSecond() << " ms" << std::endl; + } + + private: + std::string msg_; + std::chrono::steady_clock::time_point start_; + std::chrono::steady_clock::time_point end_; +}; + +#endif // SUPPORT_INCLUDE_UTILS_TIME_H_ diff --git a/include/utils/utils.h b/include/utils/utils.h new file mode 100644 index 0000000..150d40c --- /dev/null +++ b/include/utils/utils.h @@ -0,0 +1,16 @@ +#ifndef SUPPORT_INCLUDE_UTILS_UTILS_H_ +#define SUPPORT_INCLUDE_UTILS_UTILS_H_ + +#include + +#include +#include + +#include "opencv2/opencv.hpp" + +bool exists_check(const std::string &name); + +void resize_unscale(const cv::Mat &mat, cv::Mat &mat_rs, int target_height, + int target_width); + +#endif // SUPPORT_INCLUDE_UTILS_UTILS_H_ diff --git a/rootfs/etc/xdg/autostart/object-detection.desktop b/rootfs/etc/xdg/autostart/object-detection.desktop new file mode 100644 index 0000000..a85ff51 --- /dev/null +++ b/rootfs/etc/xdg/autostart/object-detection.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Type=Application +Name=object-detection +Exec=/usr/bin/bianbu-ai-autotools desktop /usr/share/applications/object-detection.desktop +Terminal=false +NoDisplay=true +StartupNotify=false \ No newline at end of file diff --git a/rootfs/etc/xdg/autostart/pose-tracker.desktop b/rootfs/etc/xdg/autostart/pose-tracker.desktop new file mode 100644 index 0000000..75567c5 --- /dev/null +++ b/rootfs/etc/xdg/autostart/pose-tracker.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Type=Application +Name=pose-tracker +Exec=/usr/bin/bianbu-ai-autotools desktop /usr/share/applications/pose-tracker.desktop +Terminal=false +NoDisplay=true +StartupNotify=false \ No newline at end of file diff --git a/rootfs/usr/bin/bianbu-ai-autotools b/rootfs/usr/bin/bianbu-ai-autotools new file mode 100755 index 0000000..a4e0392 --- /dev/null +++ b/rootfs/usr/bin/bianbu-ai-autotools @@ -0,0 +1,52 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# Copyright (c) 2023, spacemit.com, Inc. All Rights Reserved +# +# ============================================================= +# +# Author: hongjie.qin@spacemit.com +# Brief: Bianbu AI Auto Toolkit. +# + +#set -e +#set -x + +cmd=$1 +shift + +#xdg-user-dirs-update +test -f ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs && . ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs + +function auto_desktop() { + desktop=$1 + shortcut=$(basename $desktop) + if [[ ! -f ${XDG_CONFIG_HOME:-~/.config}/bianbu-ai-support/applications/${shortcut%.desktop}-initial-setup-done ]]; then + xdg-desktop-icon install --novendor ${desktop} + gio set $(xdg-user-dir DESKTOP)/${shortcut} metadata::trusted true + fi + if [[ -f $(xdg-user-dir DESKTOP)/${shortcut} ]]; then + mkdir -p ${XDG_CONFIG_HOME:-~/.config}/bianbu-ai-support/applications + touch ${XDG_CONFIG_HOME:-~/.config}/bianbu-ai-support/applications/${shortcut%.desktop}-initial-setup-done + fi +} + +if [[ $cmd =~ "desktop" ]]; then + auto_desktop $@ +fi diff --git a/rootfs/usr/share/ai-support/imgs/dog.jpg b/rootfs/usr/share/ai-support/imgs/dog.jpg new file mode 100644 index 0000000..3be4738 Binary files /dev/null and b/rootfs/usr/share/ai-support/imgs/dog.jpg differ diff --git a/rootfs/usr/share/ai-support/imgs/person.jpg b/rootfs/usr/share/ai-support/imgs/person.jpg new file mode 100644 index 0000000..61c46be Binary files /dev/null and b/rootfs/usr/share/ai-support/imgs/person.jpg differ diff --git a/rootfs/usr/share/ai-support/models/coco.txt b/rootfs/usr/share/ai-support/models/coco.txt new file mode 100644 index 0000000..1f42c8e --- /dev/null +++ b/rootfs/usr/share/ai-support/models/coco.txt @@ -0,0 +1,80 @@ +person +bicycle +car +motorcycle +airplane +bus +train +truck +boat +traffic light +fire hydrant +stop sign +parking meter +bench +bird +cat +dog +horse +sheep +cow +elephant +bear +zebra +giraffe +backpack +umbrella +handbag +tie +suitcase +frisbee +skis +snowboard +sports ball +kite +baseball bat +baseball glove +skateboard +surfboard +tennis racket +bottle +wine glass +cup +fork +knife +spoon +bowl +banana +apple +sandwich +orange +broccoli +carrot +hot dog +pizza +donut +cake +chair +couch +potted plant +bed +dining table +toilet +tv +laptop +mouse +remote +keyboard +cell phone +microwave +oven +toaster +sink +refrigerator +book +clock +vase +scissors +teddy bear +hair drier +toothbrush \ No newline at end of file diff --git a/rootfs/usr/share/ai-support/models/rtmdet-nano.q.onnx b/rootfs/usr/share/ai-support/models/rtmdet-nano.q.onnx new file mode 100644 index 0000000..d81478e Binary files /dev/null and b/rootfs/usr/share/ai-support/models/rtmdet-nano.q.onnx differ diff --git a/rootfs/usr/share/ai-support/models/rtmpose-t.q.onnx b/rootfs/usr/share/ai-support/models/rtmpose-t.q.onnx new file mode 100644 index 0000000..710ea57 Binary files /dev/null and b/rootfs/usr/share/ai-support/models/rtmpose-t.q.onnx differ diff --git a/rootfs/usr/share/ai-support/models/rtmpose.json b/rootfs/usr/share/ai-support/models/rtmpose.json new file mode 100644 index 0000000..0c83945 --- /dev/null +++ b/rootfs/usr/share/ai-support/models/rtmpose.json @@ -0,0 +1,8 @@ +{ + "name": "Rtmpose", + "instance_name": "pose-estimation-inference", + "model_path": "/usr/share/ai-support/models/rtmpose-t.q.onnx", + "label_path": "/usr/share/ai-support/models/coco.txt", + "intra_threads_num": 2, + "graph_optimization_level": "" +} \ No newline at end of file diff --git a/rootfs/usr/share/ai-support/models/yolov6.json b/rootfs/usr/share/ai-support/models/yolov6.json new file mode 100644 index 0000000..8b580e5 --- /dev/null +++ b/rootfs/usr/share/ai-support/models/yolov6.json @@ -0,0 +1,9 @@ +{ + "name": "Yolov6", + "instance_name": "object-detection-inference", + "model_path": "/usr/share/ai-support/models/yolov6p5_n.q.onnx", + "label_path": "/usr/share/ai-support/models/coco.txt", + "intra_threads_num": 2, + "graph_optimization_level": "", + "score_threshold": 0.3 +} \ No newline at end of file diff --git a/rootfs/usr/share/ai-support/models/yolov6p5_n.q.onnx b/rootfs/usr/share/ai-support/models/yolov6p5_n.q.onnx new file mode 100644 index 0000000..dea9490 Binary files /dev/null and b/rootfs/usr/share/ai-support/models/yolov6p5_n.q.onnx differ diff --git a/rootfs/usr/share/ai-support/videos/test.mp4 b/rootfs/usr/share/ai-support/videos/test.mp4 new file mode 100644 index 0000000..ad3c3e1 Binary files /dev/null and b/rootfs/usr/share/ai-support/videos/test.mp4 differ diff --git a/rootfs/usr/share/applications/object-detection.desktop b/rootfs/usr/share/applications/object-detection.desktop new file mode 100644 index 0000000..79847e6 --- /dev/null +++ b/rootfs/usr/share/applications/object-detection.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Type=Application +#Encoding=UTF-8 +Version=1.0.3 +Name=object-detection +Exec=/usr/bin/detection_stream_demo /usr/share/ai-support/models/yolov6.json 0 cameraId +Terminal=true +Icon=/usr/share/icons/bianbu-ai-demo/object-detection.png diff --git a/rootfs/usr/share/applications/pose-tracker.desktop b/rootfs/usr/share/applications/pose-tracker.desktop new file mode 100644 index 0000000..4c4b83a --- /dev/null +++ b/rootfs/usr/share/applications/pose-tracker.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Type=Application +#Encoding=UTF-8 +Version=1.0.3 +Name=pose-tracker +Exec=/usr/bin/tracker_stream_demo /usr/share/ai-support/models/yolov6.json /usr/share/ai-support/models/rtmpose.json 0 cameraId +Terminal=true +Icon=/usr/share/icons/bianbu-ai-demo/pose-tracker.png diff --git a/rootfs/usr/share/icons/bianbu-ai-demo/hand-tracker.png b/rootfs/usr/share/icons/bianbu-ai-demo/hand-tracker.png new file mode 100644 index 0000000..c6c16d0 Binary files /dev/null and b/rootfs/usr/share/icons/bianbu-ai-demo/hand-tracker.png differ diff --git a/rootfs/usr/share/icons/bianbu-ai-demo/object-detection.png b/rootfs/usr/share/icons/bianbu-ai-demo/object-detection.png new file mode 100644 index 0000000..28b12fd Binary files /dev/null and b/rootfs/usr/share/icons/bianbu-ai-demo/object-detection.png differ diff --git a/rootfs/usr/share/icons/bianbu-ai-demo/pose-tracker.png b/rootfs/usr/share/icons/bianbu-ai-demo/pose-tracker.png new file mode 100644 index 0000000..2665d0c Binary files /dev/null and b/rootfs/usr/share/icons/bianbu-ai-demo/pose-tracker.png differ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..7b865fc --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,91 @@ +file(READ ${CMAKE_SOURCE_DIR}/VERSION_NUMBER VERSION_CONTENT) +string(STRIP "${VERSION_CONTENT}" VERSION_CONTENT) +project(bianbuai-support-library VERSION ${VERSION_CONTENT}) + +set(CMAKE_CXX_STANDARD 14) +#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive") + +if (WIN32) + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) +else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror") +endif() + +# TODO: update cc files with '#ifndef NDEBUG' +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG") + +set(OPENCV_LIBS opencv_core opencv_imgproc) +# To find OpenCV, one may need to set OpenCV_DIR variable to the +# absolute path to the directory containing OpenCVConfig.cmake file. +# Otherwise, try to set OPENCV_INC and OPENCV_LIB variables via the +# command line or GUI. +if ((NOT DEFINED OPENCV_INC OR OPENCV_INC STREQUAL "") OR ((NOT DEFINED OPENCV_LIB OR OPENCV_LIB STREQUAL ""))) +find_package(OpenCV REQUIRED COMPONENTS ${OPENCV_LIBS}) +if (OpenCV_FOUND) + if (NOT DEFINED OPENCV_INC OR OPENCV_INC STREQUAL "") + set(OPENCV_INC "${OpenCV_INCLUDE_DIRS}") + endif() + if (NOT DEFINED OPENCV_LIB OR OPENCV_LIB STREQUAL "") + get_target_property(OpenCV_LIB_PATH opencv_core LOCATION) + get_filename_component(OPENCV_LIB ${OpenCV_LIB_PATH} DIRECTORY) + endif() +endif() +endif() + +# Check Required Env +if (NOT DEFINED ORT_HOME OR ORT_HOME STREQUAL "") + message(FATAL_ERROR "Env 'ORT_HOME' not defined for platform ${CMAKE_GENERATOR_PLATFORM}") +endif() +if (NOT DEFINED OPENCV_INC OR OPENCV_INC STREQUAL "") + message(FATAL_ERROR "OpenCV include dirs not found for platform ${CMAKE_GENERATOR_PLATFORM}") +endif() +if (NOT DEFINED OPENCV_LIB OR OPENCV_LIB STREQUAL "") + message(FATAL_ERROR "OpenCV library dirs not found for platform ${CMAKE_GENERATOR_PLATFORM}") +endif() + +link_directories(${OPENCV_LIB}) +link_directories(${ORT_HOME}/lib) + +file(GLOB_RECURSE SRC_FILES "./*.cpp" "./*.c" "./*.cc") +add_library(bianbuai SHARED ${SRC_FILES}) +set_target_properties(bianbuai PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}) + +if (EXISTS "${ORT_HOME}/lib/libspacemit_ep.so") + add_definitions(-DHAS_SPACEMIT_EP) + set(SPACEMITEP_LIB "spacemit_ep") +endif() + +target_include_directories(bianbuai PUBLIC ${CMAKE_SOURCE_DIR}/include) +target_include_directories(bianbuai PRIVATE ${CMAKE_SOURCE_DIR}) +target_include_directories(bianbuai SYSTEM PUBLIC ${OPENCV_INC}) +target_include_directories(bianbuai SYSTEM PRIVATE ${ORT_HOME}/include ${ORT_HOME}/include/onnxruntime) + +set(HIDE_SYMBOLS_LINKER_FLAGS "-Wl,--exclude-libs,ALL") +# Note: 'target_link_options' with 'PRIVATE' keyword would be cleaner +# but it's not available until CMake 3.13. Switch to 'target_link_options' +# once minimum CMake version is bumped up to 3.13 or above. +target_link_libraries(bianbuai PRIVATE ${HIDE_SYMBOLS_LINKER_FLAGS}) + +set(TARGET_SHARED_LINKER_FLAGS "-Wl,--as-needed") +# Note: As modern cmake suggests to give the preference to the property settings before the global ones, +# so instead of 'CMAKE_SHARED_LINKER_FLAGS' that has a global scope, the 'target_link_options' or +# 'target_link_libraries' should be used here: +#set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed") +target_link_libraries(bianbuai PRIVATE ${TARGET_SHARED_LINKER_FLAGS}) +target_link_libraries(bianbuai PRIVATE ${SPACEMITEP_LIB} onnxruntime ${OPENCV_LIBS}) + +install(TARGETS bianbuai + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) + +install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/task ${CMAKE_SOURCE_DIR}/include/utils + DESTINATION include/bianbuai + FILES_MATCHING PATTERN "*.h") + +#install(DIRECTORY ${ORT_HOME}/include ${ORT_HOME}/lib +# DESTINATION lib/3rdparty/onnxruntime +# FILES_MATCHING PATTERN "*.h" PATTERN "*onnxruntime*.so*" PATTERN "*spacemit*.so*") +#if (EXISTS "${ORT_HOME}/bin") +# install(DIRECTORY ${ORT_HOME}/bin DESTINATION lib/3rdparty/onnxruntime) +#endif() \ No newline at end of file diff --git a/src/core/engine.cc b/src/core/engine.cc new file mode 100644 index 0000000..a17b5de --- /dev/null +++ b/src/core/engine.cc @@ -0,0 +1,26 @@ +#include "src/core/engine.h" + +#ifdef _WIN32 +#include +inline std::wstring to_wstring(const std::string& input) { + std::wstring_convert> converter; + return converter.from_bytes(input); +} +#endif /* _WIN32 */ + +int Engine::Init(std::string instanceName, std::string modelFilepath) { + return ortwrapper_.Init(instanceName, +#ifdef _WIN32 + to_wstring(modelFilepath) +#else + modelFilepath +#endif /* _WIN32 */ + ); +} + +int Engine::Init(json config) { return ortwrapper_.Init(config); } + +std::vector Engine::Interpreter( + std::vector>& input_values_handler) { + return ortwrapper_.Invoke(input_values_handler); +} diff --git a/src/core/engine.h b/src/core/engine.h new file mode 100644 index 0000000..b306ae3 --- /dev/null +++ b/src/core/engine.h @@ -0,0 +1,33 @@ +#ifndef SUPPORT_SRC_CORE_ENGINE_H_ +#define SUPPORT_SRC_CORE_ENGINE_H_ + +#include +#include + +#include "opencv2/opencv.hpp" +#include "src/core/ort_wrapper.h" +#include "src/utils/json.hpp" +using json = nlohmann::json; +class Engine { + public: + Engine() { OrtWrapper ortwrapper_; } + ~Engine() {} + int Init(std::string instanceName, std::string modelFilepath); + int Init(json config); + size_t GetInputCount() { return ortwrapper_.GetInputCount(); } + size_t GetOutputCount() { return ortwrapper_.GetOutputCount(); } + std::vector> GetInputDims() { + return ortwrapper_.GetInputDims(); + } + std::vector> GetOutputDims() { + return ortwrapper_.GetOutputDims(); + } + std::vector Interpreter( + std::vector> &input_values_handler); + + protected: + private: + OrtWrapper ortwrapper_; +}; + +#endif // SUPPORT_SRC_CORE_ENGINE_H_ diff --git a/src/core/ort_wrapper.cc b/src/core/ort_wrapper.cc new file mode 100644 index 0000000..bf7e8bf --- /dev/null +++ b/src/core/ort_wrapper.cc @@ -0,0 +1,216 @@ +#include "src/core/ort_wrapper.h" + +#include // for move + +#include "utils/time.h" +#ifdef HAS_SPACEMIT_EP +#include "spacemit_ort_env.h" +#endif + +int OrtWrapper::Init(std::string instanceName, + std::basic_string modelFilepath) { + std::unique_ptr env(new Ort::Env( + OrtLoggingLevel::ORT_LOGGING_LEVEL_WARNING, instanceName.c_str())); + // Creation: The Ort::Session is created here + env_ = std::move(env); + sessionOptions_.SetIntraOpNumThreads(2); + sessionOptions_.AddConfigEntry("session.intra_op.allow_spinning", "0"); + sessionOptions_.SetInterOpNumThreads(2); + sessionOptions_.AddConfigEntry("session.inter_op.allow_spinning", "0"); +#ifdef HAS_SPACEMIT_EP + SessionOptionsSpaceMITEnvInit(sessionOptions_); + // auto providers = Ort::GetAvailableProviders(); + std::cout << "Enable spacemit ep now" << std::endl; +#else + std::cout << "Disable spacemit ep now" << std::endl; +#endif + // Sets graph optimization level + // Available levels are + // ORT_DISABLE_ALL -> To disable all optimizations + // ORT_ENABLE_BASIC -> To enable basic optimizations (Such as redundant node + // removals) ORT_ENABLE_EXTENDED -> To enable extended optimizations + // (Includes level 1 + more complex optimizations like node fusions) + // ORT_ENABLE_ALL -> To Enable All possible optimizations + // sessionOptions_.SetGraphOptimizationLevel( + // GraphOptimizationLevel::ORT_DISABLE_ALL); + std::unique_ptr session( + new Ort::Session(*env_, modelFilepath.c_str(), sessionOptions_)); + session_ = std::move(session); + return 0; +} + +int OrtWrapper::Init(json config) { + std::string instanceName; + if (config.contains("instance_name")) { + instanceName = config["instance_name"]; + } + std::basic_string modelFilepath = config["model_path"]; + std::unique_ptr env(new Ort::Env( + OrtLoggingLevel::ORT_LOGGING_LEVEL_WARNING, instanceName.c_str())); + // Creation: The Ort::Session is created here + env_ = std::move(env); + if (!config.contains("disable_spcacemit_ep") || + config["disable_spcacemit_ep"] == false) { +#ifdef HAS_SPACEMIT_EP + SessionOptionsSpaceMITEnvInit(sessionOptions_); + // auto providers = Ort::GetAvailableProviders(); + std::cout << "Enable spacemit ep now" << std::endl; +#else + std::cout << "[Warning] Unsupport spacemit ep now" << std::endl; +#endif + } else { + std::cout << "Disable spacemit ep now" << std::endl; + } + if (config.contains("intra_threads_num")) { + int intraThreadsnum = config["intra_threads_num"]; + sessionOptions_.SetIntraOpNumThreads(intraThreadsnum); + sessionOptions_.AddConfigEntry("session.intra_op.allow_spinning", "0"); + } else { + sessionOptions_.SetIntraOpNumThreads(4); + sessionOptions_.AddConfigEntry("session.intra_op.allow_spinning", "0"); + } + sessionOptions_.SetInterOpNumThreads(1); + sessionOptions_.AddConfigEntry("session.inter_op.allow_spinning", "0"); + if (config.contains("profiling_projects")) { + std::basic_string profiling_projects = + config["profiling_projects"]; + if (profiling_projects.size()) { + sessionOptions_.EnableProfiling(profiling_projects.c_str()); + } + } + if (config.contains("opt_model_path")) { + std::basic_string opt_model_path = config["opt_model_path"]; + if (opt_model_path.size()) { + sessionOptions_.SetOptimizedModelFilePath(opt_model_path.c_str()); + } + } + if (config.contains("log_level")) { + int log_level = config["log_level"]; + if (log_level >= 0 && log_level <= 4) { + sessionOptions_.SetLogSeverityLevel(log_level); + } + } + // Sets graph optimization level + // Available levels are + // ORT_DISABLE_ALL -> To disable all optimizations + // ORT_ENABLE_BASIC -> To enable basic optimizations (Such as redundant node + // removals) ORT_ENABLE_EXTENDED -> To enable extended optimizations + // (Includes level 1 + more complex optimizations like node fusions) + // ORT_ENABLE_ALL -> To Enable All possible optimizations + if (config.contains("graph_optimization_level")) { + if (config["graph_optimization_level"] == "ort_disable_all") { + sessionOptions_.SetGraphOptimizationLevel( + GraphOptimizationLevel::ORT_DISABLE_ALL); + } else if (config["graph_optimization_level"] == "ort_enable_basic") { + sessionOptions_.SetGraphOptimizationLevel( + GraphOptimizationLevel::ORT_ENABLE_BASIC); + } else if (config["graph_optimization_level"] == "ort_enable_extended") { + sessionOptions_.SetGraphOptimizationLevel( + GraphOptimizationLevel::ORT_ENABLE_EXTENDED); + } else { + sessionOptions_.SetGraphOptimizationLevel( + GraphOptimizationLevel::ORT_ENABLE_ALL); + } + } + std::unique_ptr session( + new Ort::Session(*env_, modelFilepath.c_str(), sessionOptions_)); + session_ = std::move(session); + return 0; +} + +std::vector> OrtWrapper::GetInputDims() { + size_t num_inputs = session_->GetInputCount(); + std::vector> input_node_dims; + input_node_dims.resize(num_inputs); + for (size_t i = 0; i < num_inputs; ++i) { + Ort::TypeInfo input_type_info = session_->GetInputTypeInfo(i); + auto input_tensor_info = input_type_info.GetTensorTypeAndShapeInfo(); + auto input_dims = input_tensor_info.GetShape(); + input_dims[0] = abs(input_dims[0]); + input_dims[1] = abs(input_dims[1]); + input_node_dims[i] = input_dims; + } + return input_node_dims; +} + +std::vector> OrtWrapper::GetOutputDims() { + size_t num_outputs = session_->GetOutputCount(); + std::vector> output_node_dims; + output_node_dims.resize(num_outputs); + for (size_t i = 0; i < num_outputs; ++i) { + Ort::TypeInfo output_type_info = session_->GetOutputTypeInfo(i); + auto output_tensor_info = output_type_info.GetTensorTypeAndShapeInfo(); + auto output_dims = output_tensor_info.GetShape(); + output_node_dims[i] = output_dims; + } + return output_node_dims; +} + +std::vector OrtWrapper::Invoke( + std::vector> &input_tensor_values) { +#ifdef DEBUG + TimeWatcher t("|-- Infer tensor"); +#endif + // init onnxruntime allocator. + Ort::AllocatorWithDefaultOptions allocator; + + // input names initial and build + std::vector input_node_names; + std::vector input_names; + size_t num_inputs = session_->GetInputCount(); + input_node_names.resize(num_inputs); + for (size_t i = 0; i < num_inputs; i++) { + input_names.push_back(std::string("")); + } + + for (size_t i = 0; i < num_inputs; ++i) { + auto input_name = session_->GetInputNameAllocated(i, allocator); + input_names[i].append(input_name.get()); + input_node_names[i] = input_names[i].c_str(); + } + + // input node dims and input dims + auto input_node_dims = GetInputDims(); + + // input tensor size + std::vector input_tensor_size; + input_tensor_size.resize(input_node_dims.size()); + for (size_t i = 0; i < num_inputs; ++i) { + input_tensor_size[i] = 1; + for (size_t j = 0; j < input_node_dims[i].size(); ++j) { + input_tensor_size[i] *= input_node_dims[i][j]; + } + } + + // output names initial and build + std::vector output_node_names; + std::vector output_names; + size_t num_outputs = session_->GetOutputCount(); + output_node_names.resize(num_outputs); + for (size_t i = 0; i < num_outputs; i++) { + output_names.push_back(std::string("")); + } + + for (size_t i = 0; i < num_outputs; ++i) { + auto output_name = session_->GetOutputNameAllocated(i, allocator); + output_names[i].append(output_name.get()); + output_node_names[i] = output_names[i].c_str(); + } + + // init and build input tensors + std::vector input_tensors; + Ort::MemoryInfo memoryInfo = Ort::MemoryInfo::CreateCpu( + OrtAllocatorType::OrtArenaAllocator, OrtMemType::OrtMemTypeDefault); + + for (int i = 0; i < static_cast(num_inputs); i++) { + input_tensors.push_back(Ort::Value::CreateTensor( + memoryInfo, input_tensor_values[i].data(), input_tensor_size[i], + input_node_dims[i].data(), input_node_dims[i].size())); + } + + // run model + auto outputTensors = session_->Run( + Ort::RunOptions{nullptr}, input_node_names.data(), input_tensors.data(), + num_inputs, output_node_names.data(), num_outputs); + return outputTensors; +} diff --git a/src/core/ort_wrapper.h b/src/core/ort_wrapper.h new file mode 100644 index 0000000..68adbdb --- /dev/null +++ b/src/core/ort_wrapper.h @@ -0,0 +1,37 @@ +#ifndef SUPPORT_SRC_CORE_ORT_WRAPPER_H_ +#define SUPPORT_SRC_CORE_ORT_WRAPPER_H_ + +#include +#include +#include +#include +#include +#include + +#include "onnxruntime_cxx_api.h" +#include "opencv2/opencv.hpp" +#include "src/utils/json.hpp" +using json = nlohmann::json; + +class OrtWrapper { + public: + OrtWrapper() {} + ~OrtWrapper() {} + int Init(std::string instanceName, + std::basic_string modelFilepath); + int Init(json config); + size_t GetInputCount() { return session_->GetInputCount(); } + size_t GetOutputCount() { return session_->GetOutputCount(); } + std::vector> GetInputDims(); + std::vector> GetOutputDims(); + + std::vector Invoke( + std::vector>& input_tensor_values); + + protected: + private: + std::unique_ptr env_; + Ort::SessionOptions sessionOptions_; + std::unique_ptr session_; +}; +#endif // SUPPORT_SRC_CORE_ORT_WRAPPER_H_ diff --git a/src/processor/classification_postprocessor.cc b/src/processor/classification_postprocessor.cc new file mode 100644 index 0000000..9f77bd3 --- /dev/null +++ b/src/processor/classification_postprocessor.cc @@ -0,0 +1,41 @@ +#include "src/processor/classification_postprocessor.h" + +#include // for numeric_limits<> + +#include "utils/time.h" + +float ClassificationPostprocessor::division(float num, float den) { + if (den == 0) { + throw std::runtime_error( + "[ ERROR ] Math error: Attempted to divide by Zero\n"); + } + return (num / den); +} + +ImageClassificationResult ClassificationPostprocessor::Postprocess( + std::vector output_tensors, std::vector &labels) { +#ifdef DEBUG + TimeWatcher t("|-- Postprocess"); +#endif + int predId = 0; + float activation = 0; + float maxActivation = std::numeric_limits::lowest(); + float expSum = 0; + /* The inference result could be found in the buffer for the output tensors, + which are usually the buffer from std::vector instances. */ + Ort::Value &pred = output_tensors.at(0); + const float *output_pred_ptr = pred.GetTensorData(); + for (int i = 0; i < static_cast(labels.size()); i++) { + activation = output_pred_ptr[i]; + expSum += std::exp(activation); + if (activation > maxActivation) { + predId = i; + maxActivation = activation; + } + } + ImageClassificationResult result; + result.label = predId; + result.label_text = labels.at(predId); + result.score = std::exp(maxActivation) / expSum; + return result; +} diff --git a/src/processor/classification_postprocessor.h b/src/processor/classification_postprocessor.h new file mode 100644 index 0000000..b952da2 --- /dev/null +++ b/src/processor/classification_postprocessor.h @@ -0,0 +1,26 @@ +#ifndef SUPPORT_SRC_PROCESSOR_CLASSIFICATION_POSTPROCESSOR_H_ +#define SUPPORT_SRC_PROCESSOR_CLASSIFICATION_POSTPROCESSOR_H_ + +#include +#include +#include // To use runtime_error +#include +#include + +#include "onnxruntime_cxx_api.h" +#include "src/processor/processor.h" +#include "task/vision/image_classification_types.h" + +class ClassificationPostprocessor : public Postprocessor { + public: + ClassificationPostprocessor() {} + ~ClassificationPostprocessor() {} + // Function to validate the input image file extension. + ImageClassificationResult Postprocess(std::vector output_tensors, + std::vector &labels); + + // Handling divide by zero + float division(float num, float den); +}; + +#endif // SUPPORT_SRC_PROCESSOR_CLASSIFICATION_POSTPROCESSOR_H_ diff --git a/src/processor/classification_preprocessor.cc b/src/processor/classification_preprocessor.cc new file mode 100644 index 0000000..6aba6ba --- /dev/null +++ b/src/processor/classification_preprocessor.cc @@ -0,0 +1,41 @@ +#include "src/processor/classification_preprocessor.h" + +#include "utils/time.h" + +void ClassificationPreprocessor::Preprocess( + const cv::Mat& imageBGR, std::vector> inputDims, + std::vector>& input_tensor_values) { + cv::Mat resizedImageBGR, resizedImageRGB, resizedImage, preprocessedImage; + { +#ifdef DEBUG + TimeWatcher t("| |-- Resize image"); +#endif + cv::resize(imageBGR, resizedImageBGR, + cv::Size(static_cast(inputDims[0][3]), + static_cast(inputDims[0][2])), + cv::InterpolationFlags::INTER_CUBIC); + } + + // step 3: Convert the image to HWC RGB UINT8 format. + cv::cvtColor(resizedImageBGR, resizedImageRGB, + cv::ColorConversionCodes::COLOR_BGR2RGB); + // step 4: Convert the image to HWC RGB float format by dividing each pixel by + // 255. + resizedImageRGB.convertTo(resizedImage, CV_32F, 1.0 / 255); + + // step 5: Split the RGB channels from the image. + cv::Mat channels[3]; + cv::split(resizedImage, channels); + const float mean_vals[3] = {0.485f, 0.456f, 0.406f}; + const float scale_vals[3] = {0.229f, 0.224f, 0.225f}; + + int channel = 3; + std::vector input_tensor_value; + for (int i = 0; i < channel; i++) { + channels[i] = (channels[i] - mean_vals[i]) / (scale_vals[i]); + std::vector data = std::vector(channels[i].reshape(1, 1)); + input_tensor_value.insert(input_tensor_value.end(), data.begin(), + data.end()); + } + input_tensor_values.push_back(input_tensor_value); +} diff --git a/src/processor/classification_preprocessor.h b/src/processor/classification_preprocessor.h new file mode 100644 index 0000000..cd68d53 --- /dev/null +++ b/src/processor/classification_preprocessor.h @@ -0,0 +1,22 @@ +#ifndef SUPPORT_SRC_PROCESSOR_CLASSIFICATION_PREPROCESSOR_H_ +#define SUPPORT_SRC_PROCESSOR_CLASSIFICATION_PREPROCESSOR_H_ + +#include +#include +#include +#include +#include + +#include "opencv2/opencv.hpp" +#include "src/processor/processor.h" + +class ClassificationPreprocessor : public Preprocessor { + public: + ClassificationPreprocessor() {} + ~ClassificationPreprocessor() {} + void Preprocess(const cv::Mat& imageBGR, + std::vector> inputDims, + std::vector>& input_tensor_values); +}; + +#endif // SUPPORT_SRC_PROCESSOR_CLASSIFICATION_PREPROCESSOR_H_ diff --git a/src/processor/detection_postprocessor.cc b/src/processor/detection_postprocessor.cc new file mode 100644 index 0000000..deedbaa --- /dev/null +++ b/src/processor/detection_postprocessor.cc @@ -0,0 +1,341 @@ +#include "src/processor/detection_postprocessor.h" + +#include "utils/time.h" +#include "utils/utils.h" + +void DetectionPostprocessor::Postprocess( + std::vector output_tensors, std::vector &result_boxes, + std::vector> &input_dims, int img_height, + int img_width, std::vector &labels, float score_threshold, + float iou_threshold, unsigned int topk, unsigned int nms_type) { +#ifdef DEBUG + TimeWatcher t("|-- Postprocess"); +#endif + if (score_threshold == -1.f) { + score_threshold = 0.25f; + } + if (iou_threshold == -1.f) { + iou_threshold = 0.45f; + } + int STRIDES[3] = {8, 16, 32}; + float XYSCALE[3] = {1.2f, 1.1f, 1.05f}; + int anchors[3][3][2] = {{{12, 16}, {19, 36}, {40, 28}}, + {{36, 75}, {76, 55}, {72, 146}}, + {{142, 110}, {192, 243}, {459, 401}}}; + std::vector bbox_collection; + bbox_collection.clear(); + unsigned int count = 0; + const float input_height = static_cast(input_dims[0][2]); // e.g 640 + const float input_width = static_cast(input_dims[0][1]); // e.g 640 + const float resize_ratio = + std::min(input_height / img_height, input_width / img_width); + for (int s = 0; s < static_cast(output_tensors.size()); s++) { + Ort::Value &pred = output_tensors.at(s); // batch*13*13*3*85 + auto outputInfo = pred.GetTensorTypeAndShapeInfo(); + auto pred_dims = outputInfo.GetShape(); + const auto num_classes = pred_dims.at(4) - 5; // 80 + for (auto i = 0; i < pred_dims[1]; ++i) { + for (auto j = 0; j < pred_dims[2]; ++j) { + int grid_x = j; + int grid_y = i; + for (auto k = 0; k < pred_dims[3]; ++k) { + float obj_conf = pred.At({0, i, j, k, 4}); + if (obj_conf < score_threshold) continue; // filter first. + + float cls_conf = pred.At({0, i, j, k, 5}); + unsigned int label = 0; + for (auto h = 0; h < num_classes; ++h) { + float tmp_conf = pred.At({0, i, j, k, h + 5}); + if (tmp_conf > cls_conf) { + cls_conf = tmp_conf; + label = h; + } + } + float conf = obj_conf * cls_conf; // cls_conf (0.,1.) + if (conf < score_threshold) continue; // filter + float cx = (sigmoid(pred.At({0, i, j, k, 0})) * XYSCALE[s] - + 0.5f * (XYSCALE[s] - 1) + grid_x) * + STRIDES[s]; + float cy = (sigmoid(pred.At({0, i, j, k, 1})) * XYSCALE[s] - + 0.5f * (XYSCALE[s] - 1) + grid_y) * + STRIDES[s]; + float w = exp(pred.At({0, i, j, k, 2})) * anchors[s][k][0]; + float h = exp(pred.At({0, i, j, k, 3})) * anchors[s][k][1]; + Boxf box; + float dw = (input_width - resize_ratio * img_width) / 2; + float dh = (input_height - resize_ratio * img_height) / 2; + box.x1 = (cx - w / 2.f - dw) / resize_ratio; + box.x1 = std::max(box.x1, .0f); + box.y1 = (cy - h / 2.f - dh) / resize_ratio; + box.y1 = std::max(box.y1, .0f); + box.x2 = (cx + w / 2.f - dw) / resize_ratio; + box.x2 = std::min(box.x2, static_cast(img_width - 1)); + box.y2 = (cy + h / 2.f - dh) / resize_ratio; + box.y2 = std::min(box.y2, static_cast(img_height - 1)); + box.score = conf; + box.label = label; + box.label_text = labels[label].c_str(); + box.flag = true; + bbox_collection.push_back(box); + count += 1; // limit boxes for nms. + if (count > max_nms) break; + } + } + } + } + std::vector detected_boxes; + + // 4. hard|blend|offset nms with topk. + nms(bbox_collection, detected_boxes, iou_threshold, topk, nms_type); + + int detected_boxes_num = detected_boxes.size(); + for (auto i = 0; i < static_cast(detected_boxes_num); i++) { + Boxi result_box; + result_box.x1 = static_cast(detected_boxes[i].x1); + result_box.y1 = static_cast(detected_boxes[i].y1); + result_box.x2 = static_cast(detected_boxes[i].x2); + result_box.y2 = static_cast(detected_boxes[i].y2); + result_box.label = detected_boxes[i].label; + result_box.score = detected_boxes[i].score; + result_box.label_text = detected_boxes[i].label_text; + result_box.flag = detected_boxes[i].flag; + result_boxes.push_back(result_box); + } +} + +void DetectionPostprocessor::PostprocessYolov6( + std::vector output_tensors, std::vector &result_boxes, + std::vector> &input_dims, int img_height, + int img_width, std::vector &labels, float &score_threshold) { +#ifdef DEBUG + TimeWatcher t("|-- Postprocess"); +#endif + if (score_threshold == -1.f) { + score_threshold = 0.59f; + } + std::vector bbox_collection; + bbox_collection.clear(); + const float input_height = static_cast(input_dims[0][2]); + const float input_width = static_cast(input_dims[0][3]); + const float resize_ratio = + std::min(input_height / img_height, input_width / img_width); + // Ort::Value &num_dets = output_tensors.at(0); + Ort::Value &boxes = output_tensors.at(1); + Ort::Value &scores = output_tensors.at(2); + Ort::Value &output_labels = output_tensors.at(3); + auto outputInfo = boxes.GetTensorTypeAndShapeInfo(); + auto pred_dims = outputInfo.GetShape(); + float dw = (input_width - resize_ratio * img_width) / 2; + float dh = (input_height - resize_ratio * img_height) / 2; + + auto num = pred_dims[1]; + for (auto i = 0; i < num; i++) { + Boxi result_box; + result_box.score = scores.At({0, i}); + if (result_box.score < score_threshold) { + continue; + } + result_box.x1 = + static_cast((boxes.At({0, i, 0}) - dw) / resize_ratio); + result_box.y1 = + static_cast((boxes.At({0, i, 1}) - dh) / resize_ratio); + result_box.x2 = + static_cast((boxes.At({0, i, 2}) - dw) / resize_ratio); + result_box.y2 = + static_cast((boxes.At({0, i, 3}) - dh) / resize_ratio); + if (output_labels.At({0, i}) < 0) { + continue; + } + result_box.label = output_labels.At({0, i}); + result_box.label_text = labels[result_box.label].c_str(); + result_box.flag = true; + result_boxes.push_back(result_box); + } +} + +void DetectionPostprocessor::PostprocessNanoDetPlus( + std::vector output_tensors, std::vector &result_boxes, + std::vector> &input_dims, int img_height, + int img_width, std::vector &labels, float &score_threshold, + float &nms_threshold) { +#ifdef DEBUG + TimeWatcher t("|-- Postprocess"); +#endif + if (score_threshold == -1.f) { + score_threshold = 0.4f; + } + if (nms_threshold == -1.f) { + nms_threshold = 0.5f; + } + std::vector bbox_collection; + bbox_collection.clear(); + const int cls_num = 80; + const float input_height = static_cast(input_dims[0][2]); + const float input_width = static_cast(input_dims[0][3]); + const float resize_ratio = + std::min(input_height / img_height, input_width / img_width); + Ort::Value &pred = output_tensors.at(0); + const float *output_pred_ptr = pred.GetTensorData(); + auto outputInfo = pred.GetTensorTypeAndShapeInfo(); + auto pred_dims = outputInfo.GetShape(); + std::vector hw = {40, 20, 10, 5}; + std::vector strides = {8, 16, 32, 64}; + int num = -1; + for (auto i = 0; i < 4; i++) { + for (auto y = 0; y < hw[i]; y++) { + for (auto x = 0; x < hw[i]; x++) { + num++; + int ct_x = x; + int ct_y = y; + const float *scores = output_pred_ptr + num * 112; // row ptr + float cls_conf = pred.At({0, num, 0}); + unsigned int label = 0; + for (auto h = 0; h < cls_num; h++) { + float tmp_conf = scores[h]; + if (tmp_conf > cls_conf) { + cls_conf = tmp_conf; + label = h; + } + } + if (cls_conf < score_threshold) continue; + std::vector dis_pred(4, .0); + for (int s = 0; s < 4; s++) { + float alptha = .0; + int cur_num = cls_num + s * 8; + std::vector dst(8); + for (int j = 0; j < 8; j++) { + alptha = std::max(alptha, scores[cur_num + j]); + } + float sum = .0f; + for (int j = 0; j < 8; j++) { + dst[j] = fast_exp(scores[cur_num + j] - alptha); + sum = sum + dst[j]; + } + for (int j = 0; j < 8; j++) { + dis_pred[s] = dis_pred[s] + j * (dst[j] / sum); + } + } + + Boxf box; + float dw = (input_width - resize_ratio * img_width) / 2; + float dh = (input_height - resize_ratio * img_height) / 2; + box.label = label; + box.label_text = labels[label].c_str(); + box.score = cls_conf; + box.flag = true; + box.x1 = ((ct_x - dis_pred[0]) * strides[i] - dw) / resize_ratio; + box.x1 = std::max(box.x1, .0f); + box.y1 = ((ct_y - dis_pred[1]) * strides[i] - dh) / resize_ratio; + box.y1 = std::max(box.y1, .0f); + box.x2 = ((ct_x + dis_pred[2]) * strides[i] - dw) / resize_ratio; + box.x2 = std::min(box.x2, static_cast(img_width - 1)); + box.y2 = ((ct_y + dis_pred[3]) * strides[i] - dh) / resize_ratio; + box.y2 = std::min(box.y2, static_cast(img_height - 1)); + bbox_collection.push_back(box); + } + } + } + std::vector detected_boxes; + + // 4. hard|blend|offset nms with topk. + nms(bbox_collection, detected_boxes, nms_threshold, 100, OFFSET); + + size_t detected_boxes_num = detected_boxes.size(); + for (size_t i = 0; i < detected_boxes_num; i++) { + Boxi result_box; + result_box.x1 = static_cast(detected_boxes[i].x1); + result_box.y1 = static_cast(detected_boxes[i].y1); + result_box.x2 = static_cast(detected_boxes[i].x2); + result_box.y2 = static_cast(detected_boxes[i].y2); + result_box.label = detected_boxes[i].label; + result_box.score = detected_boxes[i].score; + result_box.label_text = detected_boxes[i].label_text; + result_box.flag = detected_boxes[i].flag; + result_boxes.push_back(result_box); + } +} +void DetectionPostprocessor::PostprocessRtmDet( + std::vector output_tensors, std::vector &result_boxes, + std::vector> &input_dims, int img_height, + int img_width, std::vector &labels, float &score_threshold, + float &nms_threshold) { +#ifdef DEBUG + TimeWatcher t("|-- Postprocess"); +#endif + if (score_threshold == -1.f) { + score_threshold = 0.2f; + } + if (nms_threshold == -1.f) { + nms_threshold = 0.6f; + } + std::vector bbox_collection; + bbox_collection.clear(); + const float input_height = static_cast(input_dims[0][2]); // e.g 320 + const float input_width = static_cast(input_dims[0][3]); // e.g 320 + const float resize_ratio = + std::min(input_height / img_height, input_width / img_width); + Ort::Value &boxes = output_tensors.at(0); + Ort::Value &output_labels = output_tensors.at(1); + std::vector det_result_dims = + boxes.GetTensorTypeAndShapeInfo().GetShape(); + std::vector label_result_dims = + output_labels.GetTensorTypeAndShapeInfo().GetShape(); + + assert(det_result_dims.size() == 3 && label_result_dims.size() == 2); + int64_t num_dets = + det_result_dims[1] == label_result_dims[1] ? det_result_dims[1] : 0; + int64_t reshap_dims = det_result_dims[2]; + const float *det_result = boxes.GetTensorData(); + const int *label_result = output_labels.GetTensorData(); + float dw = (input_width - resize_ratio * img_width) / 2; + float dh = (input_height - resize_ratio * img_height) / 2; + + for (int64_t i = 0; i < num_dets; ++i) { + int classes = label_result[i]; + if (classes != 0) continue; + Boxf box; + box.flag = true; + box.score = det_result[i * reshap_dims + 4]; + if (box.score < score_threshold) continue; // filter + box.x1 = (det_result[i * reshap_dims] - dw) / resize_ratio; + box.x1 = std::max(box.x1, .0f); + box.y1 = (det_result[i * reshap_dims + 1] - dh) / resize_ratio; + box.y1 = std::max(box.y1, .0f); + box.x2 = (det_result[i * reshap_dims + 2] - dw) / resize_ratio; + box.x2 = std::min(box.x2, static_cast(img_width - 1)); + box.y2 = (det_result[i * reshap_dims + 3] - dh) / resize_ratio; + box.y2 = std::min(box.y2, static_cast(img_height - 1)); + box.label = label_result[i]; + box.label_text = labels[box.label].c_str(); + bbox_collection.push_back(box); + } + + std::vector detected_boxes; + // 4. hard|blend|offset nms with topk. + nms(bbox_collection, detected_boxes, nms_threshold, 100, OFFSET); + + size_t detected_boxes_num = detected_boxes.size(); + for (size_t i = 0; i < detected_boxes_num; i++) { + Boxi result_box; + result_box.x1 = static_cast(detected_boxes[i].x1); + result_box.y1 = static_cast(detected_boxes[i].y1); + result_box.x2 = static_cast(detected_boxes[i].x2); + result_box.y2 = static_cast(detected_boxes[i].y2); + result_box.label = detected_boxes[i].label; + result_box.score = detected_boxes[i].score; + result_box.label_text = detected_boxes[i].label_text; + result_box.flag = detected_boxes[i].flag; + result_boxes.push_back(result_box); + } +} + +void DetectionPostprocessor::nms(std::vector &input, + std::vector &output, float iou_threshold, + unsigned int topk, unsigned int nms_type) { + if (nms_type == BLEND) + blending_nms(input, output, iou_threshold, topk); + else if (nms_type == OFFSET) + offset_nms(input, output, iou_threshold, topk); + else + hard_nms(input, output, iou_threshold, topk); +} diff --git a/src/processor/detection_postprocessor.h b/src/processor/detection_postprocessor.h new file mode 100644 index 0000000..e7e8cbe --- /dev/null +++ b/src/processor/detection_postprocessor.h @@ -0,0 +1,52 @@ +#ifndef SUPPORT_SRC_PROCESSOR_DETECTION_POSTPROCESSOR_H_ +#define SUPPORT_SRC_PROCESSOR_DETECTION_POSTPROCESSOR_H_ + +#include +#include +#include +#include + +#include "onnxruntime_cxx_api.h" +#include "src/processor/processor.h" +#include "src/utils/nms_utils.h" +#include "src/utils/utils.h" +#include "task/vision/object_detection_types.h" + +class DetectionPostprocessor : public Postprocessor { + public: + DetectionPostprocessor() {} + + void Postprocess(std::vector output_tensors, + std::vector &result_boxes, + std::vector> &input_dims, + int img_height, int img_width, + std::vector &labels, float score_threshold, + float iou_threshold, unsigned int topk = 100, + unsigned int nms_type = OFFSET); + + void PostprocessYolov6(std::vector output_tensors, + std::vector &result_boxes, + std::vector> &input_dims, + int img_height, int img_width, + std::vector &labels, + float &score_threshold); + + void PostprocessNanoDetPlus(std::vector output_tensors, + std::vector &result_boxes, + std::vector> &input_dims, + int img_height, int img_width, + std::vector &labels, + float &score_threshold, float &nms_threshold); + + void PostprocessRtmDet(std::vector output_tensors, + std::vector &result_boxes, + std::vector> &input_dims, + int img_height, int img_width, + std::vector &labels, + float &score_threshold, float &nms_threshold); + + private: + void nms(std::vector &input, std::vector &output, + float iou_threshold, unsigned int topk, unsigned int nms_type); +}; +#endif // SUPPORT_SRC_PROCESSOR_DETECTION_POSTPROCESSOR_H_ diff --git a/src/processor/detection_preprocessor.cc b/src/processor/detection_preprocessor.cc new file mode 100644 index 0000000..0d8d5ac --- /dev/null +++ b/src/processor/detection_preprocessor.cc @@ -0,0 +1,125 @@ +#include "src/processor/detection_preprocessor.h" + +#include "utils/time.h" +#include "utils/utils.h" + +void DetectionPreprocessor::PreprocessNanoDetPlus( + const cv::Mat& mat, std::vector>& input_node_dims, + std::vector>& input_tensor_values) { + const int input_height = (int)input_node_dims[0][2]; + const int input_width = (int)input_node_dims[0][3]; + cv::Mat resizedImageBGR, resizedImage, preprocessedImage; + { +#ifdef DEBUG + TimeWatcher t("| |-- Resize unscale"); +#endif + if (input_height != mat.cols || input_width != mat.rows) { + resize_unscale(mat, resizedImage, input_height, input_width); + } else { + resizedImage = mat; + } + } + { +#ifdef DEBUG + TimeWatcher t("| |-- Convert to fp32"); +#endif + resizedImage.convertTo(resizedImage, CV_32F, 1.0); + } + + { +#ifdef DEBUG + TimeWatcher t("| |-- Normalize"); +#endif + cv::Mat channels[3]; + cv::split(resizedImage, channels); + const float mean_vals[3] = {103.53f, 116.28f, 123.675f}; + const float scale_vals[3] = {57.375f, 57.12f, 58.395f}; + int channel = 3; + std::vector input_tensor_value; + for (int i = 0; i < channel; i++) { + channels[i] = (channels[i] - mean_vals[i]) / (scale_vals[i]); + std::vector data = std::vector(channels[i].reshape(1, 1)); + input_tensor_value.insert(input_tensor_value.end(), data.begin(), + data.end()); + } + input_tensor_values.push_back(input_tensor_value); + } +} + +void DetectionPreprocessor::Preprocess( + const cv::Mat& mat, std::vector>& input_node_dims, + std::vector>& input_tensor_values, + unsigned int data_format) { + if (mat.empty()) return; + if (data_format == 1) { + const int input_height = static_cast(input_node_dims[0][1]); + const int input_width = static_cast(input_node_dims[0][2]); + + // resize & unscale + cv::Mat resizedImageBGR, resizedImageRGB, resizedImage, preprocessedImage; + { +#ifdef DEBUG + TimeWatcher t("| |-- Resize unscale"); +#endif + if (input_height != mat.cols || input_width != mat.rows) { + resize_unscale(mat, resizedImageBGR, input_height, input_width); + } else { + resizedImageBGR = mat; + } + } + cv::cvtColor(resizedImageBGR, resizedImageRGB, cv::COLOR_BGR2RGB); + resizedImageRGB.convertTo(resizedImage, CV_32F, 1.0 / 255); + const unsigned int target_tensor_size = 3 * input_height * input_width; + std::vector input_tensor_value; + input_tensor_value.resize(target_tensor_size); + std::memcpy(input_tensor_value.data(), resizedImage.data, + target_tensor_size * sizeof(float)); + input_tensor_values.push_back(input_tensor_value); + } else { + const int input_height = static_cast(input_node_dims[0][2]); + const int input_width = static_cast(input_node_dims[0][3]); + + cv::Mat resizedImageBGR, resizedImageRGB, resizedImage, preprocessedImage; + { +#ifdef DEBUG + TimeWatcher t("| |-- Resize unscale"); +#endif + if (input_height != mat.cols || input_width != mat.rows) { + resize_unscale(mat, resizedImageBGR, input_height, input_width); + } else { + resizedImageBGR = mat; + } + } + { +#ifdef DEBUG + TimeWatcher t("| |-- Convert to RGB"); +#endif + // step 3: Convert the image to HWC RGB UINT8 format. + cv::cvtColor(resizedImageBGR, resizedImageRGB, cv::COLOR_BGR2RGB); + } + { +#ifdef DEBUG + TimeWatcher t("| |-- Convert to fp32"); +#endif + resizedImageRGB.convertTo(resizedImage, CV_32F, 1.0 / 255); + } + { +#ifdef DEBUG + TimeWatcher t("| |-- Normalize"); +#endif + cv::Mat channels[3]; + cv::split(resizedImage, channels); + // const float mean_vals[3] = {116.28f, 116.28f, 116.28f}; + // const float scale_vals[3] = {0.017429f, 0.017429f, 0.017429f}; + int channel = 3; + std::vector input_tensor_value; + for (int i = 0; i < channel; i++) { + // channels[i] = (channels[i] - mean_vals[i]) * scale_vals[i]; + std::vector data = std::vector(channels[i].reshape(1, 1)); + input_tensor_value.insert(input_tensor_value.end(), data.begin(), + data.end()); + } + input_tensor_values.push_back(input_tensor_value); + } + } +} diff --git a/src/processor/detection_preprocessor.h b/src/processor/detection_preprocessor.h new file mode 100644 index 0000000..5cbad26 --- /dev/null +++ b/src/processor/detection_preprocessor.h @@ -0,0 +1,27 @@ +#ifndef SUPPORT_SRC_PROCESSOR_DETECTION_PREPROCESSOR_H_ +#define SUPPORT_SRC_PROCESSOR_DETECTION_PREPROCESSOR_H_ + +#include +#include +#include + +#include "opencv2/opencv.hpp" +#include "src/processor/processor.h" +#include "src/utils/cv2_utils.h" +#include "src/utils/nms_utils.h" + +class DetectionPreprocessor : public Preprocessor { + public: + DetectionPreprocessor() {} + ~DetectionPreprocessor() {} + // Function to validate the input image file extension. + void Preprocess(const cv::Mat& mat, + std::vector>& input_node_dims, + std::vector>& input_tensor_values, + unsigned int data_format); + void PreprocessNanoDetPlus( + const cv::Mat& mat, std::vector>& input_node_dims, + std::vector>& input_tensor_values); +}; + +#endif // SUPPORT_SRC_PROCESSOR_DETECTION_PREPROCESSOR_H_ diff --git a/src/processor/estimation_postprocessor.cc b/src/processor/estimation_postprocessor.cc new file mode 100644 index 0000000..948136b --- /dev/null +++ b/src/processor/estimation_postprocessor.cc @@ -0,0 +1,73 @@ +#include "src/processor/estimation_postprocessor.h" + +#include "utils/time.h" + +void EstimationPostprocessor::Postprocess( + std::vector output_tensors, + std::pair crop_result_pair, + std::vector &result_points) { +#ifdef DEBUG + TimeWatcher t("|-- Postprocess"); +#endif + std::vector simcc_x_dims = + output_tensors[0].GetTensorTypeAndShapeInfo().GetShape(); + std::vector simcc_y_dims = + output_tensors[1].GetTensorTypeAndShapeInfo().GetShape(); + + assert(simcc_x_dims.size() == 3 && simcc_y_dims.size() == 3); + + // int batch_size = simcc_x_dims[0] == simcc_y_dims[0] ? simcc_x_dims[0] : 0; + int joint_num = simcc_x_dims[1] == simcc_y_dims[1] ? simcc_x_dims[1] : 0; + int extend_width = simcc_x_dims[2]; + int extend_height = simcc_y_dims[2]; + + float *simcc_x_result = output_tensors[0].GetTensorMutableData(); + float *simcc_y_result = output_tensors[1].GetTensorMutableData(); + + for (int i = 0; i < joint_num; ++i) { + // find the maximum and maximum indexes in the value of each Extend_width + // length + auto x_biggest_iter = + std::max_element(simcc_x_result + i * extend_width, + simcc_x_result + i * extend_width + extend_width); + int max_x_pos = + std::distance(simcc_x_result + i * extend_width, x_biggest_iter); + int pose_x = max_x_pos / 2; + float score_x = *x_biggest_iter; + + // find the maximum and maximum indexes in the value of each exten_height + // length + auto y_biggest_iter = + std::max_element(simcc_y_result + i * extend_height, + simcc_y_result + i * extend_height + extend_height); + int max_y_pos = + std::distance(simcc_y_result + i * extend_height, y_biggest_iter); + int pose_y = max_y_pos / 2; + float score_y = *y_biggest_iter; + + // float score = (score_x + score_y) / 2; + float score = std::max(score_x, score_y); + + PosePoint temp_point; + temp_point.x = static_cast(pose_x); + temp_point.y = static_cast(pose_y); + temp_point.score = score; + result_points.emplace_back(temp_point); + // char index[8]; + // sprintf(index, "%d", i); + // cv::putText(input_mat_copy_rgb, index, cv::Point(pose_result[i].x, + // pose_result[i].y), 1, 1, cv::Scalar{ 0, 0, 255 }, 1); + } + // cv::imwrite("pose.jpg", input_mat_copy_rgb); + // anti affine transformation to obtain the coordinates on the original + // picture + cv::Mat affine_transform_reverse = crop_result_pair.second; + for (int i = 0; i < static_cast(result_points.size()); ++i) { + cv::Mat origin_point_Mat = cv::Mat::ones(3, 1, CV_64FC1); + origin_point_Mat.at(0, 0) = result_points[i].x; + origin_point_Mat.at(1, 0) = result_points[i].y; + cv::Mat temp_result_mat = affine_transform_reverse * origin_point_Mat; + result_points[i].x = temp_result_mat.at(0, 0); + result_points[i].y = temp_result_mat.at(1, 0); + } +} diff --git a/src/processor/estimation_postprocessor.h b/src/processor/estimation_postprocessor.h new file mode 100644 index 0000000..68129de --- /dev/null +++ b/src/processor/estimation_postprocessor.h @@ -0,0 +1,23 @@ +#ifndef SUPPORT_SRC_PROCESSOR_ESTIMATION_POSTPROCESSOR_H_ +#define SUPPORT_SRC_PROCESSOR_ESTIMATION_POSTPROCESSOR_H_ + +#include +#include +#include +#include + +#include "onnxruntime_cxx_api.h" +#include "src/processor/processor.h" +#include "src/utils/nms_utils.h" +#include "src/utils/utils.h" +#include "task/vision/pose_estimation_types.h" + +class EstimationPostprocessor : public Postprocessor { + public: + EstimationPostprocessor() {} + void Postprocess(std::vector output_tensors, + std::pair crop_result_pair, + std::vector &result_points); +}; + +#endif // SUPPORT_SRC_PROCESSOR_ESTIMATION_POSTPROCESSOR_H_ diff --git a/src/processor/estimation_preprocessor.cc b/src/processor/estimation_preprocessor.cc new file mode 100644 index 0000000..897b401 --- /dev/null +++ b/src/processor/estimation_preprocessor.cc @@ -0,0 +1,106 @@ +#include "src/processor/estimation_preprocessor.h" + +#include "src/utils/cv2_utils.h" +#include "src/utils/nms_utils.h" +#include "utils/time.h" +#include "utils/utils.h" + +void EstimationPreprocessor::Preprocess( + const cv::Mat& mat, const Boxi& box, + std::vector>& input_tensor_values, + std::pair& crop_result_pair, unsigned int data_format) { + if (mat.empty()) return; + if (data_format == 0) { + // const int input_height = input_node_dims[0][2]; + // const int input_width = input_node_dims[0][3]; + crop_result_pair = CropImageByDetectBox(mat, box); + + cv::Mat crop_matBGR = crop_result_pair.first; + cv::Mat affine_transform_reverse = crop_result_pair.second; + cv::Mat crop_mat, crop_matRGB; + + { +#ifdef DEBUG + TimeWatcher t("| |-- Convert to RGB"); +#endif + // step 3: Convert the image to HWC RGB UINT8 format. + cv::cvtColor(crop_matBGR, crop_matRGB, cv::COLOR_BGR2RGB); + } + { +#ifdef DEBUG + TimeWatcher t("| |-- Convert to fp32"); +#endif + crop_matRGB.convertTo(crop_mat, CV_32F, 1.0 / 255); + } + { +#ifdef DEBUG + TimeWatcher t("| |-- Normalize"); +#endif + cv::Mat channels[3]; + cv::split(crop_mat, channels); + int channel = 3; + std::vector input_tensor_value; + for (int i = 0; i < channel; i++) { + // channels[i] = (channels[i] - mean_vals[i]) * scale_vals[i]; + std::vector data = std::vector(channels[i].reshape(1, 1)); + input_tensor_value.insert(input_tensor_value.end(), data.begin(), + data.end()); + } + input_tensor_values.push_back(input_tensor_value); + } + } +} + +std::pair EstimationPreprocessor::CropImageByDetectBox( + const cv::Mat& input_image, const Boxi& box) { + // auto time_start = std::chrono::steady_clock::now(); + std::pair result_pair; + + if (!input_image.data) { + return result_pair; + } + + if (!box.flag) { + return result_pair; + } + + // deep copy + cv::Mat input_mat_copy; + input_image.copyTo(input_mat_copy); + + // calculate the width, height and center points of the human detection box + int box_width = box.x2 - box.x1; + int box_height = box.y2 - box.y1; + int box_center_x = box.x1 + box_width / 2; + int box_center_y = box.y1 + box_height / 2; + + float aspect_ratio = 192.0 / 256.0; + + // adjust the width and height ratio of the size of the picture in the RTMPOSE + // input + if (box_width > (aspect_ratio * box_height)) { + box_height = box_width / aspect_ratio; + } else if (box_width < (aspect_ratio * box_height)) { + box_width = box_height * aspect_ratio; + } + + float scale_image_width = box_width * 1.3; + float scale_image_height = box_height * 1.3; + + // get the affine matrix + cv::Mat affine_transform = + GetAffineTransform(box_center_x, box_center_y, scale_image_width, + scale_image_height, 192, 256); + + cv::Mat affine_transform_reverse = + GetAffineTransform(box_center_x, box_center_y, scale_image_width, + scale_image_height, 192, 256, true); + + // affine transform + cv::Mat affine_image; + cv::warpAffine(input_mat_copy, affine_image, affine_transform, + cv::Size(192, 256), cv::INTER_LINEAR); + + result_pair = std::make_pair(affine_image, affine_transform_reverse); + return result_pair; +} diff --git a/src/processor/estimation_preprocessor.h b/src/processor/estimation_preprocessor.h new file mode 100644 index 0000000..65ac43a --- /dev/null +++ b/src/processor/estimation_preprocessor.h @@ -0,0 +1,28 @@ +#ifndef SUPPORT_SRC_PROCESSOR_ESTIMATION_PREPROCESSOR_H_ +#define SUPPORT_SRC_PROCESSOR_ESTIMATION_PREPROCESSOR_H_ + +#include +#include +#include +#include + +#include "opencv2/opencv.hpp" +#include "src/processor/processor.h" +#include "task/vision/object_detection_types.h" + +class EstimationPreprocessor : public Preprocessor { + public: + EstimationPreprocessor() {} + ~EstimationPreprocessor() {} + // Function to validate the input image file extension. + void Preprocess(const cv::Mat& mat, const Boxi& box, + std::vector>& input_tensor_values, + std::pair& crop_result_pair, + unsigned int data_format); + + protected: + std::pair CropImageByDetectBox(const cv::Mat& input_image, + const Boxi& box); +}; + +#endif // SUPPORT_SRC_PROCESSOR_ESTIMATION_PREPROCESSOR_H_ diff --git a/src/processor/processor.h b/src/processor/processor.h new file mode 100644 index 0000000..250dc31 --- /dev/null +++ b/src/processor/processor.h @@ -0,0 +1,24 @@ +#ifndef SUPPORT_SRC_PROCESSOR_PROCESSOR_H_ +#define SUPPORT_SRC_PROCESSOR_PROCESSOR_H_ + +class Processor { + public: + Processor() = default; + virtual ~Processor() = default; + + // Processor is neither copyable nor movable. + Processor(const Processor&) = delete; + Processor& operator=(const Processor&) = delete; +}; + +class Preprocessor : public Processor { + protected: + using Processor::Processor; +}; + +class Postprocessor : public Processor { + protected: + using Processor::Processor; +}; + +#endif // SUPPORT_SRC_PROCESSOR_PROCESSOR_H_ diff --git a/src/task/core/base_task_api.h b/src/task/core/base_task_api.h new file mode 100644 index 0000000..7ea46ce --- /dev/null +++ b/src/task/core/base_task_api.h @@ -0,0 +1,46 @@ +#ifndef SUPPORT_SRC_TASK_CORE_BASE_TASK_API_H_ +#define SUPPORT_SRC_TASK_CORE_BASE_TASK_API_H_ + +#include +#include + +#include "onnxruntime_cxx_api.h" +#include "opencv2/opencv.hpp" +#include "src/core/engine.h" + +class BaseUntypedTaskApi { + public: + BaseUntypedTaskApi() { engine_ = std::unique_ptr(new Engine()); } + virtual ~BaseUntypedTaskApi() = default; + + protected: + Engine* GetEngine() { return engine_.get(); } + std::unique_ptr engine_; +}; + +template +class BaseTaskApi : public BaseUntypedTaskApi { + public: + BaseTaskApi() : BaseUntypedTaskApi() {} + ~BaseTaskApi() {} + // BaseTaskApi is neither copyable nor movable. + BaseTaskApi(const BaseTaskApi&) = delete; + BaseTaskApi& operator=(const BaseTaskApi&) = delete; + std::vector> GetInputShape() { + return GetEngine()->GetInputDims(); + } + void Cancel() {} + + protected: + // Subclasses need to populate input_tensors from api_inputs. + virtual void Preprocess(InputTypes... api_inputs) = 0; + // Subclasses need to construct OutputType object from output_tensors. + // Original inputs are also provided as they may be needed. + virtual OutputType Postprocess() = 0; + std::vector Infer( + std::vector>& input_tensors) { + return GetEngine()->Interpreter(input_tensors); + } +}; + +#endif // SUPPORT_SRC_TASK_CORE_BASE_TASK_API_H_ diff --git a/src/task/vision/base_vision_task_api.h b/src/task/vision/base_vision_task_api.h new file mode 100644 index 0000000..0c4cffb --- /dev/null +++ b/src/task/vision/base_vision_task_api.h @@ -0,0 +1,24 @@ +#ifndef _BASE_VISION_TASK_API_H_ +#define _BASE_VISION_TASK_API_H_ + +#include +#include + +#include "opencv2/opencv.hpp" +#include "src/task/core/base_task_api.h" +#include "task/vision/object_detection_types.h" + +template +class BaseVisionTaskApi : public BaseTaskApi { + public: + BaseVisionTaskApi() : BaseTaskApi() {} + ~BaseVisionTaskApi() {} + // BaseVisionTaskApi is neither copyable nor movable. + BaseVisionTaskApi(const BaseVisionTaskApi&) = delete; + BaseVisionTaskApi& operator=(const BaseVisionTaskApi&) = delete; + + protected: + virtual void Preprocess(const cv::Mat& img_raw) = 0; +}; + +#endif diff --git a/src/task/vision/imageclassification/image_classification.cc b/src/task/vision/imageclassification/image_classification.cc new file mode 100644 index 0000000..f0d5353 --- /dev/null +++ b/src/task/vision/imageclassification/image_classification.cc @@ -0,0 +1,41 @@ +#include "src/task/vision/imageclassification/image_classification.h" + +#include "utils/time.h" + +int imageClassification::Init(const std::string modelFilepath, + const std::string labelFilepath) { + instanceName_ = "image-classification-inference"; + modelFilepath_ = modelFilepath; + labelFilepath_ = labelFilepath; + labels_ = readLabels(labelFilepath_); + initFlag_ = GetEngine()->Init(instanceName_, modelFilepath_); + return initFlag_; +} + +void imageClassification::Preprocess(const cv::Mat &img_raw) { + auto input_dims = GetInputShape(); + preprocessor_.Preprocess(img_raw, input_dims, input_tensors_); +} + +ImageClassificationResult imageClassification::Postprocess() { + return postprocessor_.Postprocess(Infer(input_tensors_), labels_); +} + +ImageClassificationResult imageClassification::Classify( + const cv::Mat &img_raw) { + if (initFlag_ != 0) { + std::cout << "[ ERROR ] Init fail return empty result" << std::endl; + ImageClassificationResult empty_result{"", -1, .0f}; + return empty_result; + } else { + img_raw_ = img_raw; + { +#ifdef DEBUG + std::cout << "|-- Preprocess" << std::endl; + TimeWatcher t("|--"); +#endif + Preprocess(img_raw_); + } + return Postprocess(); + } +} diff --git a/src/task/vision/imageclassification/image_classification.h b/src/task/vision/imageclassification/image_classification.h new file mode 100644 index 0000000..2ae9cc0 --- /dev/null +++ b/src/task/vision/imageclassification/image_classification.h @@ -0,0 +1,49 @@ +#ifndef SUPPORT_SRC_TASK_VISION_IMAGECLASSIFICATION_IMAGE_CLASSIFICATION_H_ +#define SUPPORT_SRC_TASK_VISION_IMAGECLASSIFICATION_IMAGE_CLASSIFICATION_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "opencv2/opencv.hpp" +#include "src/core/engine.h" +#include "src/processor/classification_postprocessor.h" +#include "src/processor/classification_preprocessor.h" +#include "src/task/vision/base_vision_task_api.h" +#include "src/utils/utils.h" +#include "task/vision/image_classification_types.h" + +class imageClassification + : public BaseVisionTaskApi { + public: + imageClassification() : BaseVisionTaskApi() { + initFlag_ = -1; + } + ~imageClassification() {} + int Init(const std::string modelFilepath, const std::string labelFilepath); + ImageClassificationResult Classify(const cv::Mat& img_raw); + + protected: + void Preprocess(const cv::Mat& img_raw) override; + ImageClassificationResult Postprocess() override; + + private: + ClassificationPreprocessor preprocessor_; + ClassificationPostprocessor postprocessor_; + std::string instanceName_; + std::string modelFilepath_; + cv::Mat img_raw_; + std::string labelFilepath_; + std::vector labels_; + std::vector output_tensors_; + std::vector> input_tensors_; + int initFlag_ = false; +}; + +#endif // SUPPORT_SRC_TASK_VISION_IMAGECLASSIFICATION_IMAGE_CLASSIFICATION_H_ diff --git a/src/task/vision/imageclassification/image_classification_task.cc b/src/task/vision/imageclassification/image_classification_task.cc new file mode 100644 index 0000000..1d7d457 --- /dev/null +++ b/src/task/vision/imageclassification/image_classification_task.cc @@ -0,0 +1,42 @@ +#include "task/vision/image_classification_task.h" + +#include "include/utils/utils.h" +#include "src/task/vision/imageclassification/image_classification.h" +#include "src/utils/utils.h" + +class imageClassificationTask::impl { + public: + std::unique_ptr imageclassification_; +}; + +imageClassificationTask::imageClassificationTask( + const std::string& filePath, const std::string& labelFilepath) + : pimpl_(std::make_unique()) { + pimpl_->imageclassification_ = + std::unique_ptr(new imageClassification()); + if (!checkLabelFileExtension(labelFilepath)) { + std::cout << "[ ERROR ] The LabelFilepath is not set correctly and the " + "labels file should end with extension .txt" + << std::endl; + } else if (!checkModelFileExtension(filePath)) { + std::cout << "[ ERROR ] The ModelFilepath is not correct. Make sure you " + "are setting the path to an onnx model file (.onnx)" + << std::endl; + } else if (!exists_check(filePath) || !exists_check(labelFilepath)) { + std::cout << "[ ERROR ] The File does not exist. Make sure you are setting " + "the correct path to the file" + << std::endl; + } else { + init_flag_ = pimpl_->imageclassification_->Init(filePath, labelFilepath); + if (init_flag_ != 0) { + std::cout << "[Error] Init fail" << std::endl; + } + } +} + +int imageClassificationTask::getInitFlag() { return init_flag_; } + +ImageClassificationResult imageClassificationTask::Classify( + const cv::Mat& img_raw) { + return pimpl_->imageclassification_->Classify(img_raw); +} diff --git a/src/task/vision/objectdetection/object_detection.cc b/src/task/vision/objectdetection/object_detection.cc new file mode 100644 index 0000000..f4f5318 --- /dev/null +++ b/src/task/vision/objectdetection/object_detection.cc @@ -0,0 +1,194 @@ +#include "src/task/vision/objectdetection/object_detection.h" + +#include +#include + +#include "src/utils/json.hpp" +#include "utils/time.h" +using json = nlohmann::json; + +std::vector> ObjectDetection::Process( + const cv::Mat &raw_img) { + input_tensors_.clear(); + if (initFlag_ != 0) { + std::cout << "[ ERROR ] Init fail return empty tensors" << std::endl; + return input_tensors_; + } + if (modelFilepath_.find("yolov4") != modelFilepath_.npos) { + preprocessor_.Preprocess(raw_img, inputDims_, input_tensors_, HWC); + } else if (modelFilepath_.find("yolov6") != modelFilepath_.npos) { + preprocessor_.Preprocess(raw_img, inputDims_, input_tensors_, CHW); + } else if (modelFilepath_.find("nanodet-plus") != modelFilepath_.npos) { + preprocessor_.PreprocessNanoDetPlus(raw_img, inputDims_, input_tensors_); + } else if (modelFilepath_.find("rtmdet") != modelFilepath_.npos) { + preprocessor_.Preprocess(raw_img, inputDims_, input_tensors_, CHW); + } else { + std::cout << "[ ERROR ] Unsupported model return empty tensors" + << std::endl; + return input_tensors_; + } + return input_tensors_; +} + +ObjectDetectionResult ObjectDetection::Detect(const cv::Mat &raw_img) { + result_boxes_.clear(); + input_tensors_.clear(); + Preprocess(raw_img); + return Postprocess(); +} + +ObjectDetectionResult ObjectDetection::Detect( + const std::vector> &input_tensors, const int img_height, + const int img_width) { + result_boxes_.clear(); + input_tensors_ = input_tensors; + if (initFlag_ != 0) { + std::cout << "[ ERROR ] Init fail return empty result" << std::endl; + result_.result_bboxes = result_boxes_; + result_.timestamp = std::chrono::steady_clock::now(); + return result_; + } + if (modelFilepath_.find("yolov4") != modelFilepath_.npos) { + postprocessor_.Postprocess(Infer(input_tensors_), result_boxes_, inputDims_, + img_height, img_width, labels_, score_threshold_, + nms_threshold_); + } else if (modelFilepath_.find("yolov6") != modelFilepath_.npos) { + postprocessor_.PostprocessYolov6(Infer(input_tensors_), result_boxes_, + inputDims_, img_height, img_width, labels_, + score_threshold_); + } else if (modelFilepath_.find("nanodet-plus") != modelFilepath_.npos) { + postprocessor_.PostprocessNanoDetPlus( + Infer(input_tensors_), result_boxes_, inputDims_, img_height, img_width, + labels_, score_threshold_, nms_threshold_); + } else if (modelFilepath_.find("rtmdet") != modelFilepath_.npos) { + postprocessor_.PostprocessRtmDet(Infer(input_tensors_), result_boxes_, + inputDims_, img_height, img_width, labels_, + score_threshold_, nms_threshold_); + } else { + std::cout << "[ ERROR ] Unsupported model return empty result" << std::endl; + } + result_.result_bboxes = result_boxes_; + result_.timestamp = std::chrono::steady_clock::now(); + return result_; +} + +void ObjectDetection::Preprocess(const cv::Mat &raw_img) { + if (initFlag_ != 0) { + std::cout << "[ ERROR ] Init fail" << std::endl; + return; + } + img_height_ = raw_img.rows; + img_width_ = raw_img.cols; + if (modelFilepath_.find("yolov4") != modelFilepath_.npos) { + preprocessor_.Preprocess(raw_img, inputDims_, input_tensors_, HWC); + } else if (modelFilepath_.find("yolov6") != modelFilepath_.npos) { + preprocessor_.Preprocess(raw_img, inputDims_, input_tensors_, CHW); + } else if (modelFilepath_.find("nanodet-plus") != modelFilepath_.npos) { + preprocessor_.PreprocessNanoDetPlus(raw_img, inputDims_, input_tensors_); + } else if (modelFilepath_.find("rtmdet") != modelFilepath_.npos) { + preprocessor_.Preprocess(raw_img, inputDims_, input_tensors_, CHW); + } else { + std::cout << "[ ERROR ] Unsupported model" << std::endl; + } +} + +ObjectDetectionResult ObjectDetection::Postprocess() { + if (initFlag_ != 0) { + std::cout << "[ ERROR ] Init fail return empty result" << std::endl; + result_.result_bboxes = result_boxes_; + result_.timestamp = std::chrono::steady_clock::now(); + return result_; + } + if (modelFilepath_.find("yolov4") != modelFilepath_.npos) { + postprocessor_.Postprocess(Infer(input_tensors_), result_boxes_, inputDims_, + img_height_, img_width_, labels_, + score_threshold_, nms_threshold_); + } else if (modelFilepath_.find("yolov6") != modelFilepath_.npos) { + postprocessor_.PostprocessYolov6(Infer(input_tensors_), result_boxes_, + inputDims_, img_height_, img_width_, + labels_, score_threshold_); + } else if (modelFilepath_.find("nanodet-plus") != modelFilepath_.npos) { + postprocessor_.PostprocessNanoDetPlus( + Infer(input_tensors_), result_boxes_, inputDims_, img_height_, + img_width_, labels_, score_threshold_, nms_threshold_); + } else if (modelFilepath_.find("rtmdet") != modelFilepath_.npos) { + postprocessor_.PostprocessRtmDet(Infer(input_tensors_), result_boxes_, + inputDims_, img_height_, img_width_, + labels_, score_threshold_, nms_threshold_); + } else { + std::cout << "[ ERROR ] Unsupported model return empty result" << std::endl; + } + if (!class_name_blacklist_.empty()) { + for (int i = 0; i < static_cast(class_name_blacklist_.size()); i++) { + for (int j = 0; j < static_cast(result_boxes_.size()); j++) { + if (class_name_blacklist_[i] == + static_cast(result_boxes_[j].label)) { + result_boxes_[j].flag = false; + } + } + } + } + if (!class_name_whitelist_.empty()) { + for (int j = 0; j < static_cast(result_boxes_.size()); j++) { + result_boxes_[j].flag = false; + } + for (int i = 0; i < static_cast(class_name_whitelist_.size()); i++) { + for (int j = 0; j < static_cast(result_boxes_.size()); j++) { + if (class_name_whitelist_[i] == + static_cast(result_boxes_[j].label)) { + result_boxes_[j].flag = true; + } + } + } + } + result_.result_bboxes = result_boxes_; + result_.timestamp = std::chrono::steady_clock::now(); + return result_; +} + +int ObjectDetection::InitFromCommand(const std::string &modelFilepath, + const std::string &labelFilepath) { + instanceName_ = "object-detection-inference"; + modelFilepath_ = modelFilepath; + labelFilepath_ = labelFilepath; + score_threshold_ = -1.f; + nms_threshold_ = -1.f; + initFlag_ = GetEngine()->Init(instanceName_, modelFilepath_); + inputDims_ = GetEngine()->GetInputDims(); + labels_ = readLabels(labelFilepath_); + return initFlag_; +} + +int ObjectDetection::InitFromConfig(const std::string &configFilepath) { + std::ifstream f(configFilepath); + json config = json::parse(f); + if (configCheck(config)) { + initFlag_ = 1; + std::cout << "[ ERROR ] Config check fail" << std::endl; + return initFlag_; + } + modelFilepath_ = config["model_path"]; + labelFilepath_ = config["label_path"]; + if (config.contains("score_threshold")) { + score_threshold_ = config["score_threshold"]; + } else { + score_threshold_ = -1.f; + } + if (config.contains("nms_threshold")) { + nms_threshold_ = config["nms_threshold"]; + } else { + nms_threshold_ = -1.f; + } + if (config.contains("class_name_whitelist")) { + class_name_whitelist_ = + config["class_name_whitelist"].get>(); + } + if (config.contains("class_name_blacklist")) { + class_name_blacklist_ = + config["class_name_blacklist"].get>(); + } + labels_ = readLabels(labelFilepath_); + initFlag_ = GetEngine()->Init(config); + inputDims_ = GetEngine()->GetInputDims(); + return initFlag_; +} diff --git a/src/task/vision/objectdetection/object_detection.h b/src/task/vision/objectdetection/object_detection.h new file mode 100644 index 0000000..e3b5478 --- /dev/null +++ b/src/task/vision/objectdetection/object_detection.h @@ -0,0 +1,55 @@ +#ifndef SUPPORT_SRC_TASK_VISION_OBJECTDETECTION_OBJECT_DETECTION_H_ +#define SUPPORT_SRC_TASK_VISION_OBJECTDETECTION_OBJECT_DETECTION_H_ + +#include +#include +#include + +#include "opencv2/opencv.hpp" +#include "src/core/engine.h" +#include "src/processor/detection_postprocessor.h" +#include "src/processor/detection_preprocessor.h" +#include "src/task/vision/base_vision_task_api.h" +#include "src/utils/utils.h" +#include "task/vision/object_detection_types.h" + +class ObjectDetection : public BaseVisionTaskApi { + public: + ObjectDetection() : BaseVisionTaskApi() { + initFlag_ = -1; + } + ~ObjectDetection() {} + ObjectDetectionResult Detect(const cv::Mat &raw_img); + int InitFromCommand(const std::string &modelFilepath, + const std::string &labelFilepath); + int InitFromConfig(const std::string &configFilepath); + std::vector> Process(const cv::Mat &raw_img); + ObjectDetectionResult Detect( + const std::vector> &input_tensors, + const int img_height, const int img_width); + + protected: + void Preprocess(const cv::Mat &raw_img) override; + ObjectDetectionResult Postprocess() override; + + private: + std::string instanceName_; + std::string modelFilepath_; + std::string labelFilepath_; + std::vector labels_; + std::vector> inputDims_; + std::vector> input_tensors_; + DetectionPreprocessor preprocessor_; + DetectionPostprocessor postprocessor_; + std::vector result_boxes_; + ObjectDetectionResult result_; + int img_height_; + int img_width_; + int initFlag_; + float score_threshold_; + float nms_threshold_; + std::vector class_name_whitelist_; + std::vector class_name_blacklist_; +}; + +#endif // SUPPORT_SRC_TASK_VISION_OBJECTDETECTION_OBJECT_DETECTION_H_ diff --git a/src/task/vision/objectdetection/object_detection_task.cc b/src/task/vision/objectdetection/object_detection_task.cc new file mode 100644 index 0000000..a755a18 --- /dev/null +++ b/src/task/vision/objectdetection/object_detection_task.cc @@ -0,0 +1,108 @@ +#include "task/vision/object_detection_task.h" + +#include "include/utils/utils.h" +#include "src/task/vision/objectdetection/object_detection.h" +#include "src/utils/utils.h" + +class objectDetectionTask::impl { + public: + std::unique_ptr objectdetection_; +}; + +objectDetectionTask::objectDetectionTask(const std::string &filePath, + const std::string &labelFilepath) + : pimpl_(std::make_unique()) { + init_flag_ = -1; + pimpl_->objectdetection_ = + std::unique_ptr(new ObjectDetection()); + if (!checkLabelFileExtension(labelFilepath)) { + std::cout << "[ ERROR ] The LabelFilepath is not set correctly and the " + "labels file should end with extension .txt" + << std::endl; + } else if (filePath.length() > 4) { + std::string suffixStr = filePath.substr(filePath.length() - 4, 4); + if (strcmp(suffixStr.c_str(), "onnx") == 0) { + if (!checkModelFileExtension(filePath)) { + std::cout << "[ ERROR ] The ModelFilepath is not correct. Make sure " + "you are setting the path to an onnx model file (.onnx)" + << std::endl; + } else if (!exists_check(filePath) || !exists_check(labelFilepath)) { + std::cout << "[ ERROR ] The File does not exist. Make sure you are " + "setting the correct path to the file" + << std::endl; + } else { + init_flag_ = + pimpl_->objectdetection_->InitFromCommand(filePath, labelFilepath); + if (init_flag_ != 0) { + std::cout << "[Error] Init fail" << std::endl; + } + } + } else if (strcmp(suffixStr.c_str(), "json") == 0) { + if (!checkConfigFileExtension(filePath)) { + std::cout << "[ ERROR ] The ConfigFilepath is not correct. Make sure " + "you are setting the path to an json file (.json)" + << std::endl; + } else if (!exists_check(filePath)) { + std::cout << "[ ERROR ] The File does not exist. Make sure you are " + "setting the correct path to the file" + << std::endl; + } else { + init_flag_ = pimpl_->objectdetection_->InitFromConfig(filePath); + if (init_flag_ != 0) { + std::cout << "[Error] Init fail" << std::endl; + } + } + } else { + std::cout << "[ ERROR ] Unsupport file" << std::endl; + } + } else { + std::cout << "[ ERROR ] Unsupport filepath" << std::endl; + } +} + +objectDetectionTask::objectDetectionTask(const std::string &filePath) + : pimpl_(std::make_unique()) { + init_flag_ = -1; + pimpl_->objectdetection_ = + std::unique_ptr(new ObjectDetection()); + if (filePath.length() > 4) { + std::string suffixStr = filePath.substr(filePath.length() - 4, 4); + if (strcmp(suffixStr.c_str(), "json") == 0) { + if (!checkConfigFileExtension(filePath)) { + std::cout << "[ ERROR ] The ConfigFilepath is not correct. Make sure " + "you are setting the path to an json file (.json)" + << std::endl; + } else if (!exists_check(filePath)) { + std::cout << "[ ERROR ] The File does not exist. Make sure you are " + "setting the correct path to the file" + << std::endl; + } else { + init_flag_ = pimpl_->objectdetection_->InitFromConfig(filePath); + if (init_flag_ != 0) { + std::cout << "[Error] Init fail" << std::endl; + } + } + } else { + std::cout << "[ ERROR ] Unsupport file" << std::endl; + } + } else { + std::cout << "[ ERROR ] Unsupport filepath" << std::endl; + } +} + +int objectDetectionTask::getInitFlag() { return init_flag_; } + +ObjectDetectionResult objectDetectionTask::Detect(const cv::Mat &raw_img) { + return pimpl_->objectdetection_->Detect(raw_img); +} + +ObjectDetectionResult objectDetectionTask::Detect( + const std::vector> &input_tensors, const int img_height, + const int img_width) { + return pimpl_->objectdetection_->Detect(input_tensors, img_height, img_width); +} + +std::vector> objectDetectionTask::Process( + const cv::Mat &img_raw) { + return pimpl_->objectdetection_->Process(img_raw); +} diff --git a/src/task/vision/poseestimation/pose_estimation.cc b/src/task/vision/poseestimation/pose_estimation.cc new file mode 100644 index 0000000..c89c6d6 --- /dev/null +++ b/src/task/vision/poseestimation/pose_estimation.cc @@ -0,0 +1,77 @@ +#include "src/task/vision/poseestimation/pose_estimation.h" + +#include +#include + +#include "src/utils/json.hpp" +#include "utils/time.h" + +using json = nlohmann::json; + +PoseEstimationResult PoseEstimation::Estimate(const cv::Mat &raw_img, + const Boxi &box) { + result_points_.clear(); + input_tensors_.clear(); + box_ = box; + { +#ifdef DEBUG + std::cout << "|-- Preprocess" << std::endl; + TimeWatcher t("|--"); +#endif + Preprocess(raw_img); + } + return Postprocess(); +} + +void PoseEstimation::Preprocess(const cv::Mat &img_raw) { + if (initFlag_ != 0) { + std::cout << "[ ERROR ] Init fail" << std::endl; + return; + } + if (modelFilepath_.find("rtmpose") != modelFilepath_.npos) { + processor_.Preprocess(img_raw, box_, input_tensors_, crop_result_pair_, + CHW); + } else { + std::cout << "[ ERROR ] Unsupported model" << std::endl; + } +} + +PoseEstimationResult PoseEstimation::Postprocess() { + if (initFlag_ != 0) { + std::cout << "[ ERROR ] Init fail" << std::endl; + result_.result_points = result_points_; + result_.timestamp = std::chrono::steady_clock::now(); + return result_; + } + if (modelFilepath_.find("rtmpose") != modelFilepath_.npos) { + postprocessor_.Postprocess(Infer(input_tensors_), crop_result_pair_, + result_points_); + } else { + std::cout << "[ ERROR ] Unsupported model" << std::endl; + } + result_.result_points = result_points_; + result_.timestamp = std::chrono::steady_clock::now(); + return result_; +} + +int PoseEstimation::InitFromCommand(const std::string &modelFilepath) { + instanceName_ = "pose-estimation-inference"; + modelFilepath_ = modelFilepath; + initFlag_ = GetEngine()->Init(instanceName_, modelFilepath_); + inputDims_ = GetEngine()->GetInputDims(); + return initFlag_; +} + +int PoseEstimation::InitFromConfig(const std::string &configFilepath) { + std::ifstream f(configFilepath); + json config = json::parse(f); + if (configCheck(config)) { + initFlag_ = 1; + std::cout << "[ ERROR ] Config check fail" << std::endl; + return initFlag_; + } + modelFilepath_ = config["model_path"]; + initFlag_ = GetEngine()->Init(config); + inputDims_ = GetEngine()->GetInputDims(); + return initFlag_; +} diff --git a/src/task/vision/poseestimation/pose_estimation.h b/src/task/vision/poseestimation/pose_estimation.h new file mode 100644 index 0000000..eb4b1d6 --- /dev/null +++ b/src/task/vision/poseestimation/pose_estimation.h @@ -0,0 +1,46 @@ +#ifndef SUPPORT_SRC_TASK_VISION_POSEESTIMATION_POSE_ESTIMATION_H_ +#define SUPPORT_SRC_TASK_VISION_POSEESTIMATION_POSE_ESTIMATION_H_ + +#include +#include +#include // for pair<> +#include + +#include "opencv2/opencv.hpp" +#include "src/core/engine.h" +#include "src/processor/estimation_postprocessor.h" +#include "src/processor/estimation_preprocessor.h" +#include "src/task/vision/base_vision_task_api.h" +#include "src/utils/cv2_utils.h" +#include "task/vision/pose_estimation_types.h" + +class PoseEstimation : public BaseVisionTaskApi { + public: + PoseEstimation() : BaseVisionTaskApi() { + initFlag_ = -1; + } + ~PoseEstimation() {} + PoseEstimationResult Estimate(const cv::Mat &raw_img, const Boxi &box); + int InitFromCommand(const std::string &modelFilepath); + int InitFromConfig(const std::string &configFilepath); + + protected: + void Preprocess(const cv::Mat &img_raw) override; + PoseEstimationResult Postprocess() override; + + private: + std::string instanceName_; + std::string modelFilepath_; + std::vector labels_; + std::vector> inputDims_; + std::vector> input_tensors_; + EstimationPreprocessor processor_; + EstimationPostprocessor postprocessor_; + std::vector result_points_; + PoseEstimationResult result_; + Boxi box_; + int initFlag_; + std::pair crop_result_pair_; +}; + +#endif // SUPPORT_SRC_TASK_VISION_POSEESTIMATION_POSE_ESTIMATION_H_ diff --git a/src/task/vision/poseestimation/pose_estinmation_task.cc b/src/task/vision/poseestimation/pose_estinmation_task.cc new file mode 100644 index 0000000..abe4b55 --- /dev/null +++ b/src/task/vision/poseestimation/pose_estinmation_task.cc @@ -0,0 +1,61 @@ +#include "include/utils/utils.h" +#include "src/task/vision/poseestimation/pose_estimation.h" +#include "src/utils/utils.h" +#include "task/vision/pose_estimation_task.h" + +class poseEstimationTask::impl { + public: + std::unique_ptr poseestimation_; +}; + +poseEstimationTask::poseEstimationTask(const std::string &filePath) + : pimpl_(std::make_unique()) { + init_flag_ = -1; + pimpl_->poseestimation_ = + std::unique_ptr(new PoseEstimation()); + if (filePath.length() > 4) { + std::string suffixStr = filePath.substr(filePath.length() - 4, 4); + if (strcmp(suffixStr.c_str(), "onnx") == 0) { + if (!checkModelFileExtension(filePath)) { + std::cout << "[ ERROR ] The ModelFilepath is not correct. Make sure " + "you are setting the path to an onnx model file (.onnx)" + << std::endl; + } else if (!exists_check(filePath)) { + std::cout << "[ ERROR ] The File does not exist. Make sure you are " + "setting the correct path to the file" + << std::endl; + } else { + init_flag_ = pimpl_->poseestimation_->InitFromCommand(filePath); + if (init_flag_ != 0) { + std::cout << "[Error] Init fail" << std::endl; + } + } + } else if (strcmp(suffixStr.c_str(), "json") == 0) { + if (!checkConfigFileExtension(filePath)) { + std::cout << "[ ERROR ] The ConfigFilepath is not correct. Make sure " + "you are setting the path to an json file (.json)" + << std::endl; + } else if (!exists_check(filePath)) { + std::cout << "[ ERROR ] The File does not exist. Make sure you are " + "setting the correct path to the file" + << std::endl; + } else { + init_flag_ = pimpl_->poseestimation_->InitFromConfig(filePath); + if (init_flag_ != 0) { + std::cout << "[Error] Init fail" << std::endl; + } + } + } else { + std::cout << "[ ERROR ] Unsupport file" << std::endl; + } + } else { + std::cout << "[ ERROR ] Unsupport filepath" << std::endl; + } +} + +int poseEstimationTask::getInitFlag() { return init_flag_; } + +PoseEstimationResult poseEstimationTask::Estimate(const cv::Mat &raw_img, + const Boxi &box) { + return pimpl_->poseestimation_->Estimate(raw_img, box); +} diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt new file mode 100644 index 0000000..35c9301 --- /dev/null +++ b/src/tests/CMakeLists.txt @@ -0,0 +1 @@ +add_executable(json_test json_test.cc) \ No newline at end of file diff --git a/src/tests/json_test.cc b/src/tests/json_test.cc new file mode 100644 index 0000000..e7dea93 --- /dev/null +++ b/src/tests/json_test.cc @@ -0,0 +1,20 @@ +#include "../utils/json.hpp" + +#include +#include + +using json = nlohmann::json; + +int main(int argc, char *argv[]) { + if (argc < 2) { + std::cout << "Usage: " << argv[0] << " \n"; + return 0; + } + std::ifstream f(argv[1]); + json config = json::parse(f); + if (config.contains("name")) { + std::string name = config["name"]; + std::cout << name << std::endl; + } + return 0; +} \ No newline at end of file diff --git a/src/utils/cv2_utils.cc b/src/utils/cv2_utils.cc new file mode 100644 index 0000000..6ea3986 --- /dev/null +++ b/src/utils/cv2_utils.cc @@ -0,0 +1,120 @@ +#ifndef SUPPORT_SRC_UTILS_CV2_UTILS_H_ +#define SUPPORT_SRC_UTILS_CV2_UTILS_H_ + +#include "src/utils/cv2_utils.h" + +#include +#include +#include +#include + +#include "opencv2/opencv.hpp" + +enum { CHW = 0, HWC = 1 }; + +cv::Mat normalize(const cv::Mat &mat, float mean, float scale) { + cv::Mat matf; + if (mat.type() != CV_32FC3) + mat.convertTo(matf, CV_32FC3); + else + matf = mat; // reference + return (matf - mean) * scale; +} + +cv::Mat normalize(const cv::Mat &mat, const float *mean, const float *scale) { + cv::Mat mat_copy; + if (mat.type() != CV_32FC3) + mat.convertTo(mat_copy, CV_32FC3); + else + mat_copy = mat.clone(); + for (int i = 0; i < mat_copy.rows; ++i) { + cv::Vec3f *p = mat_copy.ptr(i); + for (int j = 0; j < mat_copy.cols; ++j) { + p[j][0] = (p[j][0] - mean[0]) * scale[0]; + p[j][1] = (p[j][1] - mean[1]) * scale[1]; + p[j][2] = (p[j][2] - mean[2]) * scale[2]; + } + } + return mat_copy; +} + +void normalize(const cv::Mat &inmat, cv::Mat &outmat, float mean, float scale) { + outmat = normalize(inmat, mean, scale); +} + +void normalize_inplace(cv::Mat &mat_inplace, float mean, float scale) { + if (mat_inplace.type() != CV_32FC3) + mat_inplace.convertTo(mat_inplace, CV_32FC3); + normalize(mat_inplace, mat_inplace, mean, scale); +} + +void normalize_inplace(cv::Mat &mat_inplace, const float *mean, + const float *scale) { + if (mat_inplace.type() != CV_32FC3) + mat_inplace.convertTo(mat_inplace, CV_32FC3); + for (int i = 0; i < mat_inplace.rows; ++i) { + cv::Vec3f *p = mat_inplace.ptr(i); + for (int j = 0; j < mat_inplace.cols; ++j) { + p[j][0] = (p[j][0] - mean[0]) * scale[0]; + p[j][1] = (p[j][1] - mean[1]) * scale[1]; + p[j][2] = (p[j][2] - mean[2]) * scale[2]; + } + } +} + +cv::Mat GetAffineTransform(float center_x, float center_y, float scale_width, + float scale_height, int output_image_width, + int output_image_height, bool inverse = false) { + // solve the affine transformation matrix + + // get the three points corresponding to the source picture and the target + // picture + cv::Point2f src_point_1; + src_point_1.x = center_x; + src_point_1.y = center_y; + + cv::Point2f src_point_2; + src_point_2.x = center_x - scale_height * 0; + src_point_2.y = center_y - scale_width * 0.5; + + cv::Point2f src_point_3; + src_point_3.x = src_point_2.x - (src_point_1.y - src_point_2.y); + src_point_3.y = src_point_2.y + (src_point_1.x - src_point_2.x); + + float alphapose_image_center_x = output_image_width / 2; + float alphapose_image_center_y = output_image_height / 2; + + cv::Point2f dst_point_1; + dst_point_1.x = alphapose_image_center_x; + dst_point_1.y = alphapose_image_center_y; + + cv::Point2f dst_point_2; + dst_point_2.x = alphapose_image_center_x; + dst_point_2.y = alphapose_image_center_y - output_image_width * 0.5; + + cv::Point2f dst_point_3; + dst_point_3.x = dst_point_2.x - (dst_point_1.y - dst_point_2.y); + dst_point_3.y = dst_point_2.y + (dst_point_1.x - dst_point_2.x); + + cv::Point2f srcPoints[3]; + srcPoints[0] = src_point_1; + srcPoints[1] = src_point_2; + srcPoints[2] = src_point_3; + + cv::Point2f dstPoints[3]; + dstPoints[0] = dst_point_1; + dstPoints[1] = dst_point_2; + dstPoints[2] = dst_point_3; + + // get affine matrix + cv::Mat affineTransform; + if (inverse) { + affineTransform = cv::getAffineTransform(dstPoints, srcPoints); + } else { + affineTransform = cv::getAffineTransform(srcPoints, dstPoints); + } + + return affineTransform; +} + +#endif // SUPPORT_SRC_UTILS_CV2_UTILS_H_ diff --git a/src/utils/cv2_utils.h b/src/utils/cv2_utils.h new file mode 100644 index 0000000..2a28dce --- /dev/null +++ b/src/utils/cv2_utils.h @@ -0,0 +1,25 @@ +#ifndef SUPPORT_SRC_UTILS_CV2_UTILS_H_ +#define SUPPORT_SRC_UTILS_CV2_UTILS_H_ + +#include + +#include "opencv2/opencv.hpp" + +enum { CHW = 0, HWC = 1 }; + +cv::Mat normalize(const cv::Mat &mat, float mean, float scale); + +cv::Mat normalize(const cv::Mat &mat, const float *mean, const float *scale); + +void normalize(const cv::Mat &inmat, cv::Mat &outmat, float mean, float scale); + +void normalize_inplace(cv::Mat &mat_inplace, float mean, float scale); + +void normalize_inplace(cv::Mat &mat_inplace, const float *mean, + const float *scale); + +cv::Mat GetAffineTransform(float center_x, float center_y, float scale_width, + float scale_height, int output_image_width, + int output_image_height, bool inverse = false); + +#endif // SUPPORT_SRC_UTILS_CV2_UTILS_H_ diff --git a/src/utils/json.hpp b/src/utils/json.hpp new file mode 100644 index 0000000..8b72ea6 --- /dev/null +++ b/src/utils/json.hpp @@ -0,0 +1,24765 @@ +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-License-Identifier: MIT + +/****************************************************************************\ + * Note on documentation: The source files contain links to the online * + * documentation of the public API at https://json.nlohmann.me. This URL * + * contains the most recent documentation and should also be applicable to * + * previous versions; documentation for deprecated functions is not * + * removed, but marked deprecated. See "Generate documentation" section in * + * file docs/README.md. * +\****************************************************************************/ + +#ifndef INCLUDE_NLOHMANN_JSON_HPP_ +#define INCLUDE_NLOHMANN_JSON_HPP_ + +#include // all_of, find, for_each +#include // nullptr_t, ptrdiff_t, size_t +#include // hash, less +#include // initializer_list +#ifndef JSON_NO_IO + #include // istream, ostream +#endif // JSON_NO_IO +#include // random_access_iterator_tag +#include // unique_ptr +#include // string, stoi, to_string +#include // declval, forward, move, pair, swap +#include // vector + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +// This file contains all macro definitions affecting or depending on the ABI + +#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK + #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH) + #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 3 + #warning "Already included a different version of the library!" + #endif + #endif +#endif + +#define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum) +#define NLOHMANN_JSON_VERSION_MINOR 11 // NOLINT(modernize-macro-to-enum) +#define NLOHMANN_JSON_VERSION_PATCH 3 // NOLINT(modernize-macro-to-enum) + +#ifndef JSON_DIAGNOSTICS + #define JSON_DIAGNOSTICS 0 +#endif + +#ifndef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON + #define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0 +#endif + +#if JSON_DIAGNOSTICS + #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag +#else + #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS +#endif + +#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON + #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp +#else + #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON +#endif + +#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION + #define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0 +#endif + +// Construct the namespace ABI tags component +#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi ## a ## b +#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \ + NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) + +#define NLOHMANN_JSON_ABI_TAGS \ + NLOHMANN_JSON_ABI_TAGS_CONCAT( \ + NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ + NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON) + +// Construct the namespace version component +#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \ + _v ## major ## _ ## minor ## _ ## patch +#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \ + NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) + +#if NLOHMANN_JSON_NAMESPACE_NO_VERSION +#define NLOHMANN_JSON_NAMESPACE_VERSION +#else +#define NLOHMANN_JSON_NAMESPACE_VERSION \ + NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \ + NLOHMANN_JSON_VERSION_MINOR, \ + NLOHMANN_JSON_VERSION_PATCH) +#endif + +// Combine namespace components +#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b +#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \ + NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) + +#ifndef NLOHMANN_JSON_NAMESPACE +#define NLOHMANN_JSON_NAMESPACE \ + nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \ + NLOHMANN_JSON_ABI_TAGS, \ + NLOHMANN_JSON_NAMESPACE_VERSION) +#endif + +#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN +#define NLOHMANN_JSON_NAMESPACE_BEGIN \ + namespace nlohmann \ + { \ + inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \ + NLOHMANN_JSON_ABI_TAGS, \ + NLOHMANN_JSON_NAMESPACE_VERSION) \ + { +#endif + +#ifndef NLOHMANN_JSON_NAMESPACE_END +#define NLOHMANN_JSON_NAMESPACE_END \ + } /* namespace (inline namespace) NOLINT(readability/namespace) */ \ + } // namespace nlohmann +#endif + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include // transform +#include // array +#include // forward_list +#include // inserter, front_inserter, end +#include // map +#include // string +#include // tuple, make_tuple +#include // is_arithmetic, is_same, is_enum, underlying_type, is_convertible +#include // unordered_map +#include // pair, declval +#include // valarray + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include // nullptr_t +#include // exception +#if JSON_DIAGNOSTICS + #include // accumulate +#endif +#include // runtime_error +#include // to_string +#include // vector + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include // array +#include // size_t +#include // uint8_t +#include // string + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include // declval, pair +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ + +template struct make_void +{ + using type = void; +}; +template using void_t = typename make_void::type; + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END + + +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ + +// https://en.cppreference.com/w/cpp/experimental/is_detected +struct nonesuch +{ + nonesuch() = delete; + ~nonesuch() = delete; + nonesuch(nonesuch const&) = delete; + nonesuch(nonesuch const&&) = delete; + void operator=(nonesuch const&) = delete; + void operator=(nonesuch&&) = delete; +}; + +template class Op, + class... Args> +struct detector +{ + using value_t = std::false_type; + using type = Default; +}; + +template class Op, class... Args> +struct detector>, Op, Args...> +{ + using value_t = std::true_type; + using type = Op; +}; + +template class Op, class... Args> +using is_detected = typename detector::value_t; + +template class Op, class... Args> +struct is_detected_lazy : is_detected { }; + +template class Op, class... Args> +using detected_t = typename detector::type; + +template class Op, class... Args> +using detected_or = detector; + +template class Op, class... Args> +using detected_or_t = typename detected_or::type; + +template class Op, class... Args> +using is_detected_exact = std::is_same>; + +template class Op, class... Args> +using is_detected_convertible = + std::is_convertible, To>; + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END + +// #include + + +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-FileCopyrightText: 2016-2021 Evan Nemerson +// SPDX-License-Identifier: MIT + +/* Hedley - https://nemequ.github.io/hedley + * Created by Evan Nemerson + */ + +#if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15) +#if defined(JSON_HEDLEY_VERSION) + #undef JSON_HEDLEY_VERSION +#endif +#define JSON_HEDLEY_VERSION 15 + +#if defined(JSON_HEDLEY_STRINGIFY_EX) + #undef JSON_HEDLEY_STRINGIFY_EX +#endif +#define JSON_HEDLEY_STRINGIFY_EX(x) #x + +#if defined(JSON_HEDLEY_STRINGIFY) + #undef JSON_HEDLEY_STRINGIFY +#endif +#define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x) + +#if defined(JSON_HEDLEY_CONCAT_EX) + #undef JSON_HEDLEY_CONCAT_EX +#endif +#define JSON_HEDLEY_CONCAT_EX(a,b) a##b + +#if defined(JSON_HEDLEY_CONCAT) + #undef JSON_HEDLEY_CONCAT +#endif +#define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b) + +#if defined(JSON_HEDLEY_CONCAT3_EX) + #undef JSON_HEDLEY_CONCAT3_EX +#endif +#define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c + +#if defined(JSON_HEDLEY_CONCAT3) + #undef JSON_HEDLEY_CONCAT3 +#endif +#define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c) + +#if defined(JSON_HEDLEY_VERSION_ENCODE) + #undef JSON_HEDLEY_VERSION_ENCODE +#endif +#define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision)) + +#if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR) + #undef JSON_HEDLEY_VERSION_DECODE_MAJOR +#endif +#define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000) + +#if defined(JSON_HEDLEY_VERSION_DECODE_MINOR) + #undef JSON_HEDLEY_VERSION_DECODE_MINOR +#endif +#define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000) + +#if defined(JSON_HEDLEY_VERSION_DECODE_REVISION) + #undef JSON_HEDLEY_VERSION_DECODE_REVISION +#endif +#define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000) + +#if defined(JSON_HEDLEY_GNUC_VERSION) + #undef JSON_HEDLEY_GNUC_VERSION +#endif +#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__) + #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) +#elif defined(__GNUC__) + #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0) +#endif + +#if defined(JSON_HEDLEY_GNUC_VERSION_CHECK) + #undef JSON_HEDLEY_GNUC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_GNUC_VERSION) + #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_MSVC_VERSION) + #undef JSON_HEDLEY_MSVC_VERSION +#endif +#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100) +#elif defined(_MSC_FULL_VER) && !defined(__ICL) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10) +#elif defined(_MSC_VER) && !defined(__ICL) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0) +#endif + +#if defined(JSON_HEDLEY_MSVC_VERSION_CHECK) + #undef JSON_HEDLEY_MSVC_VERSION_CHECK +#endif +#if !defined(JSON_HEDLEY_MSVC_VERSION) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0) +#elif defined(_MSC_VER) && (_MSC_VER >= 1400) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch))) +#elif defined(_MSC_VER) && (_MSC_VER >= 1200) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch))) +#else + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor))) +#endif + +#if defined(JSON_HEDLEY_INTEL_VERSION) + #undef JSON_HEDLEY_INTEL_VERSION +#endif +#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL) + #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE) +#elif defined(__INTEL_COMPILER) && !defined(__ICL) + #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0) +#endif + +#if defined(JSON_HEDLEY_INTEL_VERSION_CHECK) + #undef JSON_HEDLEY_INTEL_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_INTEL_VERSION) + #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_INTEL_CL_VERSION) + #undef JSON_HEDLEY_INTEL_CL_VERSION +#endif +#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL) + #define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0) +#endif + +#if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK) + #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_INTEL_CL_VERSION) + #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_PGI_VERSION) + #undef JSON_HEDLEY_PGI_VERSION +#endif +#if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__) + #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__) +#endif + +#if defined(JSON_HEDLEY_PGI_VERSION_CHECK) + #undef JSON_HEDLEY_PGI_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_PGI_VERSION) + #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_SUNPRO_VERSION) + #undef JSON_HEDLEY_SUNPRO_VERSION +#endif +#if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), (__SUNPRO_C & 0xf) * 10) +#elif defined(__SUNPRO_C) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf) +#elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), (__SUNPRO_CC & 0xf) * 10) +#elif defined(__SUNPRO_CC) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf) +#endif + +#if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK) + #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_SUNPRO_VERSION) + #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) + #undef JSON_HEDLEY_EMSCRIPTEN_VERSION +#endif +#if defined(__EMSCRIPTEN__) + #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__) +#endif + +#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK) + #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) + #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_ARM_VERSION) + #undef JSON_HEDLEY_ARM_VERSION +#endif +#if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION) + #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100) +#elif defined(__CC_ARM) && defined(__ARMCC_VERSION) + #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100) +#endif + +#if defined(JSON_HEDLEY_ARM_VERSION_CHECK) + #undef JSON_HEDLEY_ARM_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_ARM_VERSION) + #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_IBM_VERSION) + #undef JSON_HEDLEY_IBM_VERSION +#endif +#if defined(__ibmxl__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__) +#elif defined(__xlC__) && defined(__xlC_ver__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff) +#elif defined(__xlC__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0) +#endif + +#if defined(JSON_HEDLEY_IBM_VERSION_CHECK) + #undef JSON_HEDLEY_IBM_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_IBM_VERSION) + #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_VERSION) + #undef JSON_HEDLEY_TI_VERSION +#endif +#if \ + defined(__TI_COMPILER_VERSION__) && \ + ( \ + defined(__TMS470__) || defined(__TI_ARM__) || \ + defined(__MSP430__) || \ + defined(__TMS320C2000__) \ + ) +#if (__TI_COMPILER_VERSION__ >= 16000000) + #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif +#endif + +#if defined(JSON_HEDLEY_TI_VERSION_CHECK) + #undef JSON_HEDLEY_TI_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_VERSION) + #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_CL2000_VERSION) + #undef JSON_HEDLEY_TI_CL2000_VERSION +#endif +#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__) + #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif + +#if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_CL2000_VERSION) + #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_CL430_VERSION) + #undef JSON_HEDLEY_TI_CL430_VERSION +#endif +#if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__) + #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif + +#if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_CL430_VERSION) + #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_ARMCL_VERSION) + #undef JSON_HEDLEY_TI_ARMCL_VERSION +#endif +#if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__)) + #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif + +#if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK) + #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_ARMCL_VERSION) + #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_CL6X_VERSION) + #undef JSON_HEDLEY_TI_CL6X_VERSION +#endif +#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__) + #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif + +#if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_CL6X_VERSION) + #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_CL7X_VERSION) + #undef JSON_HEDLEY_TI_CL7X_VERSION +#endif +#if defined(__TI_COMPILER_VERSION__) && defined(__C7000__) + #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif + +#if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_CL7X_VERSION) + #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_CLPRU_VERSION) + #undef JSON_HEDLEY_TI_CLPRU_VERSION +#endif +#if defined(__TI_COMPILER_VERSION__) && defined(__PRU__) + #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif + +#if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_CLPRU_VERSION) + #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_CRAY_VERSION) + #undef JSON_HEDLEY_CRAY_VERSION +#endif +#if defined(_CRAYC) + #if defined(_RELEASE_PATCHLEVEL) + #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL) + #else + #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0) + #endif +#endif + +#if defined(JSON_HEDLEY_CRAY_VERSION_CHECK) + #undef JSON_HEDLEY_CRAY_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_CRAY_VERSION) + #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_IAR_VERSION) + #undef JSON_HEDLEY_IAR_VERSION +#endif +#if defined(__IAR_SYSTEMS_ICC__) + #if __VER__ > 1000 + #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000)) + #else + #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0) + #endif +#endif + +#if defined(JSON_HEDLEY_IAR_VERSION_CHECK) + #undef JSON_HEDLEY_IAR_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_IAR_VERSION) + #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TINYC_VERSION) + #undef JSON_HEDLEY_TINYC_VERSION +#endif +#if defined(__TINYC__) + #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100) +#endif + +#if defined(JSON_HEDLEY_TINYC_VERSION_CHECK) + #undef JSON_HEDLEY_TINYC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TINYC_VERSION) + #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_DMC_VERSION) + #undef JSON_HEDLEY_DMC_VERSION +#endif +#if defined(__DMC__) + #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf) +#endif + +#if defined(JSON_HEDLEY_DMC_VERSION_CHECK) + #undef JSON_HEDLEY_DMC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_DMC_VERSION) + #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_COMPCERT_VERSION) + #undef JSON_HEDLEY_COMPCERT_VERSION +#endif +#if defined(__COMPCERT_VERSION__) + #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100) +#endif + +#if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK) + #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_COMPCERT_VERSION) + #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_PELLES_VERSION) + #undef JSON_HEDLEY_PELLES_VERSION +#endif +#if defined(__POCC__) + #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0) +#endif + +#if defined(JSON_HEDLEY_PELLES_VERSION_CHECK) + #undef JSON_HEDLEY_PELLES_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_PELLES_VERSION) + #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_MCST_LCC_VERSION) + #undef JSON_HEDLEY_MCST_LCC_VERSION +#endif +#if defined(__LCC__) && defined(__LCC_MINOR__) + #define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__) +#endif + +#if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK) + #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_MCST_LCC_VERSION) + #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_GCC_VERSION) + #undef JSON_HEDLEY_GCC_VERSION +#endif +#if \ + defined(JSON_HEDLEY_GNUC_VERSION) && \ + !defined(__clang__) && \ + !defined(JSON_HEDLEY_INTEL_VERSION) && \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_ARM_VERSION) && \ + !defined(JSON_HEDLEY_CRAY_VERSION) && \ + !defined(JSON_HEDLEY_TI_VERSION) && \ + !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \ + !defined(JSON_HEDLEY_TI_CL430_VERSION) && \ + !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \ + !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \ + !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \ + !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \ + !defined(__COMPCERT__) && \ + !defined(JSON_HEDLEY_MCST_LCC_VERSION) + #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION +#endif + +#if defined(JSON_HEDLEY_GCC_VERSION_CHECK) + #undef JSON_HEDLEY_GCC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_GCC_VERSION) + #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_ATTRIBUTE +#endif +#if \ + defined(__has_attribute) && \ + ( \ + (!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \ + ) +# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute) +#else +# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE +#endif +#if defined(__has_attribute) + #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) +#else + #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE +#endif +#if defined(__has_attribute) + #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) +#else + #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE +#endif +#if \ + defined(__has_cpp_attribute) && \ + defined(__cplusplus) && \ + (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute) +#else + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0) +#endif + +#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS) + #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS +#endif +#if !defined(__cplusplus) || !defined(__has_cpp_attribute) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0) +#elif \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_IAR_VERSION) && \ + (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \ + (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0)) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute) +#else + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE +#endif +#if defined(__has_cpp_attribute) && defined(__cplusplus) + #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute) +#else + #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE +#endif +#if defined(__has_cpp_attribute) && defined(__cplusplus) + #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute) +#else + #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_BUILTIN) + #undef JSON_HEDLEY_HAS_BUILTIN +#endif +#if defined(__has_builtin) + #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin) +#else + #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN) + #undef JSON_HEDLEY_GNUC_HAS_BUILTIN +#endif +#if defined(__has_builtin) + #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin) +#else + #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_BUILTIN) + #undef JSON_HEDLEY_GCC_HAS_BUILTIN +#endif +#if defined(__has_builtin) + #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin) +#else + #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_FEATURE) + #undef JSON_HEDLEY_HAS_FEATURE +#endif +#if defined(__has_feature) + #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature) +#else + #define JSON_HEDLEY_HAS_FEATURE(feature) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_FEATURE) + #undef JSON_HEDLEY_GNUC_HAS_FEATURE +#endif +#if defined(__has_feature) + #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature) +#else + #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_FEATURE) + #undef JSON_HEDLEY_GCC_HAS_FEATURE +#endif +#if defined(__has_feature) + #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature) +#else + #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_EXTENSION) + #undef JSON_HEDLEY_HAS_EXTENSION +#endif +#if defined(__has_extension) + #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension) +#else + #define JSON_HEDLEY_HAS_EXTENSION(extension) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION) + #undef JSON_HEDLEY_GNUC_HAS_EXTENSION +#endif +#if defined(__has_extension) + #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension) +#else + #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_EXTENSION) + #undef JSON_HEDLEY_GCC_HAS_EXTENSION +#endif +#if defined(__has_extension) + #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension) +#else + #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE +#endif +#if defined(__has_declspec_attribute) + #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute) +#else + #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE +#endif +#if defined(__has_declspec_attribute) + #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute) +#else + #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE +#endif +#if defined(__has_declspec_attribute) + #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute) +#else + #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_WARNING) + #undef JSON_HEDLEY_HAS_WARNING +#endif +#if defined(__has_warning) + #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning) +#else + #define JSON_HEDLEY_HAS_WARNING(warning) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_WARNING) + #undef JSON_HEDLEY_GNUC_HAS_WARNING +#endif +#if defined(__has_warning) + #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning) +#else + #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_WARNING) + #undef JSON_HEDLEY_GCC_HAS_WARNING +#endif +#if defined(__has_warning) + #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning) +#else + #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if \ + (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ + defined(__clang__) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR)) + #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value) +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) + #define JSON_HEDLEY_PRAGMA(value) __pragma(value) +#else + #define JSON_HEDLEY_PRAGMA(value) +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH) + #undef JSON_HEDLEY_DIAGNOSTIC_PUSH +#endif +#if defined(JSON_HEDLEY_DIAGNOSTIC_POP) + #undef JSON_HEDLEY_DIAGNOSTIC_POP +#endif +#if defined(__clang__) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push)) + #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop)) +#elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop") +#elif \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop") +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") +#else + #define JSON_HEDLEY_DIAGNOSTIC_PUSH + #define JSON_HEDLEY_DIAGNOSTIC_POP +#endif + +/* JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ is for + HEDLEY INTERNAL USE ONLY. API subject to change without notice. */ +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ +#endif +#if defined(__cplusplus) +# if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat") +# if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions") +# if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions") +# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ + _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \ + _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \ + xpr \ + JSON_HEDLEY_DIAGNOSTIC_POP +# else +# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ + _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \ + xpr \ + JSON_HEDLEY_DIAGNOSTIC_POP +# endif +# else +# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ + xpr \ + JSON_HEDLEY_DIAGNOSTIC_POP +# endif +# endif +#endif +#if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x +#endif + +#if defined(JSON_HEDLEY_CONST_CAST) + #undef JSON_HEDLEY_CONST_CAST +#endif +#if defined(__cplusplus) +# define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast(expr)) +#elif \ + JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) +# define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \ + ((T) (expr)); \ + JSON_HEDLEY_DIAGNOSTIC_POP \ + })) +#else +# define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr)) +#endif + +#if defined(JSON_HEDLEY_REINTERPRET_CAST) + #undef JSON_HEDLEY_REINTERPRET_CAST +#endif +#if defined(__cplusplus) + #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast(expr)) +#else + #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr)) +#endif + +#if defined(JSON_HEDLEY_STATIC_CAST) + #undef JSON_HEDLEY_STATIC_CAST +#endif +#if defined(__cplusplus) + #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast(expr)) +#else + #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr)) +#endif + +#if defined(JSON_HEDLEY_CPP_CAST) + #undef JSON_HEDLEY_CPP_CAST +#endif +#if defined(__cplusplus) +# if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast") +# define JSON_HEDLEY_CPP_CAST(T, expr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \ + ((T) (expr)) \ + JSON_HEDLEY_DIAGNOSTIC_POP +# elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0) +# define JSON_HEDLEY_CPP_CAST(T, expr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("diag_suppress=Pe137") \ + JSON_HEDLEY_DIAGNOSTIC_POP +# else +# define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr)) +# endif +#else +# define JSON_HEDLEY_CPP_CAST(T, expr) (expr) +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)") +#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786)) +#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445") +#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996)) +#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") +#elif \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718") +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)") +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215") +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)") +#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161)) +#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068)) +#elif \ + JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") +#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161") +#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)") +#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292)) +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030)) +#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098") +#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)") +#elif \ + JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097") +#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wcast-qual") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunused-function") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505)) +#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION +#endif + +#if defined(JSON_HEDLEY_DEPRECATED) + #undef JSON_HEDLEY_DEPRECATED +#endif +#if defined(JSON_HEDLEY_DEPRECATED_FOR) + #undef JSON_HEDLEY_DEPRECATED_FOR +#endif +#if \ + JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since)) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement)) +#elif \ + (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since))) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement))) +#elif defined(__cplusplus) && (__cplusplus >= 201402L) + #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]]) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]]) +#elif \ + JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) + #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__)) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__)) +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ + JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated) +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated") + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated") +#else + #define JSON_HEDLEY_DEPRECATED(since) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) +#endif + +#if defined(JSON_HEDLEY_UNAVAILABLE) + #undef JSON_HEDLEY_UNAVAILABLE +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since))) +#else + #define JSON_HEDLEY_UNAVAILABLE(available_since) +#endif + +#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT) + #undef JSON_HEDLEY_WARN_UNUSED_RESULT +#endif +#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG) + #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__)) +#elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L) + #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]]) +#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) + #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) +#elif defined(_Check_return_) /* SAL */ + #define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_ + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_ +#else + #define JSON_HEDLEY_WARN_UNUSED_RESULT + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) +#endif + +#if defined(JSON_HEDLEY_SENTINEL) + #undef JSON_HEDLEY_SENTINEL +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position))) +#else + #define JSON_HEDLEY_SENTINEL(position) +#endif + +#if defined(JSON_HEDLEY_NO_RETURN) + #undef JSON_HEDLEY_NO_RETURN +#endif +#if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_NO_RETURN __noreturn +#elif \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) +#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L + #define JSON_HEDLEY_NO_RETURN _Noreturn +#elif defined(__cplusplus) && (__cplusplus >= 201103L) + #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]]) +#elif \ + JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) + #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) + #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return") +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_NO_RETURN __declspec(noreturn) +#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus) + #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;") +#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0) + #define JSON_HEDLEY_NO_RETURN __attribute((noreturn)) +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0) + #define JSON_HEDLEY_NO_RETURN __declspec(noreturn) +#else + #define JSON_HEDLEY_NO_RETURN +#endif + +#if defined(JSON_HEDLEY_NO_ESCAPE) + #undef JSON_HEDLEY_NO_ESCAPE +#endif +#if JSON_HEDLEY_HAS_ATTRIBUTE(noescape) + #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__)) +#else + #define JSON_HEDLEY_NO_ESCAPE +#endif + +#if defined(JSON_HEDLEY_UNREACHABLE) + #undef JSON_HEDLEY_UNREACHABLE +#endif +#if defined(JSON_HEDLEY_UNREACHABLE_RETURN) + #undef JSON_HEDLEY_UNREACHABLE_RETURN +#endif +#if defined(JSON_HEDLEY_ASSUME) + #undef JSON_HEDLEY_ASSUME +#endif +#if \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_ASSUME(expr) __assume(expr) +#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume) + #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr) +#elif \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) + #if defined(__cplusplus) + #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr) + #else + #define JSON_HEDLEY_ASSUME(expr) _nassert(expr) + #endif +#endif +#if \ + (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable() +#elif defined(JSON_HEDLEY_ASSUME) + #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0) +#endif +#if !defined(JSON_HEDLEY_ASSUME) + #if defined(JSON_HEDLEY_UNREACHABLE) + #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1))) + #else + #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr) + #endif +#endif +#if defined(JSON_HEDLEY_UNREACHABLE) + #if \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value)) + #else + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE() + #endif +#else + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value) +#endif +#if !defined(JSON_HEDLEY_UNREACHABLE) + #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0) +#endif + +JSON_HEDLEY_DIAGNOSTIC_PUSH +#if JSON_HEDLEY_HAS_WARNING("-Wpedantic") + #pragma clang diagnostic ignored "-Wpedantic" +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus) + #pragma clang diagnostic ignored "-Wc++98-compat-pedantic" +#endif +#if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0) + #if defined(__clang__) + #pragma clang diagnostic ignored "-Wvariadic-macros" + #elif defined(JSON_HEDLEY_GCC_VERSION) + #pragma GCC diagnostic ignored "-Wvariadic-macros" + #endif +#endif +#if defined(JSON_HEDLEY_NON_NULL) + #undef JSON_HEDLEY_NON_NULL +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) + #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__))) +#else + #define JSON_HEDLEY_NON_NULL(...) +#endif +JSON_HEDLEY_DIAGNOSTIC_POP + +#if defined(JSON_HEDLEY_PRINTF_FORMAT) + #undef JSON_HEDLEY_PRINTF_FORMAT +#endif +#if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check))) +#elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check))) +#elif \ + JSON_HEDLEY_HAS_ATTRIBUTE(format) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check))) +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check)) +#else + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) +#endif + +#if defined(JSON_HEDLEY_CONSTEXPR) + #undef JSON_HEDLEY_CONSTEXPR +#endif +#if defined(__cplusplus) + #if __cplusplus >= 201103L + #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr) + #endif +#endif +#if !defined(JSON_HEDLEY_CONSTEXPR) + #define JSON_HEDLEY_CONSTEXPR +#endif + +#if defined(JSON_HEDLEY_PREDICT) + #undef JSON_HEDLEY_PREDICT +#endif +#if defined(JSON_HEDLEY_LIKELY) + #undef JSON_HEDLEY_LIKELY +#endif +#if defined(JSON_HEDLEY_UNLIKELY) + #undef JSON_HEDLEY_UNLIKELY +#endif +#if defined(JSON_HEDLEY_UNPREDICTABLE) + #undef JSON_HEDLEY_UNPREDICTABLE +#endif +#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable) + #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr)) +#endif +#if \ + (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) +# define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability)) +# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability)) +# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability)) +# define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 ) +# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 ) +#elif \ + (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) +# define JSON_HEDLEY_PREDICT(expr, expected, probability) \ + (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))) +# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \ + (__extension__ ({ \ + double hedley_probability_ = (probability); \ + ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \ + })) +# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \ + (__extension__ ({ \ + double hedley_probability_ = (probability); \ + ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \ + })) +# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1) +# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0) +#else +# define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)) +# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr)) +# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr)) +# define JSON_HEDLEY_LIKELY(expr) (!!(expr)) +# define JSON_HEDLEY_UNLIKELY(expr) (!!(expr)) +#endif +#if !defined(JSON_HEDLEY_UNPREDICTABLE) + #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5) +#endif + +#if defined(JSON_HEDLEY_MALLOC) + #undef JSON_HEDLEY_MALLOC +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_MALLOC __attribute__((__malloc__)) +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) + #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory") +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_MALLOC __declspec(restrict) +#else + #define JSON_HEDLEY_MALLOC +#endif + +#if defined(JSON_HEDLEY_PURE) + #undef JSON_HEDLEY_PURE +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) +# define JSON_HEDLEY_PURE __attribute__((__pure__)) +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) +# define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data") +#elif defined(__cplusplus) && \ + ( \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \ + ) +# define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;") +#else +# define JSON_HEDLEY_PURE +#endif + +#if defined(JSON_HEDLEY_CONST) + #undef JSON_HEDLEY_CONST +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(const) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_CONST __attribute__((__const__)) +#elif \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) + #define JSON_HEDLEY_CONST _Pragma("no_side_effect") +#else + #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE +#endif + +#if defined(JSON_HEDLEY_RESTRICT) + #undef JSON_HEDLEY_RESTRICT +#endif +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus) + #define JSON_HEDLEY_RESTRICT restrict +#elif \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \ + defined(__clang__) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_RESTRICT __restrict +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus) + #define JSON_HEDLEY_RESTRICT _Restrict +#else + #define JSON_HEDLEY_RESTRICT +#endif + +#if defined(JSON_HEDLEY_INLINE) + #undef JSON_HEDLEY_INLINE +#endif +#if \ + (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ + (defined(__cplusplus) && (__cplusplus >= 199711L)) + #define JSON_HEDLEY_INLINE inline +#elif \ + defined(JSON_HEDLEY_GCC_VERSION) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0) + #define JSON_HEDLEY_INLINE __inline__ +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_INLINE __inline +#else + #define JSON_HEDLEY_INLINE +#endif + +#if defined(JSON_HEDLEY_ALWAYS_INLINE) + #undef JSON_HEDLEY_ALWAYS_INLINE +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) +# define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) +# define JSON_HEDLEY_ALWAYS_INLINE __forceinline +#elif defined(__cplusplus) && \ + ( \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \ + ) +# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) +# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced") +#else +# define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE +#endif + +#if defined(JSON_HEDLEY_NEVER_INLINE) + #undef JSON_HEDLEY_NEVER_INLINE +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) + #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__)) +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) +#elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline") +#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never") +#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0) + #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline)) +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0) + #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) +#else + #define JSON_HEDLEY_NEVER_INLINE +#endif + +#if defined(JSON_HEDLEY_PRIVATE) + #undef JSON_HEDLEY_PRIVATE +#endif +#if defined(JSON_HEDLEY_PUBLIC) + #undef JSON_HEDLEY_PUBLIC +#endif +#if defined(JSON_HEDLEY_IMPORT) + #undef JSON_HEDLEY_IMPORT +#endif +#if defined(_WIN32) || defined(__CYGWIN__) +# define JSON_HEDLEY_PRIVATE +# define JSON_HEDLEY_PUBLIC __declspec(dllexport) +# define JSON_HEDLEY_IMPORT __declspec(dllimport) +#else +# if \ + JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ + ( \ + defined(__TI_EABI__) && \ + ( \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \ + ) \ + ) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) +# define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden"))) +# define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default"))) +# else +# define JSON_HEDLEY_PRIVATE +# define JSON_HEDLEY_PUBLIC +# endif +# define JSON_HEDLEY_IMPORT extern +#endif + +#if defined(JSON_HEDLEY_NO_THROW) + #undef JSON_HEDLEY_NO_THROW +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__)) +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) + #define JSON_HEDLEY_NO_THROW __declspec(nothrow) +#else + #define JSON_HEDLEY_NO_THROW +#endif + +#if defined(JSON_HEDLEY_FALL_THROUGH) + #undef JSON_HEDLEY_FALL_THROUGH +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__)) +#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough) + #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]]) +#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough) + #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]]) +#elif defined(__fallthrough) /* SAL */ + #define JSON_HEDLEY_FALL_THROUGH __fallthrough +#else + #define JSON_HEDLEY_FALL_THROUGH +#endif + +#if defined(JSON_HEDLEY_RETURNS_NON_NULL) + #undef JSON_HEDLEY_RETURNS_NON_NULL +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__)) +#elif defined(_Ret_notnull_) /* SAL */ + #define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_ +#else + #define JSON_HEDLEY_RETURNS_NON_NULL +#endif + +#if defined(JSON_HEDLEY_ARRAY_PARAM) + #undef JSON_HEDLEY_ARRAY_PARAM +#endif +#if \ + defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ + !defined(__STDC_NO_VLA__) && \ + !defined(__cplusplus) && \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_TINYC_VERSION) + #define JSON_HEDLEY_ARRAY_PARAM(name) (name) +#else + #define JSON_HEDLEY_ARRAY_PARAM(name) +#endif + +#if defined(JSON_HEDLEY_IS_CONSTANT) + #undef JSON_HEDLEY_IS_CONSTANT +#endif +#if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR) + #undef JSON_HEDLEY_REQUIRE_CONSTEXPR +#endif +/* JSON_HEDLEY_IS_CONSTEXPR_ is for + HEDLEY INTERNAL USE ONLY. API subject to change without notice. */ +#if defined(JSON_HEDLEY_IS_CONSTEXPR_) + #undef JSON_HEDLEY_IS_CONSTEXPR_ +#endif +#if \ + JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr) +#endif +#if !defined(__cplusplus) +# if \ + JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24) +#if defined(__INTPTR_TYPE__) + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*) +#else + #include + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*) +#endif +# elif \ + ( \ + defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \ + !defined(JSON_HEDLEY_SUNPRO_VERSION) && \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_IAR_VERSION)) || \ + (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0) +#if defined(__INTPTR_TYPE__) + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0) +#else + #include + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0) +#endif +# elif \ + defined(JSON_HEDLEY_GCC_VERSION) || \ + defined(JSON_HEDLEY_INTEL_VERSION) || \ + defined(JSON_HEDLEY_TINYC_VERSION) || \ + defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \ + defined(JSON_HEDLEY_TI_CL2000_VERSION) || \ + defined(JSON_HEDLEY_TI_CL6X_VERSION) || \ + defined(JSON_HEDLEY_TI_CL7X_VERSION) || \ + defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \ + defined(__clang__) +# define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \ + sizeof(void) != \ + sizeof(*( \ + 1 ? \ + ((void*) ((expr) * 0L) ) : \ +((struct { char v[sizeof(void) * 2]; } *) 1) \ + ) \ + ) \ + ) +# endif +#endif +#if defined(JSON_HEDLEY_IS_CONSTEXPR_) + #if !defined(JSON_HEDLEY_IS_CONSTANT) + #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr) + #endif + #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1)) +#else + #if !defined(JSON_HEDLEY_IS_CONSTANT) + #define JSON_HEDLEY_IS_CONSTANT(expr) (0) + #endif + #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr) +#endif + +#if defined(JSON_HEDLEY_BEGIN_C_DECLS) + #undef JSON_HEDLEY_BEGIN_C_DECLS +#endif +#if defined(JSON_HEDLEY_END_C_DECLS) + #undef JSON_HEDLEY_END_C_DECLS +#endif +#if defined(JSON_HEDLEY_C_DECL) + #undef JSON_HEDLEY_C_DECL +#endif +#if defined(__cplusplus) + #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" { + #define JSON_HEDLEY_END_C_DECLS } + #define JSON_HEDLEY_C_DECL extern "C" +#else + #define JSON_HEDLEY_BEGIN_C_DECLS + #define JSON_HEDLEY_END_C_DECLS + #define JSON_HEDLEY_C_DECL +#endif + +#if defined(JSON_HEDLEY_STATIC_ASSERT) + #undef JSON_HEDLEY_STATIC_ASSERT +#endif +#if \ + !defined(__cplusplus) && ( \ + (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \ + (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + defined(_Static_assert) \ + ) +# define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message) +#elif \ + (defined(__cplusplus) && (__cplusplus >= 201103L)) || \ + JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) +# define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message)) +#else +# define JSON_HEDLEY_STATIC_ASSERT(expr, message) +#endif + +#if defined(JSON_HEDLEY_NULL) + #undef JSON_HEDLEY_NULL +#endif +#if defined(__cplusplus) + #if __cplusplus >= 201103L + #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr) + #elif defined(NULL) + #define JSON_HEDLEY_NULL NULL + #else + #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0) + #endif +#elif defined(NULL) + #define JSON_HEDLEY_NULL NULL +#else + #define JSON_HEDLEY_NULL ((void*) 0) +#endif + +#if defined(JSON_HEDLEY_MESSAGE) + #undef JSON_HEDLEY_MESSAGE +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") +# define JSON_HEDLEY_MESSAGE(msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ + JSON_HEDLEY_PRAGMA(message msg) \ + JSON_HEDLEY_DIAGNOSTIC_POP +#elif \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) +# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg) +#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) +# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg) +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) +# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0) +# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) +#else +# define JSON_HEDLEY_MESSAGE(msg) +#endif + +#if defined(JSON_HEDLEY_WARNING) + #undef JSON_HEDLEY_WARNING +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") +# define JSON_HEDLEY_WARNING(msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ + JSON_HEDLEY_PRAGMA(clang warning msg) \ + JSON_HEDLEY_DIAGNOSTIC_POP +#elif \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) +# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg) +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) +# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg)) +#else +# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg) +#endif + +#if defined(JSON_HEDLEY_REQUIRE) + #undef JSON_HEDLEY_REQUIRE +#endif +#if defined(JSON_HEDLEY_REQUIRE_MSG) + #undef JSON_HEDLEY_REQUIRE_MSG +#endif +#if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if) +# if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat") +# define JSON_HEDLEY_REQUIRE(expr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ + __attribute__((diagnose_if(!(expr), #expr, "error"))) \ + JSON_HEDLEY_DIAGNOSTIC_POP +# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ + __attribute__((diagnose_if(!(expr), msg, "error"))) \ + JSON_HEDLEY_DIAGNOSTIC_POP +# else +# define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error"))) +# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error"))) +# endif +#else +# define JSON_HEDLEY_REQUIRE(expr) +# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) +#endif + +#if defined(JSON_HEDLEY_FLAGS) + #undef JSON_HEDLEY_FLAGS +#endif +#if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion")) + #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__)) +#else + #define JSON_HEDLEY_FLAGS +#endif + +#if defined(JSON_HEDLEY_FLAGS_CAST) + #undef JSON_HEDLEY_FLAGS_CAST +#endif +#if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0) +# define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("warning(disable:188)") \ + ((T) (expr)); \ + JSON_HEDLEY_DIAGNOSTIC_POP \ + })) +#else +# define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr) +#endif + +#if defined(JSON_HEDLEY_EMPTY_BASES) + #undef JSON_HEDLEY_EMPTY_BASES +#endif +#if \ + (JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases) +#else + #define JSON_HEDLEY_EMPTY_BASES +#endif + +/* Remaining macros are deprecated. */ + +#if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK) + #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK +#endif +#if defined(__clang__) + #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0) +#else + #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE +#endif +#define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) + +#if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE +#endif +#define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) + +#if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN) + #undef JSON_HEDLEY_CLANG_HAS_BUILTIN +#endif +#define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin) + +#if defined(JSON_HEDLEY_CLANG_HAS_FEATURE) + #undef JSON_HEDLEY_CLANG_HAS_FEATURE +#endif +#define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature) + +#if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION) + #undef JSON_HEDLEY_CLANG_HAS_EXTENSION +#endif +#define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension) + +#if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE +#endif +#define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) + +#if defined(JSON_HEDLEY_CLANG_HAS_WARNING) + #undef JSON_HEDLEY_CLANG_HAS_WARNING +#endif +#define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning) + +#endif /* !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < X) */ + + +// This file contains all internal macro definitions (except those affecting ABI) +// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them + +// #include + + +// exclude unsupported compilers +#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) + #if defined(__clang__) + #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400 + #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" + #endif + #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) + #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800 + #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers" + #endif + #endif +#endif + +// C++ language standard detection +// if the user manually specified the used c++ version this is skipped +#if !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11) + #if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) + #define JSON_HAS_CPP_20 + #define JSON_HAS_CPP_17 + #define JSON_HAS_CPP_14 + #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 + #define JSON_HAS_CPP_17 + #define JSON_HAS_CPP_14 + #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1) + #define JSON_HAS_CPP_14 + #endif + // the cpp 11 flag is always specified because it is the minimal required version + #define JSON_HAS_CPP_11 +#endif + +#ifdef __has_include + #if __has_include() + #include + #endif +#endif + +#if !defined(JSON_HAS_FILESYSTEM) && !defined(JSON_HAS_EXPERIMENTAL_FILESYSTEM) + #ifdef JSON_HAS_CPP_17 + #if defined(__cpp_lib_filesystem) + #define JSON_HAS_FILESYSTEM 1 + #elif defined(__cpp_lib_experimental_filesystem) + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 + #elif !defined(__has_include) + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 + #elif __has_include() + #define JSON_HAS_FILESYSTEM 1 + #elif __has_include() + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 + #endif + + // std::filesystem does not work on MinGW GCC 8: https://sourceforge.net/p/mingw-w64/bugs/737/ + #if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ == 8 + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #endif + + // no filesystem support before GCC 8: https://en.cppreference.com/w/cpp/compiler_support + #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 8 + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #endif + + // no filesystem support before Clang 7: https://en.cppreference.com/w/cpp/compiler_support + #if defined(__clang_major__) && __clang_major__ < 7 + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #endif + + // no filesystem support before MSVC 19.14: https://en.cppreference.com/w/cpp/compiler_support + #if defined(_MSC_VER) && _MSC_VER < 1914 + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #endif + + // no filesystem support before iOS 13 + #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000 + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #endif + + // no filesystem support before macOS Catalina + #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500 + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #endif + #endif +#endif + +#ifndef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 0 +#endif + +#ifndef JSON_HAS_FILESYSTEM + #define JSON_HAS_FILESYSTEM 0 +#endif + +#ifndef JSON_HAS_THREE_WAY_COMPARISON + #if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L \ + && defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L + #define JSON_HAS_THREE_WAY_COMPARISON 1 + #else + #define JSON_HAS_THREE_WAY_COMPARISON 0 + #endif +#endif + +#ifndef JSON_HAS_RANGES + // ranges header shipping in GCC 11.1.0 (released 2021-04-27) has syntax error + #if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427 + #define JSON_HAS_RANGES 0 + #elif defined(__cpp_lib_ranges) + #define JSON_HAS_RANGES 1 + #else + #define JSON_HAS_RANGES 0 + #endif +#endif + +#ifndef JSON_HAS_STATIC_RTTI + #if !defined(_HAS_STATIC_RTTI) || _HAS_STATIC_RTTI != 0 + #define JSON_HAS_STATIC_RTTI 1 + #else + #define JSON_HAS_STATIC_RTTI 0 + #endif +#endif + +#ifdef JSON_HAS_CPP_17 + #define JSON_INLINE_VARIABLE inline +#else + #define JSON_INLINE_VARIABLE +#endif + +#if JSON_HEDLEY_HAS_ATTRIBUTE(no_unique_address) + #define JSON_NO_UNIQUE_ADDRESS [[no_unique_address]] +#else + #define JSON_NO_UNIQUE_ADDRESS +#endif + +// disable documentation warnings on clang +#if defined(__clang__) + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdocumentation" + #pragma clang diagnostic ignored "-Wdocumentation-unknown-command" +#endif + +// allow disabling exceptions +#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION) + #define JSON_THROW(exception) throw exception + #define JSON_TRY try + #define JSON_CATCH(exception) catch(exception) + #define JSON_INTERNAL_CATCH(exception) catch(exception) +#else + #include + #define JSON_THROW(exception) std::abort() + #define JSON_TRY if(true) + #define JSON_CATCH(exception) if(false) + #define JSON_INTERNAL_CATCH(exception) if(false) +#endif + +// override exception macros +#if defined(JSON_THROW_USER) + #undef JSON_THROW + #define JSON_THROW JSON_THROW_USER +#endif +#if defined(JSON_TRY_USER) + #undef JSON_TRY + #define JSON_TRY JSON_TRY_USER +#endif +#if defined(JSON_CATCH_USER) + #undef JSON_CATCH + #define JSON_CATCH JSON_CATCH_USER + #undef JSON_INTERNAL_CATCH + #define JSON_INTERNAL_CATCH JSON_CATCH_USER +#endif +#if defined(JSON_INTERNAL_CATCH_USER) + #undef JSON_INTERNAL_CATCH + #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER +#endif + +// allow overriding assert +#if !defined(JSON_ASSERT) + #include // assert + #define JSON_ASSERT(x) assert(x) +#endif + +// allow to access some private functions (needed by the test suite) +#if defined(JSON_TESTS_PRIVATE) + #define JSON_PRIVATE_UNLESS_TESTED public +#else + #define JSON_PRIVATE_UNLESS_TESTED private +#endif + +/*! +@brief macro to briefly define a mapping between an enum and JSON +@def NLOHMANN_JSON_SERIALIZE_ENUM +@since version 3.4.0 +*/ +#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \ + template \ + inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \ + { \ + static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ + static const std::pair m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), \ + [e](const std::pair& ej_pair) -> bool \ + { \ + return ej_pair.first == e; \ + }); \ + j = ((it != std::end(m)) ? it : std::begin(m))->second; \ + } \ + template \ + inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \ + { \ + static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ + static const std::pair m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), \ + [&j](const std::pair& ej_pair) -> bool \ + { \ + return ej_pair.second == j; \ + }); \ + e = ((it != std::end(m)) ? it : std::begin(m))->first; \ + } + +// Ugly macros to avoid uglier copy-paste when specializing basic_json. They +// may be removed in the future once the class is split. + +#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \ + template class ObjectType, \ + template class ArrayType, \ + class StringType, class BooleanType, class NumberIntegerType, \ + class NumberUnsignedType, class NumberFloatType, \ + template class AllocatorType, \ + template class JSONSerializer, \ + class BinaryType, \ + class CustomBaseClass> + +#define NLOHMANN_BASIC_JSON_TPL \ + basic_json + +// Macros to simplify conversion from/to types + +#define NLOHMANN_JSON_EXPAND( x ) x +#define NLOHMANN_JSON_GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, NAME,...) NAME +#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \ + NLOHMANN_JSON_PASTE64, \ + NLOHMANN_JSON_PASTE63, \ + NLOHMANN_JSON_PASTE62, \ + NLOHMANN_JSON_PASTE61, \ + NLOHMANN_JSON_PASTE60, \ + NLOHMANN_JSON_PASTE59, \ + NLOHMANN_JSON_PASTE58, \ + NLOHMANN_JSON_PASTE57, \ + NLOHMANN_JSON_PASTE56, \ + NLOHMANN_JSON_PASTE55, \ + NLOHMANN_JSON_PASTE54, \ + NLOHMANN_JSON_PASTE53, \ + NLOHMANN_JSON_PASTE52, \ + NLOHMANN_JSON_PASTE51, \ + NLOHMANN_JSON_PASTE50, \ + NLOHMANN_JSON_PASTE49, \ + NLOHMANN_JSON_PASTE48, \ + NLOHMANN_JSON_PASTE47, \ + NLOHMANN_JSON_PASTE46, \ + NLOHMANN_JSON_PASTE45, \ + NLOHMANN_JSON_PASTE44, \ + NLOHMANN_JSON_PASTE43, \ + NLOHMANN_JSON_PASTE42, \ + NLOHMANN_JSON_PASTE41, \ + NLOHMANN_JSON_PASTE40, \ + NLOHMANN_JSON_PASTE39, \ + NLOHMANN_JSON_PASTE38, \ + NLOHMANN_JSON_PASTE37, \ + NLOHMANN_JSON_PASTE36, \ + NLOHMANN_JSON_PASTE35, \ + NLOHMANN_JSON_PASTE34, \ + NLOHMANN_JSON_PASTE33, \ + NLOHMANN_JSON_PASTE32, \ + NLOHMANN_JSON_PASTE31, \ + NLOHMANN_JSON_PASTE30, \ + NLOHMANN_JSON_PASTE29, \ + NLOHMANN_JSON_PASTE28, \ + NLOHMANN_JSON_PASTE27, \ + NLOHMANN_JSON_PASTE26, \ + NLOHMANN_JSON_PASTE25, \ + NLOHMANN_JSON_PASTE24, \ + NLOHMANN_JSON_PASTE23, \ + NLOHMANN_JSON_PASTE22, \ + NLOHMANN_JSON_PASTE21, \ + NLOHMANN_JSON_PASTE20, \ + NLOHMANN_JSON_PASTE19, \ + NLOHMANN_JSON_PASTE18, \ + NLOHMANN_JSON_PASTE17, \ + NLOHMANN_JSON_PASTE16, \ + NLOHMANN_JSON_PASTE15, \ + NLOHMANN_JSON_PASTE14, \ + NLOHMANN_JSON_PASTE13, \ + NLOHMANN_JSON_PASTE12, \ + NLOHMANN_JSON_PASTE11, \ + NLOHMANN_JSON_PASTE10, \ + NLOHMANN_JSON_PASTE9, \ + NLOHMANN_JSON_PASTE8, \ + NLOHMANN_JSON_PASTE7, \ + NLOHMANN_JSON_PASTE6, \ + NLOHMANN_JSON_PASTE5, \ + NLOHMANN_JSON_PASTE4, \ + NLOHMANN_JSON_PASTE3, \ + NLOHMANN_JSON_PASTE2, \ + NLOHMANN_JSON_PASTE1)(__VA_ARGS__)) +#define NLOHMANN_JSON_PASTE2(func, v1) func(v1) +#define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2) +#define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3) +#define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4) +#define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5) +#define NLOHMANN_JSON_PASTE7(func, v1, v2, v3, v4, v5, v6) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE6(func, v2, v3, v4, v5, v6) +#define NLOHMANN_JSON_PASTE8(func, v1, v2, v3, v4, v5, v6, v7) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE7(func, v2, v3, v4, v5, v6, v7) +#define NLOHMANN_JSON_PASTE9(func, v1, v2, v3, v4, v5, v6, v7, v8) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE8(func, v2, v3, v4, v5, v6, v7, v8) +#define NLOHMANN_JSON_PASTE10(func, v1, v2, v3, v4, v5, v6, v7, v8, v9) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE9(func, v2, v3, v4, v5, v6, v7, v8, v9) +#define NLOHMANN_JSON_PASTE11(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE10(func, v2, v3, v4, v5, v6, v7, v8, v9, v10) +#define NLOHMANN_JSON_PASTE12(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE11(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) +#define NLOHMANN_JSON_PASTE13(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE12(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) +#define NLOHMANN_JSON_PASTE14(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE13(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) +#define NLOHMANN_JSON_PASTE15(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE14(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) +#define NLOHMANN_JSON_PASTE16(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE15(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) +#define NLOHMANN_JSON_PASTE17(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE16(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) +#define NLOHMANN_JSON_PASTE18(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE17(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) +#define NLOHMANN_JSON_PASTE19(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE18(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) +#define NLOHMANN_JSON_PASTE20(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE19(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) +#define NLOHMANN_JSON_PASTE21(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE20(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) +#define NLOHMANN_JSON_PASTE22(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE21(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) +#define NLOHMANN_JSON_PASTE23(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE22(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22) +#define NLOHMANN_JSON_PASTE24(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE23(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23) +#define NLOHMANN_JSON_PASTE25(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE24(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24) +#define NLOHMANN_JSON_PASTE26(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE25(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25) +#define NLOHMANN_JSON_PASTE27(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE26(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26) +#define NLOHMANN_JSON_PASTE28(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE27(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27) +#define NLOHMANN_JSON_PASTE29(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE28(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28) +#define NLOHMANN_JSON_PASTE30(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE29(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29) +#define NLOHMANN_JSON_PASTE31(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE30(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30) +#define NLOHMANN_JSON_PASTE32(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE31(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31) +#define NLOHMANN_JSON_PASTE33(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE32(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32) +#define NLOHMANN_JSON_PASTE34(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE33(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33) +#define NLOHMANN_JSON_PASTE35(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE34(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34) +#define NLOHMANN_JSON_PASTE36(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE35(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35) +#define NLOHMANN_JSON_PASTE37(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE36(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36) +#define NLOHMANN_JSON_PASTE38(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE37(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37) +#define NLOHMANN_JSON_PASTE39(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE38(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38) +#define NLOHMANN_JSON_PASTE40(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE39(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39) +#define NLOHMANN_JSON_PASTE41(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE40(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40) +#define NLOHMANN_JSON_PASTE42(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE41(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41) +#define NLOHMANN_JSON_PASTE43(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE42(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42) +#define NLOHMANN_JSON_PASTE44(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE43(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43) +#define NLOHMANN_JSON_PASTE45(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE44(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44) +#define NLOHMANN_JSON_PASTE46(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE45(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45) +#define NLOHMANN_JSON_PASTE47(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE46(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46) +#define NLOHMANN_JSON_PASTE48(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE47(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47) +#define NLOHMANN_JSON_PASTE49(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE48(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48) +#define NLOHMANN_JSON_PASTE50(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE49(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49) +#define NLOHMANN_JSON_PASTE51(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE50(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50) +#define NLOHMANN_JSON_PASTE52(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE51(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51) +#define NLOHMANN_JSON_PASTE53(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE52(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52) +#define NLOHMANN_JSON_PASTE54(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE53(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53) +#define NLOHMANN_JSON_PASTE55(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE54(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54) +#define NLOHMANN_JSON_PASTE56(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE55(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55) +#define NLOHMANN_JSON_PASTE57(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE56(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56) +#define NLOHMANN_JSON_PASTE58(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE57(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57) +#define NLOHMANN_JSON_PASTE59(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE58(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58) +#define NLOHMANN_JSON_PASTE60(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE59(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59) +#define NLOHMANN_JSON_PASTE61(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE60(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60) +#define NLOHMANN_JSON_PASTE62(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE61(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61) +#define NLOHMANN_JSON_PASTE63(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE62(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62) +#define NLOHMANN_JSON_PASTE64(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE63(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63) + +#define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1; +#define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1); +#define NLOHMANN_JSON_FROM_WITH_DEFAULT(v1) nlohmann_json_t.v1 = nlohmann_json_j.value(#v1, nlohmann_json_default_obj.v1); + +/*! +@brief macro +@def NLOHMANN_DEFINE_TYPE_INTRUSIVE +@since version 3.9.0 +*/ +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \ + friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } + +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \ + friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } + +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \ + friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } + +/*! +@brief macro +@def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE +@since version 3.9.0 +*/ +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \ + inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } + +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \ + inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } + +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \ + inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } + +// inspired from https://stackoverflow.com/a/26745591 +// allows to call any std function as if (e.g. with begin): +// using std::begin; begin(x); +// +// it allows using the detected idiom to retrieve the return type +// of such an expression +#define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name) \ + namespace detail { \ + using std::std_name; \ + \ + template \ + using result_of_##std_name = decltype(std_name(std::declval()...)); \ + } \ + \ + namespace detail2 { \ + struct std_name##_tag \ + { \ + }; \ + \ + template \ + std_name##_tag std_name(T&&...); \ + \ + template \ + using result_of_##std_name = decltype(std_name(std::declval()...)); \ + \ + template \ + struct would_call_std_##std_name \ + { \ + static constexpr auto const value = ::nlohmann::detail:: \ + is_detected_exact::value; \ + }; \ + } /* namespace detail2 */ \ + \ + template \ + struct would_call_std_##std_name : detail2::would_call_std_##std_name \ + { \ + } + +#ifndef JSON_USE_IMPLICIT_CONVERSIONS + #define JSON_USE_IMPLICIT_CONVERSIONS 1 +#endif + +#if JSON_USE_IMPLICIT_CONVERSIONS + #define JSON_EXPLICIT +#else + #define JSON_EXPLICIT explicit +#endif + +#ifndef JSON_DISABLE_ENUM_SERIALIZATION + #define JSON_DISABLE_ENUM_SERIALIZATION 0 +#endif + +#ifndef JSON_USE_GLOBAL_UDLS + #define JSON_USE_GLOBAL_UDLS 1 +#endif + +#if JSON_HAS_THREE_WAY_COMPARISON + #include // partial_ordering +#endif + +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ + +/////////////////////////// +// JSON type enumeration // +/////////////////////////// + +/*! +@brief the JSON type enumeration + +This enumeration collects the different JSON types. It is internally used to +distinguish the stored values, and the functions @ref basic_json::is_null(), +@ref basic_json::is_object(), @ref basic_json::is_array(), +@ref basic_json::is_string(), @ref basic_json::is_boolean(), +@ref basic_json::is_number() (with @ref basic_json::is_number_integer(), +@ref basic_json::is_number_unsigned(), and @ref basic_json::is_number_float()), +@ref basic_json::is_discarded(), @ref basic_json::is_primitive(), and +@ref basic_json::is_structured() rely on it. + +@note There are three enumeration entries (number_integer, number_unsigned, and +number_float), because the library distinguishes these three types for numbers: +@ref basic_json::number_unsigned_t is used for unsigned integers, +@ref basic_json::number_integer_t is used for signed integers, and +@ref basic_json::number_float_t is used for floating-point numbers or to +approximate integers which do not fit in the limits of their respective type. + +@sa see @ref basic_json::basic_json(const value_t value_type) -- create a JSON +value with the default value for a given type + +@since version 1.0.0 +*/ +enum class value_t : std::uint8_t +{ + null, ///< null value + object, ///< object (unordered set of name/value pairs) + array, ///< array (ordered collection of values) + string, ///< string value + boolean, ///< boolean value + number_integer, ///< number value (signed integer) + number_unsigned, ///< number value (unsigned integer) + number_float, ///< number value (floating-point) + binary, ///< binary array (ordered collection of bytes) + discarded ///< discarded by the parser callback function +}; + +/*! +@brief comparison operator for JSON types + +Returns an ordering that is similar to Python: +- order: null < boolean < number < object < array < string < binary +- furthermore, each type is not smaller than itself +- discarded values are not comparable +- binary is represented as a b"" string in python and directly comparable to a + string; however, making a binary array directly comparable with a string would + be surprising behavior in a JSON file. + +@since version 1.0.0 +*/ +#if JSON_HAS_THREE_WAY_COMPARISON + inline std::partial_ordering operator<=>(const value_t lhs, const value_t rhs) noexcept // *NOPAD* +#else + inline bool operator<(const value_t lhs, const value_t rhs) noexcept +#endif +{ + static constexpr std::array order = {{ + 0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */, + 1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */, + 6 /* binary */ + } + }; + + const auto l_index = static_cast(lhs); + const auto r_index = static_cast(rhs); +#if JSON_HAS_THREE_WAY_COMPARISON + if (l_index < order.size() && r_index < order.size()) + { + return order[l_index] <=> order[r_index]; // *NOPAD* + } + return std::partial_ordering::unordered; +#else + return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index]; +#endif +} + +// GCC selects the built-in operator< over an operator rewritten from +// a user-defined spaceship operator +// Clang, MSVC, and ICC select the rewritten candidate +// (see GCC bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105200) +#if JSON_HAS_THREE_WAY_COMPARISON && defined(__GNUC__) +inline bool operator<(const value_t lhs, const value_t rhs) noexcept +{ + return std::is_lt(lhs <=> rhs); // *NOPAD* +} +#endif + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ + +/*! +@brief replace all occurrences of a substring by another string + +@param[in,out] s the string to manipulate; changed so that all + occurrences of @a f are replaced with @a t +@param[in] f the substring to replace with @a t +@param[in] t the string to replace @a f + +@pre The search string @a f must not be empty. **This precondition is +enforced with an assertion.** + +@since version 2.0.0 +*/ +template +inline void replace_substring(StringType& s, const StringType& f, + const StringType& t) +{ + JSON_ASSERT(!f.empty()); + for (auto pos = s.find(f); // find first occurrence of f + pos != StringType::npos; // make sure f was found + s.replace(pos, f.size(), t), // replace with t, and + pos = s.find(f, pos + t.size())) // find next occurrence of f + {} +} + +/*! + * @brief string escaping as described in RFC 6901 (Sect. 4) + * @param[in] s string to escape + * @return escaped string + * + * Note the order of escaping "~" to "~0" and "/" to "~1" is important. + */ +template +inline StringType escape(StringType s) +{ + replace_substring(s, StringType{"~"}, StringType{"~0"}); + replace_substring(s, StringType{"/"}, StringType{"~1"}); + return s; +} + +/*! + * @brief string unescaping as described in RFC 6901 (Sect. 4) + * @param[in] s string to unescape + * @return unescaped string + * + * Note the order of escaping "~1" to "/" and "~0" to "~" is important. + */ +template +static void unescape(StringType& s) +{ + replace_substring(s, StringType{"~1"}, StringType{"/"}); + replace_substring(s, StringType{"~0"}, StringType{"~"}); +} + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include // size_t + +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ + +/// struct to capture the start position of the current token +struct position_t +{ + /// the total number of characters read + std::size_t chars_read_total = 0; + /// the number of characters read in the current line + std::size_t chars_read_current_line = 0; + /// the number of lines read + std::size_t lines_read = 0; + + /// conversion to size_t to preserve SAX interface + constexpr operator size_t() const + { + return chars_read_total; + } +}; + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END + +// #include + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-FileCopyrightText: 2018 The Abseil Authors +// SPDX-License-Identifier: MIT + + + +#include // array +#include // size_t +#include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type +#include // index_sequence, make_index_sequence, index_sequence_for + +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ + +template +using uncvref_t = typename std::remove_cv::type>::type; + +#ifdef JSON_HAS_CPP_14 + +// the following utilities are natively available in C++14 +using std::enable_if_t; +using std::index_sequence; +using std::make_index_sequence; +using std::index_sequence_for; + +#else + +// alias templates to reduce boilerplate +template +using enable_if_t = typename std::enable_if::type; + +// The following code is taken from https://github.com/abseil/abseil-cpp/blob/10cb35e459f5ecca5b2ff107635da0bfa41011b4/absl/utility/utility.h +// which is part of Google Abseil (https://github.com/abseil/abseil-cpp), licensed under the Apache License 2.0. + +//// START OF CODE FROM GOOGLE ABSEIL + +// integer_sequence +// +// Class template representing a compile-time integer sequence. An instantiation +// of `integer_sequence` has a sequence of integers encoded in its +// type through its template arguments (which is a common need when +// working with C++11 variadic templates). `absl::integer_sequence` is designed +// to be a drop-in replacement for C++14's `std::integer_sequence`. +// +// Example: +// +// template< class T, T... Ints > +// void user_function(integer_sequence); +// +// int main() +// { +// // user_function's `T` will be deduced to `int` and `Ints...` +// // will be deduced to `0, 1, 2, 3, 4`. +// user_function(make_integer_sequence()); +// } +template +struct integer_sequence +{ + using value_type = T; + static constexpr std::size_t size() noexcept + { + return sizeof...(Ints); + } +}; + +// index_sequence +// +// A helper template for an `integer_sequence` of `size_t`, +// `absl::index_sequence` is designed to be a drop-in replacement for C++14's +// `std::index_sequence`. +template +using index_sequence = integer_sequence; + +namespace utility_internal +{ + +template +struct Extend; + +// Note that SeqSize == sizeof...(Ints). It's passed explicitly for efficiency. +template +struct Extend, SeqSize, 0> +{ + using type = integer_sequence < T, Ints..., (Ints + SeqSize)... >; +}; + +template +struct Extend, SeqSize, 1> +{ + using type = integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >; +}; + +// Recursion helper for 'make_integer_sequence'. +// 'Gen::type' is an alias for 'integer_sequence'. +template +struct Gen +{ + using type = + typename Extend < typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type; +}; + +template +struct Gen +{ + using type = integer_sequence; +}; + +} // namespace utility_internal + +// Compile-time sequences of integers + +// make_integer_sequence +// +// This template alias is equivalent to +// `integer_sequence`, and is designed to be a drop-in +// replacement for C++14's `std::make_integer_sequence`. +template +using make_integer_sequence = typename utility_internal::Gen::type; + +// make_index_sequence +// +// This template alias is equivalent to `index_sequence<0, 1, ..., N-1>`, +// and is designed to be a drop-in replacement for C++14's +// `std::make_index_sequence`. +template +using make_index_sequence = make_integer_sequence; + +// index_sequence_for +// +// Converts a typename pack into an index sequence of the same length, and +// is designed to be a drop-in replacement for C++14's +// `std::index_sequence_for()` +template +using index_sequence_for = make_index_sequence; + +//// END OF CODE FROM GOOGLE ABSEIL + +#endif + +// dispatch utility (taken from ranges-v3) +template struct priority_tag : priority_tag < N - 1 > {}; +template<> struct priority_tag<0> {}; + +// taken from ranges-v3 +template +struct static_const +{ + static JSON_INLINE_VARIABLE constexpr T value{}; +}; + +#ifndef JSON_HAS_CPP_17 + template + constexpr T static_const::value; +#endif + +template +inline constexpr std::array make_array(Args&& ... args) +{ + return std::array {{static_cast(std::forward(args))...}}; +} + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include // numeric_limits +#include // false_type, is_constructible, is_integral, is_same, true_type +#include // declval +#include // tuple +#include // char_traits + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include // random_access_iterator_tag + +// #include + +// #include + +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ + +template +struct iterator_types {}; + +template +struct iterator_types < + It, + void_t> +{ + using difference_type = typename It::difference_type; + using value_type = typename It::value_type; + using pointer = typename It::pointer; + using reference = typename It::reference; + using iterator_category = typename It::iterator_category; +}; + +// This is required as some compilers implement std::iterator_traits in a way that +// doesn't work with SFINAE. See https://github.com/nlohmann/json/issues/1341. +template +struct iterator_traits +{ +}; + +template +struct iterator_traits < T, enable_if_t < !std::is_pointer::value >> + : iterator_types +{ +}; + +template +struct iterator_traits::value>> +{ + using iterator_category = std::random_access_iterator_tag; + using value_type = T; + using difference_type = ptrdiff_t; + using pointer = T*; + using reference = T&; +}; + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END + +// #include + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN + +NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin); + +NLOHMANN_JSON_NAMESPACE_END + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN + +NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end); + +NLOHMANN_JSON_NAMESPACE_END + +// #include + +// #include + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.3 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann +// SPDX-License-Identifier: MIT + +#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_ + #define INCLUDE_NLOHMANN_JSON_FWD_HPP_ + + #include // int64_t, uint64_t + #include // map + #include // allocator + #include // string + #include // vector + + // #include + + + /*! + @brief namespace for Niels Lohmann + @see https://github.com/nlohmann + @since version 1.0.0 + */ + NLOHMANN_JSON_NAMESPACE_BEGIN + + /*! + @brief default JSONSerializer template argument + + This serializer ignores the template arguments and uses ADL + ([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)) + for serialization. + */ + template + struct adl_serializer; + + /// a class to store JSON values + /// @sa https://json.nlohmann.me/api/basic_json/ + template class ObjectType = + std::map, + template class ArrayType = std::vector, + class StringType = std::string, class BooleanType = bool, + class NumberIntegerType = std::int64_t, + class NumberUnsignedType = std::uint64_t, + class NumberFloatType = double, + template class AllocatorType = std::allocator, + template class JSONSerializer = + adl_serializer, + class BinaryType = std::vector, // cppcheck-suppress syntaxError + class CustomBaseClass = void> + class basic_json; + + /// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document + /// @sa https://json.nlohmann.me/api/json_pointer/ + template + class json_pointer; + + /*! + @brief default specialization + @sa https://json.nlohmann.me/api/json/ + */ + using json = basic_json<>; + + /// @brief a minimal map-like container that preserves insertion order + /// @sa https://json.nlohmann.me/api/ordered_map/ + template + struct ordered_map; + + /// @brief specialization that maintains the insertion order of object keys + /// @sa https://json.nlohmann.me/api/ordered_json/ + using ordered_json = basic_json; + + NLOHMANN_JSON_NAMESPACE_END + +#endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_ + + +NLOHMANN_JSON_NAMESPACE_BEGIN +/*! +@brief detail namespace with internal helper functions + +This namespace collects functions that should not be exposed, +implementations of some @ref basic_json methods, and meta-programming helpers. + +@since version 2.1.0 +*/ +namespace detail +{ + +///////////// +// helpers // +///////////// + +// Note to maintainers: +// +// Every trait in this file expects a non CV-qualified type. +// The only exceptions are in the 'aliases for detected' section +// (i.e. those of the form: decltype(T::member_function(std::declval()))) +// +// In this case, T has to be properly CV-qualified to constraint the function arguments +// (e.g. to_json(BasicJsonType&, const T&)) + +template struct is_basic_json : std::false_type {}; + +NLOHMANN_BASIC_JSON_TPL_DECLARATION +struct is_basic_json : std::true_type {}; + +// used by exceptions create() member functions +// true_type for pointer to possibly cv-qualified basic_json or std::nullptr_t +// false_type otherwise +template +struct is_basic_json_context : + std::integral_constant < bool, + is_basic_json::type>::type>::value + || std::is_same::value > +{}; + +////////////////////// +// json_ref helpers // +////////////////////// + +template +class json_ref; + +template +struct is_json_ref : std::false_type {}; + +template +struct is_json_ref> : std::true_type {}; + +////////////////////////// +// aliases for detected // +////////////////////////// + +template +using mapped_type_t = typename T::mapped_type; + +template +using key_type_t = typename T::key_type; + +template +using value_type_t = typename T::value_type; + +template +using difference_type_t = typename T::difference_type; + +template +using pointer_t = typename T::pointer; + +template +using reference_t = typename T::reference; + +template +using iterator_category_t = typename T::iterator_category; + +template +using to_json_function = decltype(T::to_json(std::declval()...)); + +template +using from_json_function = decltype(T::from_json(std::declval()...)); + +template +using get_template_function = decltype(std::declval().template get()); + +// trait checking if JSONSerializer::from_json(json const&, udt&) exists +template +struct has_from_json : std::false_type {}; + +// trait checking if j.get is valid +// use this trait instead of std::is_constructible or std::is_convertible, +// both rely on, or make use of implicit conversions, and thus fail when T +// has several constructors/operator= (see https://github.com/nlohmann/json/issues/958) +template +struct is_getable +{ + static constexpr bool value = is_detected::value; +}; + +template +struct has_from_json < BasicJsonType, T, enable_if_t < !is_basic_json::value >> +{ + using serializer = typename BasicJsonType::template json_serializer; + + static constexpr bool value = + is_detected_exact::value; +}; + +// This trait checks if JSONSerializer::from_json(json const&) exists +// this overload is used for non-default-constructible user-defined-types +template +struct has_non_default_from_json : std::false_type {}; + +template +struct has_non_default_from_json < BasicJsonType, T, enable_if_t < !is_basic_json::value >> +{ + using serializer = typename BasicJsonType::template json_serializer; + + static constexpr bool value = + is_detected_exact::value; +}; + +// This trait checks if BasicJsonType::json_serializer::to_json exists +// Do not evaluate the trait when T is a basic_json type, to avoid template instantiation infinite recursion. +template +struct has_to_json : std::false_type {}; + +template +struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json::value >> +{ + using serializer = typename BasicJsonType::template json_serializer; + + static constexpr bool value = + is_detected_exact::value; +}; + +template +using detect_key_compare = typename T::key_compare; + +template +struct has_key_compare : std::integral_constant::value> {}; + +// obtains the actual object key comparator +template +struct actual_object_comparator +{ + using object_t = typename BasicJsonType::object_t; + using object_comparator_t = typename BasicJsonType::default_object_comparator_t; + using type = typename std::conditional < has_key_compare::value, + typename object_t::key_compare, object_comparator_t>::type; +}; + +template +using actual_object_comparator_t = typename actual_object_comparator::type; + +///////////////// +// char_traits // +///////////////// + +// Primary template of char_traits calls std char_traits +template +struct char_traits : std::char_traits +{}; + +// Explicitly define char traits for unsigned char since it is not standard +template<> +struct char_traits : std::char_traits +{ + using char_type = unsigned char; + using int_type = uint64_t; + + // Redefine to_int_type function + static int_type to_int_type(char_type c) noexcept + { + return static_cast(c); + } + + static char_type to_char_type(int_type i) noexcept + { + return static_cast(i); + } + + static constexpr int_type eof() noexcept + { + return static_cast(EOF); + } +}; + +// Explicitly define char traits for signed char since it is not standard +template<> +struct char_traits : std::char_traits +{ + using char_type = signed char; + using int_type = uint64_t; + + // Redefine to_int_type function + static int_type to_int_type(char_type c) noexcept + { + return static_cast(c); + } + + static char_type to_char_type(int_type i) noexcept + { + return static_cast(i); + } + + static constexpr int_type eof() noexcept + { + return static_cast(EOF); + } +}; + +/////////////////// +// is_ functions // +/////////////////// + +// https://en.cppreference.com/w/cpp/types/conjunction +template struct conjunction : std::true_type { }; +template struct conjunction : B { }; +template +struct conjunction +: std::conditional(B::value), conjunction, B>::type {}; + +// https://en.cppreference.com/w/cpp/types/negation +template struct negation : std::integral_constant < bool, !B::value > { }; + +// Reimplementation of is_constructible and is_default_constructible, due to them being broken for +// std::pair and std::tuple until LWG 2367 fix (see https://cplusplus.github.io/LWG/lwg-defects.html#2367). +// This causes compile errors in e.g. clang 3.5 or gcc 4.9. +template +struct is_default_constructible : std::is_default_constructible {}; + +template +struct is_default_constructible> + : conjunction, is_default_constructible> {}; + +template +struct is_default_constructible> + : conjunction, is_default_constructible> {}; + +template +struct is_default_constructible> + : conjunction...> {}; + +template +struct is_default_constructible> + : conjunction...> {}; + +template +struct is_constructible : std::is_constructible {}; + +template +struct is_constructible> : is_default_constructible> {}; + +template +struct is_constructible> : is_default_constructible> {}; + +template +struct is_constructible> : is_default_constructible> {}; + +template +struct is_constructible> : is_default_constructible> {}; + +template +struct is_iterator_traits : std::false_type {}; + +template +struct is_iterator_traits> +{ + private: + using traits = iterator_traits; + + public: + static constexpr auto value = + is_detected::value && + is_detected::value && + is_detected::value && + is_detected::value && + is_detected::value; +}; + +template +struct is_range +{ + private: + using t_ref = typename std::add_lvalue_reference::type; + + using iterator = detected_t; + using sentinel = detected_t; + + // to be 100% correct, it should use https://en.cppreference.com/w/cpp/iterator/input_or_output_iterator + // and https://en.cppreference.com/w/cpp/iterator/sentinel_for + // but reimplementing these would be too much work, as a lot of other concepts are used underneath + static constexpr auto is_iterator_begin = + is_iterator_traits>::value; + + public: + static constexpr bool value = !std::is_same::value && !std::is_same::value && is_iterator_begin; +}; + +template +using iterator_t = enable_if_t::value, result_of_begin())>>; + +template +using range_value_t = value_type_t>>; + +// The following implementation of is_complete_type is taken from +// https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/ +// and is written by Xiang Fan who agreed to using it in this library. + +template +struct is_complete_type : std::false_type {}; + +template +struct is_complete_type : std::true_type {}; + +template +struct is_compatible_object_type_impl : std::false_type {}; + +template +struct is_compatible_object_type_impl < + BasicJsonType, CompatibleObjectType, + enable_if_t < is_detected::value&& + is_detected::value >> +{ + using object_t = typename BasicJsonType::object_t; + + // macOS's is_constructible does not play well with nonesuch... + static constexpr bool value = + is_constructible::value && + is_constructible::value; +}; + +template +struct is_compatible_object_type + : is_compatible_object_type_impl {}; + +template +struct is_constructible_object_type_impl : std::false_type {}; + +template +struct is_constructible_object_type_impl < + BasicJsonType, ConstructibleObjectType, + enable_if_t < is_detected::value&& + is_detected::value >> +{ + using object_t = typename BasicJsonType::object_t; + + static constexpr bool value = + (is_default_constructible::value && + (std::is_move_assignable::value || + std::is_copy_assignable::value) && + (is_constructible::value && + std::is_same < + typename object_t::mapped_type, + typename ConstructibleObjectType::mapped_type >::value)) || + (has_from_json::value || + has_non_default_from_json < + BasicJsonType, + typename ConstructibleObjectType::mapped_type >::value); +}; + +template +struct is_constructible_object_type + : is_constructible_object_type_impl {}; + +template +struct is_compatible_string_type +{ + static constexpr auto value = + is_constructible::value; +}; + +template +struct is_constructible_string_type +{ + // launder type through decltype() to fix compilation failure on ICPC +#ifdef __INTEL_COMPILER + using laundered_type = decltype(std::declval()); +#else + using laundered_type = ConstructibleStringType; +#endif + + static constexpr auto value = + conjunction < + is_constructible, + is_detected_exact>::value; +}; + +template +struct is_compatible_array_type_impl : std::false_type {}; + +template +struct is_compatible_array_type_impl < + BasicJsonType, CompatibleArrayType, + enable_if_t < + is_detected::value&& + is_iterator_traits>>::value&& +// special case for types like std::filesystem::path whose iterator's value_type are themselves +// c.f. https://github.com/nlohmann/json/pull/3073 + !std::is_same>::value >> +{ + static constexpr bool value = + is_constructible>::value; +}; + +template +struct is_compatible_array_type + : is_compatible_array_type_impl {}; + +template +struct is_constructible_array_type_impl : std::false_type {}; + +template +struct is_constructible_array_type_impl < + BasicJsonType, ConstructibleArrayType, + enable_if_t::value >> + : std::true_type {}; + +template +struct is_constructible_array_type_impl < + BasicJsonType, ConstructibleArrayType, + enable_if_t < !std::is_same::value&& + !is_compatible_string_type::value&& + is_default_constructible::value&& +(std::is_move_assignable::value || + std::is_copy_assignable::value)&& +is_detected::value&& +is_iterator_traits>>::value&& +is_detected::value&& +// special case for types like std::filesystem::path whose iterator's value_type are themselves +// c.f. https://github.com/nlohmann/json/pull/3073 +!std::is_same>::value&& + is_complete_type < + detected_t>::value >> +{ + using value_type = range_value_t; + + static constexpr bool value = + std::is_same::value || + has_from_json::value || + has_non_default_from_json < + BasicJsonType, + value_type >::value; +}; + +template +struct is_constructible_array_type + : is_constructible_array_type_impl {}; + +template +struct is_compatible_integer_type_impl : std::false_type {}; + +template +struct is_compatible_integer_type_impl < + RealIntegerType, CompatibleNumberIntegerType, + enable_if_t < std::is_integral::value&& + std::is_integral::value&& + !std::is_same::value >> +{ + // is there an assert somewhere on overflows? + using RealLimits = std::numeric_limits; + using CompatibleLimits = std::numeric_limits; + + static constexpr auto value = + is_constructible::value && + CompatibleLimits::is_integer && + RealLimits::is_signed == CompatibleLimits::is_signed; +}; + +template +struct is_compatible_integer_type + : is_compatible_integer_type_impl {}; + +template +struct is_compatible_type_impl: std::false_type {}; + +template +struct is_compatible_type_impl < + BasicJsonType, CompatibleType, + enable_if_t::value >> +{ + static constexpr bool value = + has_to_json::value; +}; + +template +struct is_compatible_type + : is_compatible_type_impl {}; + +template +struct is_constructible_tuple : std::false_type {}; + +template +struct is_constructible_tuple> : conjunction...> {}; + +template +struct is_json_iterator_of : std::false_type {}; + +template +struct is_json_iterator_of : std::true_type {}; + +template +struct is_json_iterator_of : std::true_type +{}; + +// checks if a given type T is a template specialization of Primary +template