diff --git a/.mergify.yml b/.github/mergify.yml similarity index 100% rename from .mergify.yml rename to .github/mergify.yml diff --git a/.github/workflows/all_jobs.yaml b/.github/workflows/all_jobs.yaml index 82bf8e0c6..9c5660b45 100644 --- a/.github/workflows/all_jobs.yaml +++ b/.github/workflows/all_jobs.yaml @@ -2,6 +2,7 @@ name: All Build on: workflow_dispatch: + push: pull_request: env: diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a2c5b477..25e17d5d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ cmake_minimum_required(VERSION 3.5) -project(metavision VERSION 3.1.1) +project(metavision VERSION 3.1.2) set(PROJECT_VERSION_SUFFIX "") if(PROJECT_VERSION_SUFFIX STREQUAL "") diff --git a/README.md b/README.md index a3e381d48..a651fe1ff 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,22 @@ Currently, we support Ubuntu 18.04 and 20.04. Compilation on other versions of Ubuntu or other Linux distributions was not tested. For those platforms some adjustments to this guide or to the code itself may be required (specially for non-Debian Linux). +### Upgrading OpenEB + +If you are upgrading OpenEB from a previous version, you should first read carefully the `Release Notes `_ +as some changes may impact your usage of our SDK (e.g. API updates) and cameras (e.g. `firmware update `_ might be necessary). + +Then, you need to clean your system from previously installed Prophesee software. If after a previous compilation, you chose to +deploy the Metavision files in your system path, then go to the `build` folder in the source code directory and +launch the following command to remove those files: + +```bash +sudo make uninstall +``` + +In addition, make a global check in your system paths (`/usr/lib`, `/usr/local/lib`, `/usr/include`, `/usr/local/include`) +and in your environment variables (`PATH`, `PYTHONPATH` and `LD_LIBRARY_PATH`) to remove occurrences of Prophesee or Metavision files. + ### Prerequisites Install the following dependencies: @@ -43,23 +59,53 @@ Install the following dependencies: ```bash sudo apt update sudo apt -y install apt-utils build-essential software-properties-common wget unzip curl git cmake -sudo apt -y install libopencv-dev libgtest-dev libboost-all-dev libusb-1.0-0-dev libeigen3-dev +sudo apt -y install libopencv-dev googletest libgtest-dev libboost-all-dev libusb-1.0-0-dev sudo apt -y install libglew-dev libglfw3-dev libcanberra-gtk-module ffmpeg ``` +Optionally, if you want to run the tests, you need to compile the `GoogleTest `_ package: + +```bash +cd /usr/src/googletest +sudo cmake . +sudo make +sudo make install +``` + For the Python API, you will need Python and some additional libraries. If Python is not available on your system, install it (we support Python 3.6 and 3.7 on Ubuntu 18.04 and Python 3.7 and 3.8 on Ubuntu 20.04). -Then install `pip`: +Then install `pip` and some Python libraries: ```bash sudo apt -y install python3-pip python3-distutils +sudo apt -y install python3.X-dev # where X is 6, 7 or 8 depending on your Python version (3.6, 3.7 or 3.8) python3 -m pip install pip --upgrade +python3 -m pip install "opencv-python>=4.5.5.64" "sk-video==1.1.10" "fire==0.4.0" "numpy<=1.21" pandas scipy h5py +python3 -m pip install jupyter jupyterlab matplotlib "ipywidgets==7.6.5" pytest command_runner +``` + +The Python bindings of the C++ API rely on the [pybind11](https://github.com/pybind) library, specifically version 2.6.0. + +*Note* that pybind11 is required only if you want to use the Python bindings of the C++ API . +You can opt out of creating these bindings by passing the argument `-DCOMPILE_PYTHON3_BINDINGS=OFF` at step 3 during compilation (see below). +In that case, you will not need to install pybind11, but you won't be able to use our Python interface to the C++ API. + +Unfortunately, there is no pre-compiled version of pybind11 available, so you need to install it manually: + +```bash +wget https://github.com/pybind/pybind11/archive/v2.6.0.zip +unzip v2.6.0.zip +cd pybind11-2.6.0/ +mkdir build && cd build +cmake .. -DPYBIND11_TEST=OFF +cmake --build . +sudo cmake --build . --target install ``` To use Machine Learning features, you need to install some additional dependencies. -First, if you have some Nvidia hardware with GPUs, install `CUDA (10.2 or 11.1) `_ +First, if you have some Nvidia hardware with GPUs, you can optionally install `CUDA (10.2 or 11.1) `_ and `cuDNN `_ to leverage them with pytorch and libtorch. Make sure that you install a version of CUDA that is compatible with your GPUs by checking @@ -80,37 +126,7 @@ python3 -m pip install torch==1.8.2 torchvision==0.9.2 torchaudio==0.8.2 --extra Then install some extra Python libraries: ```bash -python3 -m pip install "opencv-python>=4.5.5.64" "sk-video==1.1.10" "fire==0.4.0" "numpy<=1.21" pandas scipy numba profilehooks h5py pytest -python3 -m pip install jupyter jupyterlab matplotlib "ipywidgets==7.6.5" -python3 -m pip install "pytorch_lightning==1.5.10" "tqdm==4.63.0" "kornia==0.6.1" - -``` - -If you want to run tests, then you need to compile **gtest** package (this is optional): - -```bash -cd /usr/src/gtest -sudo cmake . -sudo make -sudo make install -``` - -The Python bindings rely on the [pybind11](https://github.com/pybind) library, specifically version 2.6.0. - -*Note* that pybind11 is required only if you want to use the Python bindings of our C++ API. -You can opt out of creating these bindings by passing the argument `-DCOMPILE_PYTHON3_BINDINGS=OFF` at step 3 during compilation (see below). -In that case, you will not need to install pybind11, but you won't be able to use our Python interface. - -Unfortunately, there is no pre-compiled version of pybind11 available, so you need to install it manually: - -```bash -wget https://github.com/pybind/pybind11/archive/v2.6.0.zip -unzip v2.6.0.zip -cd pybind11-2.6.0/ -mkdir build && cd build -cmake .. -DPYBIND11_TEST=OFF -cmake --build . -sudo cmake --build . --target install +python3 -m pip install numba profilehooks "pytorch_lightning==1.5.10" "tqdm==4.63.0" "kornia==0.6.1" ``` ### Compilation @@ -128,9 +144,13 @@ source /build/utils/scripts/setup_env.sh ``` Optionally, you can deploy the OpenEB files in the system paths to use them as 3rd party dependency in some other code -with the following command: `sudo cmake --build . --target install`. In that case, you will also need to update -`LD_LIBRARY_PATH` with `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib` (If you want to update this path -permanently, you should add the previous command in your ~/.bashrc) +with the following command: `sudo cmake --build . --target install`. + +In that case, you will also need to update: + + * `LD_LIBRARY_PATH` with `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib` + +If you want those settings to be permanent, you should add the previous commands in your ~/.bashrc. You can also deploy the OpenEB files (applications, samples, libraries etc.) in a directory of your choice by using the `CMAKE_INSTALL_PREFIX` variable (`-DCMAKE_INSTALL_PREFIX=`) when generating the makefiles @@ -142,9 +162,9 @@ Since OpenEB 3.0.0, Prophesee camera plugins are included in OpenEB. If you did used by Prophesee cameras in the system path and reload them so that your camera is detected with this command: ```bash -sudo cp $METAVISION_SRC_DIR/hal_psee_plugins/resources/rules/*.rules /etc/udev/rules.d -udevadm control --reload-rules -udevadm trigger +sudo cp /hal_psee_plugins/resources/rules/*.rules /etc/udev/rules.d +sudo udevadm control --reload-rules +sudo udevadm trigger ``` If you are using a third-party camera, you need to install the plugin provided by the camera vendor and specify @@ -176,6 +196,19 @@ Running the test suite is a sure-fire way to ensure you did everything well with ## Compiling on Windows +Currently, we support only Windows 10. +Compilation on other versions of Windows was not tested. +For those platforms some adjustments to this guide or to the code itself may be required. + +### Upgrading OpenEB + +If you are upgrading OpenEB from a previous version, you should first read carefully the `Release Notes `_ +as some changes may impact your usage of our SDK (e.g. :API updates) and cameras (e.g. `firmware update `_ might be necessary). + +Then, if you have previously installed any Prophesee's software, you will need to uninstall it first. +Remove the folders where you installed Metavision artifacts (check both the `build` folder of the source code and +`C:\Program Files\Prophesee` which is the default install path of the deployment step). + ### Prerequisites Some steps of this procedure don't work on FAT32 and exFAT file system. @@ -188,7 +221,8 @@ You must enable the support for long paths: To compile OpenEB, you will need to install some extra tools: - * install [cmake](https://cmake.org/) + * install [git](https://git-scm.com/download/win) + * install [CMake 3.20](https://cmake.org/files/v3.20/cmake-3.20.6-windows-x86_64.msi) * install Microsoft C++ compiler (64-bit). You can choose one of the following solutions: * For building only, you can install MS Build Tools (free, part of Windows 10 SDK package) * Download and run ["Build tools for Visual Studio 2019" installer](https://visualstudio.microsoft.com/visual-cpp-build-tools/) @@ -215,39 +249,43 @@ Those can be found in the [vcpkg repository](https://github.com/microsoft/vcpkg/ * gtest: 1.11.0 * dirent: 1.23.2 -#### Install pybind - -The Python bindings rely on the [pybind11](https://github.com/pybind) library. -You should install pybind using vcpkg in order to get the appropriate version: `vcpkg.exe install --triplet x64-windows pybind11` - -*Note* that pybind11 is required only if you plan to use the Python API. -You can opt out of creating these bindings by passing the argument `-DCOMPILE_PYTHON3_BINDINGS=OFF` at step 2 during compilation (see section "Compilation using CMake"). -In that case, you will not need to install pybind11, but you won't be able to use our Python interface. - - -#### Install Python 3.7 or 3.8 +#### Installing Python and libraries * Download "Windows x86-64 executable installer" for one of these Python versions: * [Python 3.7](https://www.python.org/downloads/release/python-379/) - * [Python 3.8](https://www.python.org/downloads/release/python-389/) -* We advise you to check the box to update the `PATH` or update the `PATH` manually with the following paths - after replacing the *Username* to your own and using the Python version you installed - (here, we assume that the install is limited to the local user and the default install path was used): - + * [Python 3.8](https://www.python.org/downloads/release/python-3810/) +* Add Python install and script directories in your `PATH` and make sure they are listed before + the `WindowsApps` folder which contains a Python alias launching the Microsoft Store. So, if you installed + Python 3.8 in the default path, your user `PATH` should contain those three lines in that order: + ```bash -C:\Users\Username\AppData\Local\Programs\Python\Python37 -C:\Users\Username\AppData\Local\Programs\Python\Python37\Scripts +%USERPROFILE%\AppData\Local\Programs\Python\Python38 +%USERPROFILE%\AppData\Local\Programs\Python\Python38\Scripts +%USERPROFILE%\AppData\Local\Microsoft\WindowsApps ```` -* Then make sure `pip` is up to date: +Then install `pip` and some Python libraries: ```bash python -m pip install pip --upgrade +python -m pip install "opencv-python>=4.5.5.64" "sk-video==1.1.10" "fire==0.4.0" "numpy<=1.21" pandas scipy h5py +python -m pip install jupyter jupyterlab matplotlib "ipywidgets==7.6.5" pytest command_runner ``` +#### Install pybind + +The Python bindings of the C++ API rely on the [pybind11](https://github.com/pybind) library. +You should install pybind using vcpkg in order to get the appropriate version: `vcpkg.exe install --triplet x64-windows pybind11` + +*Note* that pybind11 is required only if you plan to use the Python bindings of the C++ API. +You can opt out of creating these bindings by passing the argument `-DCOMPILE_PYTHON3_BINDINGS=OFF` at step 2 during compilation (see section "Compilation using CMake"). +In that case, you will not need to install pybind11, but you won't be able to use our Python interface to the C++ API. + +#### Prerequisites for the ML module + To use Machine Learning features, you need to install some additional dependencies. -First, if you have some Nvidia hardware with GPUs, install `CUDA (10.2 or 11.1) `_ +First, if you have some Nvidia hardware with GPUs, you can optionally install `CUDA (10.2 or 11.1) `_ and `cuDNN `_ to leverage them with pytorch and libtorch. Then, install pytorch. Go to `pytorch.org `_ to retrieve the pip command that you @@ -261,9 +299,7 @@ python -m pip install torch==1.8.2+cu111 torchvision==0.9.2+cu111 torchaudio==0. Then install some extra Python libraries: ```bash -python -m pip install "opencv-python>=4.5.5.64" "sk-video==1.1.10" "fire==0.4.0" "numpy<=1.21" pandas scipy numba profilehooks h5py pytest -python -m pip install jupyter jupyterlab matplotlib "ipywidgets==7.6.5" -python -m pip install "pytorch_lightning==1.5.10" "tqdm==4.63.0" "kornia==0.6.1" +python -m pip install numba profilehooks "pytorch_lightning==1.5.10" "tqdm==4.63.0" "kornia==0.6.1" ``` ### Compilation @@ -312,13 +348,33 @@ cmake --build . --config Release --target install #### Compilation using MS Visual Studio -Open a command prompt inside the `openeb` folder and do as follows: +Open a command prompt inside the `openeb` folder (absolute path to this directory is called `OPENEB_SRC_DIR` in next sections) and do as follows: 1. Create and open the build directory, where temporary files will be created: `mkdir build && cd build` 2. Generate the Visual Studio files using CMake: `cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_TOOLCHAIN_FILE=\cmake\toolchains\vcpkg.cmake -DVCPKG_DIRECTORY= ..` (adapt to your Visual Studio version). Note that the value passed to the parameter `-DCMAKE_TOOLCHAIN_FILE` must be an absolute path, not a relative one. 3. Open the solution file `metavision.sln`, select the `Release` configuration and build the `ALL_BUILD` project. +#### Camera Plugins + +Since OpenEB 3.0.0, **Prophesee camera plugins** are included in OpenEB, but you need to install the drivers +for the cameras to be available on Windows. To do so, follow this procedure: + +1. download [wdi-simple.exe from our file server](https://files.prophesee.ai/share/dists/public/drivers/FeD45ki5/wdi-simple.exe) +2. execute the following commands in a Command Prompt launched as an administrator: + +```bash +wdi-simple.exe -n "EVK" -m "Prophesee" -v 0x04b4 -p 0x00f4 +wdi-simple.exe -n "EVK" -m "Prophesee" -v 0x03fd -p 0x5832 -i 00 +wdi-simple.exe -n "EVK" -m "Prophesee" -v 0x04b4 -p 0x00f5 +wdi-simple.exe -n "EVK" -m "Prophesee" -v 0x04b4 -p 0x00f3 +``` + +If you are using a third-party camera, you need to follow the instructions provided by the camera vendor +to install the driver and the camera plugin. Make sure that you reference the location of the plugin in +the `MV_HAL_PLUGIN_PATH` environment variable. + + #### Getting Started To get started with OpenEB, you can download some [sample recordings](https://docs.prophesee.ai/stable/datasets.html) diff --git a/cmake/custom_functions/add_library_version_header.cmake b/cmake/custom_functions/add_library_version_header.cmake index a720380ef..fb3f49405 100644 --- a/cmake/custom_functions/add_library_version_header.cmake +++ b/cmake/custom_functions/add_library_version_header.cmake @@ -8,8 +8,8 @@ # See the License for the specific language governing permissions and limitations under the License. set(GIT_BRANCH "HEAD") -set(GIT_COMMIT_ID "37aa7510f3d6bdbd2b2b66e816d4fb0e3a420e9d") -set(GIT_COMMIT_DATE "2022-11-23 15:21:14 +0100") +set(GIT_COMMIT_ID "6a744effa905d697563baa52a50715ae69d8ba35") +set(GIT_COMMIT_DATE "2022-12-15 13:50:43 +0100") # If git information are not provided in command line when running cmake, try to automatically determine them if(NOT GIT_BRANCH OR NOT GIT_COMMIT_ID OR NOT GIT_COMMIT_DATE) diff --git a/cmake/custom_functions/python3.cmake b/cmake/custom_functions/python3.cmake index d739846bc..65c16214b 100644 --- a/cmake/custom_functions/python3.cmake +++ b/cmake/custom_functions/python3.cmake @@ -232,7 +232,14 @@ if (COMPILE_PYTHON3_BINDINGS) add_library(${target_name} ${lib_type} ${ARG_UNPARSED_ARGUMENTS}) - target_link_libraries(${target_name} PRIVATE pybind11::module Python3::Python_${python_version}) + if (NOT APPLE) + target_link_libraries(${target_name} PRIVATE pybind11::module Python3::Python_${python_version}) + else() + get_target_property(_python_include_dirs Python3::Python_${python_version} INTERFACE_INCLUDE_DIRECTORIES) + target_include_directories(${target_name} PRIVATE ${_python_include_dirs}) + target_link_libraries(${target_name} PRIVATE pybind11::module) + target_link_options(${target_name} PRIVATE -undefined dynamic_lookup) + endif() if(lib_type STREQUAL "MODULE") target_link_libraries(${target_name} PRIVATE pybind11::module) diff --git a/cmake/custom_targets/README_metavision_open.md b/cmake/custom_targets/README_metavision_open.md index a3e381d48..a651fe1ff 100644 --- a/cmake/custom_targets/README_metavision_open.md +++ b/cmake/custom_targets/README_metavision_open.md @@ -36,6 +36,22 @@ Currently, we support Ubuntu 18.04 and 20.04. Compilation on other versions of Ubuntu or other Linux distributions was not tested. For those platforms some adjustments to this guide or to the code itself may be required (specially for non-Debian Linux). +### Upgrading OpenEB + +If you are upgrading OpenEB from a previous version, you should first read carefully the `Release Notes `_ +as some changes may impact your usage of our SDK (e.g. API updates) and cameras (e.g. `firmware update `_ might be necessary). + +Then, you need to clean your system from previously installed Prophesee software. If after a previous compilation, you chose to +deploy the Metavision files in your system path, then go to the `build` folder in the source code directory and +launch the following command to remove those files: + +```bash +sudo make uninstall +``` + +In addition, make a global check in your system paths (`/usr/lib`, `/usr/local/lib`, `/usr/include`, `/usr/local/include`) +and in your environment variables (`PATH`, `PYTHONPATH` and `LD_LIBRARY_PATH`) to remove occurrences of Prophesee or Metavision files. + ### Prerequisites Install the following dependencies: @@ -43,23 +59,53 @@ Install the following dependencies: ```bash sudo apt update sudo apt -y install apt-utils build-essential software-properties-common wget unzip curl git cmake -sudo apt -y install libopencv-dev libgtest-dev libboost-all-dev libusb-1.0-0-dev libeigen3-dev +sudo apt -y install libopencv-dev googletest libgtest-dev libboost-all-dev libusb-1.0-0-dev sudo apt -y install libglew-dev libglfw3-dev libcanberra-gtk-module ffmpeg ``` +Optionally, if you want to run the tests, you need to compile the `GoogleTest `_ package: + +```bash +cd /usr/src/googletest +sudo cmake . +sudo make +sudo make install +``` + For the Python API, you will need Python and some additional libraries. If Python is not available on your system, install it (we support Python 3.6 and 3.7 on Ubuntu 18.04 and Python 3.7 and 3.8 on Ubuntu 20.04). -Then install `pip`: +Then install `pip` and some Python libraries: ```bash sudo apt -y install python3-pip python3-distutils +sudo apt -y install python3.X-dev # where X is 6, 7 or 8 depending on your Python version (3.6, 3.7 or 3.8) python3 -m pip install pip --upgrade +python3 -m pip install "opencv-python>=4.5.5.64" "sk-video==1.1.10" "fire==0.4.0" "numpy<=1.21" pandas scipy h5py +python3 -m pip install jupyter jupyterlab matplotlib "ipywidgets==7.6.5" pytest command_runner +``` + +The Python bindings of the C++ API rely on the [pybind11](https://github.com/pybind) library, specifically version 2.6.0. + +*Note* that pybind11 is required only if you want to use the Python bindings of the C++ API . +You can opt out of creating these bindings by passing the argument `-DCOMPILE_PYTHON3_BINDINGS=OFF` at step 3 during compilation (see below). +In that case, you will not need to install pybind11, but you won't be able to use our Python interface to the C++ API. + +Unfortunately, there is no pre-compiled version of pybind11 available, so you need to install it manually: + +```bash +wget https://github.com/pybind/pybind11/archive/v2.6.0.zip +unzip v2.6.0.zip +cd pybind11-2.6.0/ +mkdir build && cd build +cmake .. -DPYBIND11_TEST=OFF +cmake --build . +sudo cmake --build . --target install ``` To use Machine Learning features, you need to install some additional dependencies. -First, if you have some Nvidia hardware with GPUs, install `CUDA (10.2 or 11.1) `_ +First, if you have some Nvidia hardware with GPUs, you can optionally install `CUDA (10.2 or 11.1) `_ and `cuDNN `_ to leverage them with pytorch and libtorch. Make sure that you install a version of CUDA that is compatible with your GPUs by checking @@ -80,37 +126,7 @@ python3 -m pip install torch==1.8.2 torchvision==0.9.2 torchaudio==0.8.2 --extra Then install some extra Python libraries: ```bash -python3 -m pip install "opencv-python>=4.5.5.64" "sk-video==1.1.10" "fire==0.4.0" "numpy<=1.21" pandas scipy numba profilehooks h5py pytest -python3 -m pip install jupyter jupyterlab matplotlib "ipywidgets==7.6.5" -python3 -m pip install "pytorch_lightning==1.5.10" "tqdm==4.63.0" "kornia==0.6.1" - -``` - -If you want to run tests, then you need to compile **gtest** package (this is optional): - -```bash -cd /usr/src/gtest -sudo cmake . -sudo make -sudo make install -``` - -The Python bindings rely on the [pybind11](https://github.com/pybind) library, specifically version 2.6.0. - -*Note* that pybind11 is required only if you want to use the Python bindings of our C++ API. -You can opt out of creating these bindings by passing the argument `-DCOMPILE_PYTHON3_BINDINGS=OFF` at step 3 during compilation (see below). -In that case, you will not need to install pybind11, but you won't be able to use our Python interface. - -Unfortunately, there is no pre-compiled version of pybind11 available, so you need to install it manually: - -```bash -wget https://github.com/pybind/pybind11/archive/v2.6.0.zip -unzip v2.6.0.zip -cd pybind11-2.6.0/ -mkdir build && cd build -cmake .. -DPYBIND11_TEST=OFF -cmake --build . -sudo cmake --build . --target install +python3 -m pip install numba profilehooks "pytorch_lightning==1.5.10" "tqdm==4.63.0" "kornia==0.6.1" ``` ### Compilation @@ -128,9 +144,13 @@ source /build/utils/scripts/setup_env.sh ``` Optionally, you can deploy the OpenEB files in the system paths to use them as 3rd party dependency in some other code -with the following command: `sudo cmake --build . --target install`. In that case, you will also need to update -`LD_LIBRARY_PATH` with `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib` (If you want to update this path -permanently, you should add the previous command in your ~/.bashrc) +with the following command: `sudo cmake --build . --target install`. + +In that case, you will also need to update: + + * `LD_LIBRARY_PATH` with `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib` + +If you want those settings to be permanent, you should add the previous commands in your ~/.bashrc. You can also deploy the OpenEB files (applications, samples, libraries etc.) in a directory of your choice by using the `CMAKE_INSTALL_PREFIX` variable (`-DCMAKE_INSTALL_PREFIX=`) when generating the makefiles @@ -142,9 +162,9 @@ Since OpenEB 3.0.0, Prophesee camera plugins are included in OpenEB. If you did used by Prophesee cameras in the system path and reload them so that your camera is detected with this command: ```bash -sudo cp $METAVISION_SRC_DIR/hal_psee_plugins/resources/rules/*.rules /etc/udev/rules.d -udevadm control --reload-rules -udevadm trigger +sudo cp /hal_psee_plugins/resources/rules/*.rules /etc/udev/rules.d +sudo udevadm control --reload-rules +sudo udevadm trigger ``` If you are using a third-party camera, you need to install the plugin provided by the camera vendor and specify @@ -176,6 +196,19 @@ Running the test suite is a sure-fire way to ensure you did everything well with ## Compiling on Windows +Currently, we support only Windows 10. +Compilation on other versions of Windows was not tested. +For those platforms some adjustments to this guide or to the code itself may be required. + +### Upgrading OpenEB + +If you are upgrading OpenEB from a previous version, you should first read carefully the `Release Notes `_ +as some changes may impact your usage of our SDK (e.g. :API updates) and cameras (e.g. `firmware update `_ might be necessary). + +Then, if you have previously installed any Prophesee's software, you will need to uninstall it first. +Remove the folders where you installed Metavision artifacts (check both the `build` folder of the source code and +`C:\Program Files\Prophesee` which is the default install path of the deployment step). + ### Prerequisites Some steps of this procedure don't work on FAT32 and exFAT file system. @@ -188,7 +221,8 @@ You must enable the support for long paths: To compile OpenEB, you will need to install some extra tools: - * install [cmake](https://cmake.org/) + * install [git](https://git-scm.com/download/win) + * install [CMake 3.20](https://cmake.org/files/v3.20/cmake-3.20.6-windows-x86_64.msi) * install Microsoft C++ compiler (64-bit). You can choose one of the following solutions: * For building only, you can install MS Build Tools (free, part of Windows 10 SDK package) * Download and run ["Build tools for Visual Studio 2019" installer](https://visualstudio.microsoft.com/visual-cpp-build-tools/) @@ -215,39 +249,43 @@ Those can be found in the [vcpkg repository](https://github.com/microsoft/vcpkg/ * gtest: 1.11.0 * dirent: 1.23.2 -#### Install pybind - -The Python bindings rely on the [pybind11](https://github.com/pybind) library. -You should install pybind using vcpkg in order to get the appropriate version: `vcpkg.exe install --triplet x64-windows pybind11` - -*Note* that pybind11 is required only if you plan to use the Python API. -You can opt out of creating these bindings by passing the argument `-DCOMPILE_PYTHON3_BINDINGS=OFF` at step 2 during compilation (see section "Compilation using CMake"). -In that case, you will not need to install pybind11, but you won't be able to use our Python interface. - - -#### Install Python 3.7 or 3.8 +#### Installing Python and libraries * Download "Windows x86-64 executable installer" for one of these Python versions: * [Python 3.7](https://www.python.org/downloads/release/python-379/) - * [Python 3.8](https://www.python.org/downloads/release/python-389/) -* We advise you to check the box to update the `PATH` or update the `PATH` manually with the following paths - after replacing the *Username* to your own and using the Python version you installed - (here, we assume that the install is limited to the local user and the default install path was used): - + * [Python 3.8](https://www.python.org/downloads/release/python-3810/) +* Add Python install and script directories in your `PATH` and make sure they are listed before + the `WindowsApps` folder which contains a Python alias launching the Microsoft Store. So, if you installed + Python 3.8 in the default path, your user `PATH` should contain those three lines in that order: + ```bash -C:\Users\Username\AppData\Local\Programs\Python\Python37 -C:\Users\Username\AppData\Local\Programs\Python\Python37\Scripts +%USERPROFILE%\AppData\Local\Programs\Python\Python38 +%USERPROFILE%\AppData\Local\Programs\Python\Python38\Scripts +%USERPROFILE%\AppData\Local\Microsoft\WindowsApps ```` -* Then make sure `pip` is up to date: +Then install `pip` and some Python libraries: ```bash python -m pip install pip --upgrade +python -m pip install "opencv-python>=4.5.5.64" "sk-video==1.1.10" "fire==0.4.0" "numpy<=1.21" pandas scipy h5py +python -m pip install jupyter jupyterlab matplotlib "ipywidgets==7.6.5" pytest command_runner ``` +#### Install pybind + +The Python bindings of the C++ API rely on the [pybind11](https://github.com/pybind) library. +You should install pybind using vcpkg in order to get the appropriate version: `vcpkg.exe install --triplet x64-windows pybind11` + +*Note* that pybind11 is required only if you plan to use the Python bindings of the C++ API. +You can opt out of creating these bindings by passing the argument `-DCOMPILE_PYTHON3_BINDINGS=OFF` at step 2 during compilation (see section "Compilation using CMake"). +In that case, you will not need to install pybind11, but you won't be able to use our Python interface to the C++ API. + +#### Prerequisites for the ML module + To use Machine Learning features, you need to install some additional dependencies. -First, if you have some Nvidia hardware with GPUs, install `CUDA (10.2 or 11.1) `_ +First, if you have some Nvidia hardware with GPUs, you can optionally install `CUDA (10.2 or 11.1) `_ and `cuDNN `_ to leverage them with pytorch and libtorch. Then, install pytorch. Go to `pytorch.org `_ to retrieve the pip command that you @@ -261,9 +299,7 @@ python -m pip install torch==1.8.2+cu111 torchvision==0.9.2+cu111 torchaudio==0. Then install some extra Python libraries: ```bash -python -m pip install "opencv-python>=4.5.5.64" "sk-video==1.1.10" "fire==0.4.0" "numpy<=1.21" pandas scipy numba profilehooks h5py pytest -python -m pip install jupyter jupyterlab matplotlib "ipywidgets==7.6.5" -python -m pip install "pytorch_lightning==1.5.10" "tqdm==4.63.0" "kornia==0.6.1" +python -m pip install numba profilehooks "pytorch_lightning==1.5.10" "tqdm==4.63.0" "kornia==0.6.1" ``` ### Compilation @@ -312,13 +348,33 @@ cmake --build . --config Release --target install #### Compilation using MS Visual Studio -Open a command prompt inside the `openeb` folder and do as follows: +Open a command prompt inside the `openeb` folder (absolute path to this directory is called `OPENEB_SRC_DIR` in next sections) and do as follows: 1. Create and open the build directory, where temporary files will be created: `mkdir build && cd build` 2. Generate the Visual Studio files using CMake: `cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_TOOLCHAIN_FILE=\cmake\toolchains\vcpkg.cmake -DVCPKG_DIRECTORY= ..` (adapt to your Visual Studio version). Note that the value passed to the parameter `-DCMAKE_TOOLCHAIN_FILE` must be an absolute path, not a relative one. 3. Open the solution file `metavision.sln`, select the `Release` configuration and build the `ALL_BUILD` project. +#### Camera Plugins + +Since OpenEB 3.0.0, **Prophesee camera plugins** are included in OpenEB, but you need to install the drivers +for the cameras to be available on Windows. To do so, follow this procedure: + +1. download [wdi-simple.exe from our file server](https://files.prophesee.ai/share/dists/public/drivers/FeD45ki5/wdi-simple.exe) +2. execute the following commands in a Command Prompt launched as an administrator: + +```bash +wdi-simple.exe -n "EVK" -m "Prophesee" -v 0x04b4 -p 0x00f4 +wdi-simple.exe -n "EVK" -m "Prophesee" -v 0x03fd -p 0x5832 -i 00 +wdi-simple.exe -n "EVK" -m "Prophesee" -v 0x04b4 -p 0x00f5 +wdi-simple.exe -n "EVK" -m "Prophesee" -v 0x04b4 -p 0x00f3 +``` + +If you are using a third-party camera, you need to follow the instructions provided by the camera vendor +to install the driver and the camera plugin. Make sure that you reference the location of the plugin in +the `MV_HAL_PLUGIN_PATH` environment variable. + + #### Getting Started To get started with OpenEB, you can download some [sample recordings](https://docs.prophesee.ai/stable/datasets.html) diff --git a/cmake/custom_targets/create_metavision_open_archive_folder.cmake b/cmake/custom_targets/create_metavision_open_archive_folder.cmake index afff20cc8..cf5417fc5 100644 --- a/cmake/custom_targets/create_metavision_open_archive_folder.cmake +++ b/cmake/custom_targets/create_metavision_open_archive_folder.cmake @@ -43,6 +43,9 @@ file(COPY "${PROJECT_SOURCE_DIR}/utils/github_actions/openeb/" DESTINATION "${OUTPUT_DIR}/.github" PATTERN "*" ) +file(COPY "${PROJECT_SOURCE_DIR}/utils/github_actions/openeb/mergify.yml" + DESTINATION "${OUTPUT_DIR}/.github" +) # Remove SDK targets file(REMOVE_RECURSE "${OUTPUT_DIR}/cmake/custom_targets_metavision_sdk") diff --git a/hal/python/bindings/metavision_hal_bindings.cpp b/hal/python/bindings/metavision_hal_bindings.cpp index dfe5e7ee2..c7e3a67f5 100644 --- a/hal/python/bindings/metavision_hal_bindings.cpp +++ b/hal/python/bindings/metavision_hal_bindings.cpp @@ -15,7 +15,15 @@ #endif #include +#if defined(__APPLE__) +#include +#endif #include + +#if defined(__APPLE__) +#include "metavision/sdk/base/events/event_cd.h" +#endif +#include "metavision/sdk/base/events/event_ext_trigger.h" #include "metavision/utils/pybind/deprecation_warning_exception.h" #include "hal_python_binder.h" #include "metavision/hal/device/device.h" @@ -43,6 +51,12 @@ PYBIND11_MODULE(MODULE_NAME, m) { throw(e); } +#if defined(__APPLE__) + PYBIND11_NUMPY_DTYPE(Metavision::Event2d, x, y, p, t); + PYBIND11_NUMPY_DTYPE(Metavision::EventCD, x, y, p, t); + PYBIND11_NUMPY_DTYPE(Metavision::EventExtTrigger, p, t, id); +#endif + // Register the translation for DeprecationWarningException py::register_exception(m, "Deprecated"); diff --git a/hal_psee_plugins/include/boards/treuzell/treuzell_command_definition.h b/hal_psee_plugins/include/boards/treuzell/treuzell_command_definition.h index c472c2979..c4b600f44 100644 --- a/hal_psee_plugins/include/boards/treuzell/treuzell_command_definition.h +++ b/hal_psee_plugins/include/boards/treuzell/treuzell_command_definition.h @@ -1,4 +1,14 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/********************************************************************************************************************** + * Copyright (c) Prophesee S.A. * + * * + * Licensed 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. * + **********************************************************************************************************************/ + #ifndef __TREUZELL_COMMAND_DEFINITION_H #define __TREUZELL_COMMAND_DEFINITION_H diff --git a/sdk/modules/base/cpp/include/metavision/sdk/base/utils/log.h b/sdk/modules/base/cpp/include/metavision/sdk/base/utils/log.h index 9d78d2f96..82ae4e0b8 100644 --- a/sdk/modules/base/cpp/include/metavision/sdk/base/utils/log.h +++ b/sdk/modules/base/cpp/include/metavision/sdk/base/utils/log.h @@ -208,11 +208,11 @@ class LoggingOperation { /// @brief Disables automatically adding spaces between message tokens void disableSpaceBetweenTokens(); - /// @brief Enables automatically adding and end of line token when this operation is destroyed + /// @brief Enables automatically adding an end of line token when this operation is destroyed /// @note This feature is enabled by default void enableEndOfLineAtDestruction(); - /// @brief Disables automatically adding and end of line token when this operation is destroyed + /// @brief Disables automatically adding an end of line token when this operation is destroyed void disableEndOfLineAtDestruction(); /// @brief Returns the name of the file associated to this logging operation @@ -263,7 +263,7 @@ class LoggingOperation { /// @tparam T Type of the message to be logged /// @param op Logging operation to be logged to /// @param t Value to be logged -/// @return The modifed logging operation +/// @return The modified logging operation template LoggingOperation &operator<<(LoggingOperation &op, const T &t); /// @copydoc operator<< @@ -274,7 +274,7 @@ LoggingOperation &&operator<<(LoggingOperation &&op, const T &t); /// @tparam Level The level of the logging operation /// @param op Logging operation to be modified /// @param f Function modifying a logging operation -/// @return The modifed logging operation +/// @return The modified logging operation template LoggingOperation &operator<<(LoggingOperation &op, LoggingOperation &(*f)(LoggingOperation &)); @@ -287,7 +287,7 @@ LoggingOperation &&operator<<(LoggingOperation &&op, /// @tparam Level The level of the logging operation /// @param op Logging operation to be modified /// @param manip Stream manipulator -/// @return The modifed logging operation +/// @return The modified logging operation template LoggingOperation &operator<<(LoggingOperation &op, std::ostream &(*manip)(std::ostream &)); /// @copydoc operator<< @@ -315,7 +315,7 @@ LoggingOperation &no_space(LoggingOperation &op); template LoggingOperation &&no_space(LoggingOperation &&op); -/// @brief Stream manipulator enabling the automatic addition of and end of line token at the end of the operation +/// @brief Stream manipulator enabling the automatic addition of an end of line token at the end of the operation /// @tparam Level The level of the logging operation /// @param op The logging operation modified by this modifier /// @return The modified logging operation @@ -325,7 +325,7 @@ LoggingOperation &endline(LoggingOperation &op); template LoggingOperation &&endline(LoggingOperation &&op); -/// @brief Stream manipulator disabling the automatic addition of and end of line token at the end of the operation +/// @brief Stream manipulator disabling the automatic addition of an end of line token at the end of the operation /// @tparam Level The level of the logging operation /// @param op The logging operation modified by this modifier /// @return The modified logging operation diff --git a/sdk/modules/core/python/bindings/metavision_sdk_core_bindings.cpp b/sdk/modules/core/python/bindings/metavision_sdk_core_bindings.cpp index bab36d591..c9c76eb61 100644 --- a/sdk/modules/core/python/bindings/metavision_sdk_core_bindings.cpp +++ b/sdk/modules/core/python/bindings/metavision_sdk_core_bindings.cpp @@ -16,9 +16,11 @@ #endif #include - #include - +#if defined(__APPLE__) +#include +#include "metavision/sdk/base/events/event_cd.h" +#endif #include "metavision/sdk/base/utils/python_bindings_doc.h" #include "pb_doc_core.h" @@ -64,6 +66,11 @@ PYBIND11_MODULE(MODULE_NAME, m) { throw(e); } +#if defined(__APPLE__) + PYBIND11_NUMPY_DTYPE(Metavision::Event2d, x, y, p, t); + PYBIND11_NUMPY_DTYPE(Metavision::EventCD, x, y, p, t); +#endif + // 2. Export event types Metavision::export_event_bbox(m); Metavision::export_colors(m); diff --git a/sdk/modules/core/python/pypkg/metavision_core/event_io/raw_reader.py b/sdk/modules/core/python/pypkg/metavision_core/event_io/raw_reader.py index 0c9f3cb43..2935067e7 100644 --- a/sdk/modules/core/python/pypkg/metavision_core/event_io/raw_reader.py +++ b/sdk/modules/core/python/pypkg/metavision_core/event_io/raw_reader.py @@ -413,7 +413,7 @@ def from_device(cls, device, max_events=int(1e7)): Alternate way of constructing an RawReader from an already initialized HAL device. Note that it is not recommended to leave a device in the global scope, so either create the HAL device - in a function or, delete explicitely afterwards. In some cameras this could result in an undefined + in a function or, delete explicitly afterwards. In some cameras this could result in an undefined behaviour. Args: diff --git a/sdk/modules/core/python/samples/CMakeLists.txt b/sdk/modules/core/python/samples/CMakeLists.txt index 98ab10507..9f9625d52 100644 --- a/sdk/modules/core/python/samples/CMakeLists.txt +++ b/sdk/modules/core/python/samples/CMakeLists.txt @@ -13,5 +13,6 @@ add_subdirectory(metavision_filtering) add_subdirectory(metavision_interop) add_subdirectory(metavision_raw_to_csv) add_subdirectory(metavision_sdk_get_started) +add_subdirectory(metavision_simple_recorder) add_subdirectory(metavision_simple_viewer) add_subdirectory(metavision_sync) diff --git a/sdk/modules/core/python/samples/metavision_sdk_get_started/metavision_sdk_get_started.py b/sdk/modules/core/python/samples/metavision_sdk_get_started/metavision_sdk_get_started.py index a6c2d2710..5b209e252 100644 --- a/sdk/modules/core/python/samples/metavision_sdk_get_started/metavision_sdk_get_started.py +++ b/sdk/modules/core/python/samples/metavision_sdk_get_started/metavision_sdk_get_started.py @@ -51,7 +51,8 @@ def keyboard_cb(key, scancode, action, mods): window.set_keyboard_callback(keyboard_cb) # Event Frame Generator - event_frame_gen = PeriodicFrameGenerationAlgorithm(width, height, accumulation_time_us) + event_frame_gen = PeriodicFrameGenerationAlgorithm(sensor_width=width, sensor_height=height, + accumulation_time_us=accumulation_time_us) def on_cd_frame_cb(ts, cd_frame): window.show(cd_frame) diff --git a/sdk/modules/core/python/samples/metavision_sdk_get_started/metavision_sdk_get_started_v1.py b/sdk/modules/core/python/samples/metavision_sdk_get_started/metavision_sdk_get_started_v1.py index adf9fbf0c..707332931 100644 --- a/sdk/modules/core/python/samples/metavision_sdk_get_started/metavision_sdk_get_started_v1.py +++ b/sdk/modules/core/python/samples/metavision_sdk_get_started/metavision_sdk_get_started_v1.py @@ -36,7 +36,7 @@ def main(): mv_iterator = EventsIterator(input_path=args.input_path, delta_t=1000) for evs in mv_iterator: - print("Camera is running!") + print("Events are available!") if __name__ == "__main__": diff --git a/sdk/modules/core/python/samples/metavision_simple_recorder/CMakeLists.txt b/sdk/modules/core/python/samples/metavision_simple_recorder/CMakeLists.txt new file mode 100644 index 000000000..18fd35d36 --- /dev/null +++ b/sdk/modules/core/python/samples/metavision_simple_recorder/CMakeLists.txt @@ -0,0 +1,13 @@ +# Copyright (c) Prophesee S.A. +# +# Licensed 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. + +install(FILES metavision_simple_recorder.py + DESTINATION share/metavision/sdk/core/python_samples/metavision_simple_recorder + COMPONENT metavision-sdk-core-python-samples +) diff --git a/sdk/modules/core/python/samples/metavision_simple_recorder/metavision_simple_recorder.py b/sdk/modules/core/python/samples/metavision_simple_recorder/metavision_simple_recorder.py new file mode 100644 index 000000000..a5a961b24 --- /dev/null +++ b/sdk/modules/core/python/samples/metavision_simple_recorder/metavision_simple_recorder.py @@ -0,0 +1,83 @@ +# Copyright (c) Prophesee S.A. +# +# Licensed 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. + +""" +Sample code that demonstrates how to use Metavision SDK to record events from a live camera in a RAW file +""" + +from metavision_core.event_io.raw_reader import initiate_device +from metavision_core.event_io import EventsIterator +from metavision_sdk_core import PeriodicFrameGenerationAlgorithm, ColorPalette +from metavision_sdk_ui import EventLoop, BaseWindow, MTWindow, UIAction, UIKeyEvent +import argparse +import time +import os + + +def parse_args(): + """Parse command line arguments.""" + parser = argparse.ArgumentParser(description='Metavision RAW file Recorder sample.', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser.add_argument( + '-o', '--output-dir', default="", help="Directory where to create RAW file with recorded event data") + args = parser.parse_args() + return args + + +def main(): + """ Main """ + args = parse_args() + + # HAL Device on live camera + device = initiate_device("") + + # Start the recording + if device.get_i_events_stream(): + log_path = "recording_" + time.strftime("%y%m%d_%H%M%S", time.localtime()) + ".raw" + if args.output_dir != "": + log_path = os.path.join(args.output_dir, log_path) + print(f'Recording to {log_path}') + device.get_i_events_stream().log_raw_data(log_path) + + # Events iterator on Device + mv_iterator = EventsIterator.from_device(device=device) + height, width = mv_iterator.get_size() # Camera Geometry + + # Window - Graphical User Interface + with MTWindow(title="Metavision Events Viewer", width=width, height=height, + mode=BaseWindow.RenderMode.BGR) as window: + def keyboard_cb(key, scancode, action, mods): + if key == UIKeyEvent.KEY_ESCAPE or key == UIKeyEvent.KEY_Q: + window.set_close_flag() + + window.set_keyboard_callback(keyboard_cb) + + # Event Frame Generator + event_frame_gen = PeriodicFrameGenerationAlgorithm(sensor_width=width, sensor_height=height, fps=25, + palette=ColorPalette.Dark) + + def on_cd_frame_cb(ts, cd_frame): + window.show_async(cd_frame) + + event_frame_gen.set_output_callback(on_cd_frame_cb) + + # Process events + for evs in mv_iterator: + # Dispatch system events to the window + EventLoop.poll_and_dispatch() + event_frame_gen.process_events(evs) + + if window.should_close(): + # Stop the recording + device.get_i_events_stream().stop_log_raw_data() + break + + +if __name__ == "__main__": + main() diff --git a/sdk/modules/core/python/tests/raw_reader_pytest.py b/sdk/modules/core/python/tests/raw_reader_pytest.py index 141d4b674..8fd588134 100644 --- a/sdk/modules/core/python/tests/raw_reader_pytest.py +++ b/sdk/modules/core/python/tests/raw_reader_pytest.py @@ -46,7 +46,7 @@ def pytestcase_rawreader_init_from_device(tmpdir, dataset_dir): filename = os.path.join(dataset_dir, "openeb", "core", "event_io", "recording.raw") device = initiate_device(filename, do_time_shifting=True) # WHEN - video = RawReader.from_device(device, max_events=int(1e7)) + video = RawReader.from_device(device) # THEN assert video.width == 640 @@ -71,7 +71,7 @@ def pytestcase_rawreader_load_n_events(tmpdir, dataset_dir): # GIVEN filename = os.path.join(dataset_dir, "openeb", "core", "event_io", "recording.raw") - video = RawReader(filename, do_time_shifting=False, max_events=int(1e7)) + video = RawReader(filename, do_time_shifting=False) # WHEN events = video.load_n_events(12) # THEN @@ -90,7 +90,7 @@ def pytestcase_rawreader_seek_n_events(tmpdir, dataset_dir): # GIVEN filename = os.path.join(dataset_dir, "openeb", "core", "event_io", "recording.raw") - video = RawReader(filename, do_time_shifting=False, max_events=int(1e7)) + video = RawReader(filename, do_time_shifting=False) # WHEN video.seek_event(11) events = video.load_n_events(1) @@ -113,7 +113,7 @@ def pytestcase_rawreader_load_n_events_all(tmpdir, dataset_dir): # GIVEN filename = os.path.join(dataset_dir, "openeb", "core", "event_io", "recording.raw") - video = RawReader(filename, do_time_shifting=False, max_events=int(1e7)) + video = RawReader(filename, do_time_shifting=False) # WHEN events = video.load_n_events(667850) # THEN diff --git a/sdk/modules/ui/cpp/include/metavision/sdk/ui/pipeline/frame_display_stage.h b/sdk/modules/ui/cpp/include/metavision/sdk/ui/pipeline/frame_display_stage.h index 820db94d5..124881b9d 100644 --- a/sdk/modules/ui/cpp/include/metavision/sdk/ui/pipeline/frame_display_stage.h +++ b/sdk/modules/ui/cpp/include/metavision/sdk/ui/pipeline/frame_display_stage.h @@ -38,11 +38,9 @@ class FrameDisplayStage : public BaseStage { /// @param height Window's initial height /// @param mode Window's rendering mode (i.e. either BGR or GRAY). Cannot be changed afterwards /// @param auto_exit Flag indicating if the application automatically closes if the user presses 'Q' or 'ESCAPE' + /// @warning Must only be called from the main thread FrameDisplayStage(const std::string &title, int width, int height, - Window::RenderMode mode = Window::RenderMode::BGR, bool auto_exit = true) : - window_(title, width, height, mode) { - init(auto_exit); - } + Window::RenderMode mode = Window::RenderMode::BGR, bool auto_exit = true); /// @brief Constructs a new frame display stage given an explicit previous stage /// @param prev_stage Stage producing the input image for this display stage @@ -51,56 +49,27 @@ class FrameDisplayStage : public BaseStage { /// @param height Window's initial height /// @param mode Window's rendering mode (i.e. either BGR or GRAY). Cannot be changed afterwards /// @param auto_exit Flag indicating if the application automatically closes if the user presses 'Q' or 'ESCAPE' + /// @warning Must only be called from the main thread FrameDisplayStage(BaseStage &prev_stage, const std::string &title, int width, int height, - Window::RenderMode mode = Window::RenderMode::BGR, bool auto_exit = true) : - FrameDisplayStage(title, width, height, mode, auto_exit) { - set_previous_stage(prev_stage); - } + Window::RenderMode mode = Window::RenderMode::BGR, bool auto_exit = true); + + /// @brief Destructor + /// @warning Must only be called from the main thread + ~FrameDisplayStage(); /// @brief Sets a callback that is called when the user presses a key /// /// @note The callback is only called when the window has the focus /// @param cb The callback to call - void set_key_callback(const Window::KeyCallback &cb) { - on_key_cb_ = cb; - } + void set_key_callback(const Window::KeyCallback &cb); private: - void init(bool auto_exit) { - static bool is_pre_step_cb_set = false; - if (!is_pre_step_cb_set) { - set_setup_callback( - [this]() { pipeline().add_pre_step_callback([]() { EventLoop::poll_and_dispatch(); }); }); - is_pre_step_cb_set = true; - } - - set_consuming_callback([this](const boost::any &data) { - try { - auto res = boost::any_cast(data); - timestamp t = res.first; - FramePtr &f = res.second; - if (f && !f->empty()) - window_.show(*f); - } catch (boost::bad_any_cast &c) { MV_SDK_LOG_ERROR() << c.what(); } - }); - - window_.set_keyboard_callback([this, auto_exit](UIKeyEvent key, int scancode, UIAction action, int mods) { - on_key_cb_(key, scancode, action, mods); - - if (auto_exit) { - if (action == UIAction::RELEASE) { - if (key == UIKeyEvent::KEY_ESCAPE || key == UIKeyEvent::KEY_Q) - this->pipeline().cancel(); - } - } - }); - - on_key_cb_ = [](UIKeyEvent key, int scancode, UIAction action, int mods) {}; - } + void init(bool auto_exit); // Key pressed callback Window window_; Window::KeyCallback on_key_cb_; + static std::uint32_t instance_counter_; }; } // namespace Metavision diff --git a/sdk/modules/ui/cpp/src/CMakeLists.txt b/sdk/modules/ui/cpp/src/CMakeLists.txt index 0d027dab5..524ae54b9 100644 --- a/sdk/modules/ui/cpp/src/CMakeLists.txt +++ b/sdk/modules/ui/cpp/src/CMakeLists.txt @@ -9,6 +9,7 @@ target_sources(metavision_sdk_ui PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/base_window.cpp ${CMAKE_CURRENT_SOURCE_DIR}/event_loop.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/frame_display_stage.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mt_window.cpp ${CMAKE_CURRENT_SOURCE_DIR}/texture_utils.cpp ${CMAKE_CURRENT_SOURCE_DIR}/window.cpp diff --git a/sdk/modules/ui/cpp/src/frame_display_stage.cpp b/sdk/modules/ui/cpp/src/frame_display_stage.cpp new file mode 100644 index 000000000..84c4cf98f --- /dev/null +++ b/sdk/modules/ui/cpp/src/frame_display_stage.cpp @@ -0,0 +1,66 @@ +/********************************************************************************************************************** + * Copyright (c) Prophesee S.A. * + * * + * Licensed 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. * + **********************************************************************************************************************/ +#include "metavision/sdk/ui/pipeline/frame_display_stage.h" + +namespace Metavision { + +std::uint32_t FrameDisplayStage::instance_counter_ = 0; + +FrameDisplayStage::FrameDisplayStage(const std::string &title, int width, int height, Window::RenderMode mode, + bool auto_exit) : + window_(title, width, height, mode) { + init(auto_exit); +} + +FrameDisplayStage::FrameDisplayStage(BaseStage &prev_stage, const std::string &title, int width, int height, + Window::RenderMode mode, bool auto_exit) : + FrameDisplayStage(title, width, height, mode, auto_exit) { + set_previous_stage(prev_stage); +} + +FrameDisplayStage::~FrameDisplayStage() { + --instance_counter_; +} + +void FrameDisplayStage::set_key_callback(const Window::KeyCallback &cb) { + on_key_cb_ = cb; +} + +void FrameDisplayStage::init(bool auto_exit) { + if (instance_counter_++ == 0) { + set_setup_callback([this]() { pipeline().add_pre_step_callback([]() { EventLoop::poll_and_dispatch(); }); }); + } + + set_consuming_callback([this](const boost::any &data) { + try { + auto res = boost::any_cast(data); + timestamp t = res.first; + FramePtr &f = res.second; + if (f && !f->empty()) + window_.show(*f); + } catch (boost::bad_any_cast &c) { MV_SDK_LOG_ERROR() << c.what(); } + }); + + window_.set_keyboard_callback([this, auto_exit](UIKeyEvent key, int scancode, UIAction action, int mods) { + on_key_cb_(key, scancode, action, mods); + + if (auto_exit) { + if (action == UIAction::RELEASE) { + if (key == UIKeyEvent::KEY_ESCAPE || key == UIKeyEvent::KEY_Q) + this->pipeline().cancel(); + } + } + }); + + on_key_cb_ = [](UIKeyEvent key, int scancode, UIAction action, int mods) {}; +} + +} // namespace Metavision \ No newline at end of file