Skip to content
Snippets Groups Projects
Commit e2a8d65a authored by Alexis Durgnat's avatar Alexis Durgnat :milky_way:
Browse files

Add sphinx doc

parent b2a39db4
No related branches found
No related tags found
No related merge requests found
...@@ -182,4 +182,6 @@ dmypy.json ...@@ -182,4 +182,6 @@ dmypy.json
# Cython debug symbols # Cython debug symbols
cython_debug/ cython_debug/
.vscode/ .vscode/
\ No newline at end of file
!docs/Makefile
\ No newline at end of file
...@@ -18,4 +18,14 @@ box = Sandbox(refresh=250) ...@@ -18,4 +18,14 @@ box = Sandbox(refresh=250)
box.init("config.yaml") box.init("config.yaml")
box.func = my_function box.func = my_function
box.start() 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
```
# 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)
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:
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:
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:
# 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
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
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
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
.. 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`
@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
ar_sandbox
==========
.. toctree::
:maxdepth: 4
ar_sandbox
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment