Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/source/bundle-adjust.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ Scene graph classes
-------------------

.. autoclass:: machinevisiontoolbox.BundleAdjust.ViewPoint
:no-index:
:members:
:inherited-members:

.. autoclass:: machinevisiontoolbox.BundleAdjust.Landmark
:no-index:
:members:
:inherited-members:

.. autoclass:: machinevisiontoolbox.BundleAdjust.Observation
:no-index:
:members:
:inherited-members:
72 changes: 72 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
import sys
import inspect
from sphinx.ext import intersphinx
import importlib
from pathlib import Path
from importlib.metadata import version as _pkg_version
Expand Down Expand Up @@ -121,6 +122,7 @@

# -- Cross-project links -----------------------------------------------------
intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"scipy": ("https://docs.scipy.org/doc/scipy/", None),
"matplotlib": ("https://matplotlib.org/stable/", None),
Expand All @@ -139,6 +141,29 @@
("py:class", "H"),
("py:class", "numpy._typing.DTypeLike"),
]
# Shape annotations such as ``ndarray(N,2)`` and prose types such as "2-tuple" or
# "Vertex subclass" are split into words by Sphinx and treated as class names.
nitpick_ignore_regex = [
("py:class", r"ndarray"),
("py:class", r"\d+"), # dimensions: 2, 3, 4, ...
("py:class", r"[A-Z]\d?"), # symbolic dimensions: N, M, N1, N2, ...
("py:class", r"n"),
("py:class", r"N elements"),
("py:class", r"\d+-tuple"),
("py:class", r"N-tuple"),
("py:class", r".* subclass"),
("py:class", r"scalar|string|callable|axes|_type_"),
# pgraph's inherited docstrings use names relative to the pgraph package
("py:(class|meth|attr)", r"(Graph|UGraph|DGraph|PGraph|Edge|Vertex)(\..+)?"),
# NumPy private typing aliases leak into signatures
("py:class", r"numpy\._typing\..*"),
("py:class", r"Dtype"), # type alias used in signatures
("py:class", r"(machinevisiontoolbox\.Camera\.)?CameraBase"), # undocumented base
("py:class", r"\d+[A-Z]"), # shape such as 2N
("py:(class|meth|func|attr)", r"pgraph\..*"),
# OpenCV publishes no Sphinx inventory
("py:(class|obj|func|meth)", r"(opencv|cv2)\..*"),
]
# maybe issues with cv2 https://stackoverflow.com/questions/30939867/how-to-properly-write-cross-references-to-external-documentation-with-intersphin


Expand Down Expand Up @@ -369,7 +394,54 @@ def _sort_members_ci(self, documenters, order):


# -- Sphinx application hooks ------------------------------------------------
def _resolve_toolbox_names(app, env, node, contnode):
"""Resolve a bare name such as ``Image`` or ``CameraBase`` to this package.

Docstrings refer to toolbox classes without their full path. When Sphinx
cannot find the name as written, try it under ``machinevisiontoolbox``.
"""
if node.get("refdomain") != "py":
return None
target = node.get("reftarget", "")
if target.startswith("machinevisiontoolbox."):
return None
py = env.get_domain("py")
for prefix in (
"machinevisiontoolbox.",
"machinevisiontoolbox.Image.",
"machinevisiontoolbox.PointCloud.",
):
ref = py.resolve_xref(
env,
node.get("refdoc", ""),
app.builder,
node["reftype"],
prefix + target,
node,
contnode,
)
if ref is not None:
return ref
# spatialmath names (SE3, Polygon2, plot_line, ...), via its inventory
for prefix in (
"spatialmath.",
"spatialmath.pose3d.",
"spatialmath.pose2d.",
"spatialmath.geom2d.",
"spatialmath.base.",
"spatialmath.base.graphics.",
):
newnode = node.copy()
newnode["reftarget"] = prefix + target
ref = intersphinx.resolve_reference_in_inventory(env, "smtb", newnode, contnode)
if ref is not None:
return ref
return None


def setup(app):
app.connect("missing-reference", _resolve_toolbox_names)

# Custom stylesheet for docs/site-level overrides.
app.add_css_file("custom.css")

Expand Down
5 changes: 5 additions & 0 deletions docs/source/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ We can model a standard central-perspective camera using its known parameters:

camera = mvtb.CentralCamera(f=0.015, rho=10e-6, imagesize=[1280, 1024], pp=[640, 512], name="mycamera")
print(camera)

which displays

.. code-block:: text

Name: mycamera [CentralCamera]
focal length: (array([0.015]), array([0.015]))
pixel size: 1e-05 x 1e-05
Expand Down
4 changes: 2 additions & 2 deletions docs/source/sources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
The toolbox provides a variety of sources for these objects. They can be obtained from
files, from cameras, from ROS topics and bag files, from the web, and from other
sources. The toolbox provides a convenient interface to these sources, and the objects
they produce are instances of the :class:`~machinevisiontoolbox.ImageCore.Image` and
they produce are instances of the :class:`~machinevisiontoolbox.Image` and
:class:`~machinevisiontoolbox.PointCloudCore.PointCloud` classes, which have a large
number of methods for processing and displaying them.

