diff --git a/.gitignore b/.gitignore index e6cf7a9eafcb7a7a0ad65e74949cfa0132e8b895..7f474dc84a1530f97e7e33f550d1c0f2f3b3be82 100644 --- a/.gitignore +++ b/.gitignore @@ -182,4 +182,6 @@ dmypy.json # Cython debug symbols cython_debug/ -.vscode/ \ No newline at end of file +.vscode/ + +!docs/Makefile \ No newline at end of file diff --git a/README.md b/README.md index b75baf991cad98753e45be17eed2a19ee17222b3..017443f9104d197c529ecc551a9196d1d1d8b22d 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,14 @@ box = Sandbox(refresh=250) box.init("config.yaml") box.func = my_function box.start() -``` \ No newline at end of file +``` + +See the documentation for more information. + +To make the documentation : + +```bash +python3 -m pip install sphinx sphinx_rtd_theme +cd ./docs +make html +``` diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..d4bb2cbb9eddb1bb1b4f366623044af8e4830919 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/ar_sandbox.examples.rst b/docs/ar_sandbox.examples.rst new file mode 100644 index 0000000000000000000000000000000000000000..b764a34924a9353a85bff11d8741fe5a3d877838 --- /dev/null +++ b/docs/ar_sandbox.examples.rst @@ -0,0 +1,21 @@ +ar\_sandbox.examples package +============================ + +Submodules +---------- + +ar\_sandbox.examples.examples module +------------------------------------ + +.. automodule:: ar_sandbox.examples.examples + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: ar_sandbox.examples + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/ar_sandbox.rst b/docs/ar_sandbox.rst new file mode 100644 index 0000000000000000000000000000000000000000..81003ba75fabf3cf685cf17238d8848cff56251f --- /dev/null +++ b/docs/ar_sandbox.rst @@ -0,0 +1,30 @@ +ar\_sandbox package +=================== + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + ar_sandbox.examples + ar_sandbox.wrapper + +Submodules +---------- + +ar\_sandbox.sandbox module +-------------------------- + +.. automodule:: ar_sandbox.sandbox + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: ar_sandbox + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/ar_sandbox.wrapper.rst b/docs/ar_sandbox.wrapper.rst new file mode 100644 index 0000000000000000000000000000000000000000..34b954e481248d5bae21101df7537abb90dabe28 --- /dev/null +++ b/docs/ar_sandbox.wrapper.rst @@ -0,0 +1,21 @@ +ar\_sandbox.wrapper package +=========================== + +Submodules +---------- + +ar\_sandbox.wrapper.sandbox\_wrapper module +------------------------------------------- + +.. automodule:: ar_sandbox.wrapper.sandbox_wrapper + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: ar_sandbox.wrapper + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000000000000000000000000000000000000..82f9d40d05b878899c88dc20ac20ec3d5a53d452 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,60 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +import os +import sys +sys.path.insert(0, os.path.abspath('../src/')) + + +# -- Project information ----------------------------------------------------- + +project = 'AR_Sandbox Python Wrapper' +copyright = '2021, HEPIA' +author = 'Alexis Durgnat' + +# The full version, including alpha/beta/rc tags +release = '0.0.1' + + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.viewcode", + "sphinx_rtd_theme" +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'sphinx_rtd_theme' +# or maybe you love +# html_theme = 'alabaster' + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] \ No newline at end of file diff --git a/docs/howto/howto.rst b/docs/howto/howto.rst new file mode 100644 index 0000000000000000000000000000000000000000..1b91ec417c58ec21de4cc095b0d28d398f8de25a --- /dev/null +++ b/docs/howto/howto.rst @@ -0,0 +1,10 @@ +How to use +=================== + +It's possible to use the provided class (easier), or the wrapper directly + +.. toctree:: + :maxdepth: 2 + + sandbox + wrapper \ No newline at end of file diff --git a/docs/howto/sandbox.rst b/docs/howto/sandbox.rst new file mode 100644 index 0000000000000000000000000000000000000000..b532d644daa142c505200cd1f63daf4a8cff7802 --- /dev/null +++ b/docs/howto/sandbox.rst @@ -0,0 +1,35 @@ +Using the Sandbox class +======================= + +Using the Sandbox class is pretty simple + +.. code-block:: python + + # Import the class + from ar_sandbox import Sandbox + + # Define a function, taking the depth and the frame as parameters + # and returning a 3-channel BGR frame of the same size as depth. + # It's possible to pass aditionnal arguments + + def my_awesome_function(depth, frame, my_arg="Hello"): + # Do something with the arguments + return new_frame + + + # Instantiate the sandbox, and load the configuration : + box = Sandbox(refresh_rate=20) # in [ms] + box.init("./sandbox_conf.yaml") + + # Define the on_frame function of the sandbox to yours + box.on_frame = my_awesome_function + + # Run the sandbox with 'box.start()' + # You may pass aditionnal arguments to the on_frame call by passing them + # to the start function. + try: + box.start(my_arg="something") + except: + box.stop() + exit(1) + \ No newline at end of file diff --git a/docs/howto/wrapper.rst b/docs/howto/wrapper.rst new file mode 100644 index 0000000000000000000000000000000000000000..db38364695bc2894298fde1dd08b3f4511aa5ef3 --- /dev/null +++ b/docs/howto/wrapper.rst @@ -0,0 +1,51 @@ +Using the wrapper +=================== + +It is also possible to directly use the wrapper. + + +.. code-block:: python + + + # Import the wrapper + from ar_sandbox.wrapper import sandbox_wrapper as wrapper + + import cv2 # For displaying the result + import numpy as np # For matrix manipulation + + WINDOW_NAME = "MyWindow" + + sandbox = wrapper.Sandbox() # Instantiate a new C++ Sandbox + + # Create a cv2 window + cv2.namedWindow(WINDOW_NAME, cv2.WND_PROP_FULLSCREEN) + cv2.setWindowProperty(WINDOW_NAME, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) + + # Load the configuration file + sandbox.load_config('./sandbox_conf.yaml') + + # initialize the sandbox + sandbox.init_sandbox() + + while (True): + sandbox.capture_frame() # Update camera buffers + + curr_depth = sandbox.get_depth_frame() # Get the depth frame + + # Convert it to a readable numpy array : + curr_depth = np.array(curr_depth, copy = False) + + frame = ... # A 3 channel frame of the same size as the depth (BGR) + + # Adjust the projection according to the sandbox parameter. + # The numpy array should be converted back to cvMat + frame = np.array(sandbox.adjust_projection(wrapper.cvMat3b(frame), wrapper.cvMatf(curr_depth)), copy=False) + + + cv2.imshow(winname=WINDOW_NAME, mat=frame) + + # Wait for a key for 20 [ms] to exit + if cv2.waitKey(20) == 27: # Wait for 'Esc' key to stop + break + + cv2.destroyAllWindows() \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..548a281256adf5c0bfaaea1b08009db5851c6022 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,21 @@ +.. AR_Sandbox Python Wrapper documentation master file, created by + sphinx-quickstart on Mon Nov 1 13:24:38 2021. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to AR_Sandbox Python Wrapper's documentation! +===================================================== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + howto/howto + modules + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000000000000000000000000000000000000..8084272b4b7828a0748ae9209f92611e196801de --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/docs/modules.rst b/docs/modules.rst new file mode 100644 index 0000000000000000000000000000000000000000..a34754103b1afd7335e0fe8dcc79d0143aff47f1 --- /dev/null +++ b/docs/modules.rst @@ -0,0 +1,7 @@ +ar_sandbox +========== + +.. toctree:: + :maxdepth: 4 + + ar_sandbox