Expand Down Expand Up @@ -84,7 +84,7 @@ tensor. For example, to read a video file and display each frame::
Image Sources
-------------

:class:`~machinevisiontoolbox.ImageCore.Image` objects can be conveniently obtained from a variety of sources:
:class:`~machinevisiontoolbox.Image` objects can be conveniently obtained from a variety of sources:

.. autosummary::
:toctree: stubs
Expand Down
10 changes: 5 additions & 5 deletions src/machinevisiontoolbox/Camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ def _new_imageplane(
:param fig: Matplotlib figure number, defaults to ``None``
:type fig: int, optional
:param ax: Matplotlob axes, defaults to ``None``
:type ax: :class:`matplotlib.axes`, optional
:type ax: :class:`~matplotlib.axes.Axes`, optional
:return: whether virtual image plane exists
:rtype: bool

Expand Down Expand Up @@ -858,10 +858,10 @@ def plot_point(
:param pose: pose of the camera, defaults to ``None``
:type pose: :class:`~spatialmath.pose3d.SE3`, optional
:param ax: axes to plot into
:type ax: :class:`matplotlib.axes`
:type ax: :class:`~matplotlib.axes.Axes`
:param kwargs: additional arguments passed to :obj:`~matplotlib.pyplot.plot`
:return: Matplotlib line objects
:rtype: list of :class:`~matplotlib.lines.Line2d`
:rtype: list of :class:`~matplotlib.lines.Line2D`

3D world points are first projected to the image plane and then
plotted on the camera's virtual image plane.
Expand Down Expand Up @@ -1177,11 +1177,11 @@ def plot(
:param projection: projection model for new axes, defaults to 'ortho'
:type projection: str, optional
:param ax: axes to draw in, defaults to current 3D axes
:type ax: :class:`~matplotlib.Axes3D`, optional
:type ax: :class:`~mpl_toolkits.mplot3d.axes3d.Axes3D`, optional
:raises ValueError: called unbound (eg. ``CentralCamera.plot(...)``)
without a ``pose``
:return: axes drawn into
:rtype: :class:`~matplotlib.Axes3D`
:rtype: :class:`~mpl_toolkits.mplot3d.axes3d.Axes3D`

Plot a 3D icon representing the pose of a camera into a 3D Matplotlib
plot. Two icons are supported: the traditional frustum, and a
Expand Down
9 changes: 9 additions & 0 deletions src/machinevisiontoolbox/ImageConstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def Zeros(
:type dtype: str or NumPy dtype, optional

|dtype_aliases|

:param like: template image supplying default ``size`` and ``colororder``
when those are not given explicitly
:type like: :class:`Image` or None, optional
Expand Down Expand Up @@ -211,6 +212,7 @@ def Constant(
:type dtype: str or NumPy dtype, optional

|dtype_aliases|

:param like: template image supplying default ``size``, ``dtype`` and
``colororder`` when those are not given explicitly
:type like: :class:`Image` or None, optional
Expand Down Expand Up @@ -417,6 +419,7 @@ def Random(
:type dtype: str or NumPy dtype, optional

|dtype_aliases|

:param maxval: maximum value for random values, defaults to None
:type maxval: same as ``dtype``, optional
:param pdf: probability density function for pixel values, defaults to None
Expand Down Expand Up @@ -576,6 +579,7 @@ def Squares(
:type dtype: str or NumPy dtype, optional

|dtype_aliases|

:param colororder: color plane names for the output image, defaults to None
:type colororder: str or None, optional
:param like: template image supplying default ``size``, ``dtype`` and
Expand Down Expand Up @@ -670,6 +674,7 @@ def Circles(
:type dtype: str or NumPy dtype, optional

|dtype_aliases|

:param colororder: color plane names for the output image, defaults to None
:type colororder: str or None, optional
:param like: template image supplying default ``size``, ``dtype`` and
Expand Down Expand Up @@ -764,6 +769,7 @@ def Ramp(
:type dtype: str or NumPy dtype, optional

|dtype_aliases|

:param colororder: color plane names for the output image, defaults to None
:type colororder: str or None, optional
:param like: template image supplying default ``size``, ``dtype`` and
Expand Down Expand Up @@ -862,6 +868,7 @@ def Sin(
:type dtype: str or NumPy dtype, optional

|dtype_aliases|

:param colororder: color plane names for the output image, defaults to None
:type colororder: str or None, optional
:param like: template image supplying default ``size``, ``dtype`` and
Expand Down Expand Up @@ -944,6 +951,7 @@ def Chequerboard(
:type dtype: str or NumPy dtype, optional

|dtype_aliases|

:param colororder: color plane names for the output image, defaults to None
:type colororder: str or None, optional
:param like: template image supplying default ``size``, ``dtype`` and
Expand Down Expand Up @@ -1037,6 +1045,7 @@ def Polygons(
:type dtype: str or NumPy dtype, optional

|dtype_aliases|

:param colororder: color plane names for the output image, defaults to None
:type colororder: str or None, optional
:param like: template image supplying default ``size``, ``dtype`` and
Expand Down
6 changes: 3 additions & 3 deletions src/machinevisiontoolbox/ImagePointFeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def table(self) -> None:
Each row is in the table includes: the index in the feature vector,
centroid coordinate, feature strength, feature scale and image id.

:seealso: :meth:`str`
:seealso: ``str``
"""
columns = [
Column("#"),
Expand Down Expand Up @@ -1123,7 +1123,7 @@ def plot(
:type handthickness: int, optional
:param handalpha: transparency of clock hand, defaults to 1
:type handalpha: int, optional
:param kwargs: options passed to :obj:`matplotlib.Circle` such as color,
:param kwargs: options passed to :class:`matplotlib.patches.Circle` such as color,
alpha, edgecolor, etc.
:type kwargs: dict

Expand Down Expand Up @@ -1196,7 +1196,7 @@ def draw(
:type handthickness: int, optional
:param handalpha: transparency of clock hand, defaults to 1
:type handalpha: int, optional
:param kwargs: options passed to :obj:`matplotlib.Circle` such as color,
:param kwargs: options passed to :class:`matplotlib.patches.Circle` such as color,
alpha, edgecolor, etc.
:type kwargs: dict

Expand Down
8 changes: 4 additions & 4 deletions src/machinevisiontoolbox/ImageSpatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def convolve(
Image convolution

:param K: convolution kernel
:type K: :class:`~.Kernel` or ndarray, optional
:type K: :class:`~machinevisiontoolbox.Kernel.Kernel` or ndarray, optional
:param mode: option for convolution, defaults to 'same'
:type mode: str, optional
:param border: option for boundary handling, defaults to 'reflect'
Expand Down Expand Up @@ -258,7 +258,7 @@ def convolve(
.. important:: Uses OpenCV functions ``cv2.filter2D`` and ``cv2.copyMakeBorder`` which accept multiple-channel, CV_8U, CV_16U, CV_16S, CV_32F or CV_64F images.

:seealso:
:class:`~.Kernel`
:class:`~machinevisiontoolbox.Kernel.Kernel`
:meth:`~smooth`
`cv2.filter2D <https://docs.opencv.org/4.x/d4/d86/group__imgproc__filter.html#ga27c049795ce870216ddfb366086b5a04>`_
`cv2.copyMakeBorder <https://docs.opencv.org/4.x/d2/de8/group__core__array.html#ga2ac1049c2c3dd25c2b41bffe17658a36>`_
Expand Down Expand Up @@ -348,7 +348,7 @@ def gradients(
Compute horizontal and vertical gradients

:param K: derivative kernel, defaults to Sobel
:type K: :class:`~machinevisiontoolbox.ImageSpatial.Kernel` or ndarray, optional
:type K: :class:`~machinevisiontoolbox.Kernel.Kernel` or ndarray, optional
:param mode: option for convolution, see :meth:`convolve`, defaults to 'same'
:type mode: str, optional
:param border: option for boundary handling, see :meth:`convolve`, defaults to 'reflect'
Expand All @@ -371,7 +371,7 @@ def gradients(
:references:
- |RVC3|, Section 11.5.1.3.

:seealso: :class:`~machinevisiontoolbox.ImageSpatial.Kernel`
:seealso: :class:`~machinevisiontoolbox.Kernel.Kernel`
"""
if K is None:
K = Kernel.Sobel()
Expand Down
2 changes: 0 additions & 2 deletions src/machinevisiontoolbox/Kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ def __init__(self, K: np.ndarray, name: str | None = None) -> None:
processing operations. They are created by a number of class
methods that generate common kernels such as Gaussian, Laplacian, etc.

:class:`ImageCore.Image` :class:`machinevisiontoolbox.ImageCore.Image` :class:`machinevisiontoolbox.Image`

:seealso: :meth:`Gauss` :meth:`Laplace` :meth:`Sobel` :meth:`DoG` :meth:`LoG` :meth:`DGauss` :meth:`Circle` :meth:`Box`
"""
if not isinstance(K, np.ndarray) and K.ndim != 2:
Expand Down
2 changes: 1 addition & 1 deletion src/machinevisiontoolbox/base/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ def mpl_styling(
to specify styling in a compact format string, while still allowing for more
detailed styling through keyword arguments with decent defaults.

.. code-block:: python
.. code-block:: text

def function(*fmt, ..., **kwargs):
options = mpl_styling(fmt, defaults={color='red', marker='o'}, kwargs=kwargs)
Expand Down
6 changes: 4 additions & 2 deletions src/machinevisiontoolbox/base/imageio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1430,8 +1430,10 @@ def iwrite(

.. code-block:: python

from machinevisiontoolbox import iwrite import numpy as np image =
np.zeros((20,20)) # 20x20 black image iwrite(image, "black.png")
from machinevisiontoolbox import iwrite
import numpy as np
image = np.zeros((20,20)) # 20x20 black image
iwrite(image, "black.png")


.. note::
Expand Down
Loading