Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e01a8df
chore: configure mypy in place of the unused pyright block
petercorke Nov 18, 2026
14ae5ba
refactor: give the Image mixins a base class mypy can evaluate
petercorke Nov 18, 2026
539ec6b
fix: correct imports and declarations that mypy could not resolve
petercorke Nov 18, 2026
25524bf
fix: clear mypy errors in the small modules; check Image conforms to …
petercorke Nov 18, 2026
9a4052b
fix: clear mypy errors in PointCloud, Kernel, ImageBlobs, ImageWholeF…
petercorke Nov 18, 2026
161cef9
fix: clear mypy errors in BagOfWords and ImageFiducials
petercorke Nov 18, 2026
e6063c6
fix: clear mypy errors in BundleAdjust, ImageRegionFeatures, base/col…
petercorke Nov 18, 2026
bfc832e
fix: clear mypy errors in base/graphics and base/imageio
petercorke Nov 18, 2026
daeeb6e
fix: clear mypy errors in ImageSpatial
petercorke Nov 18, 2026
262d13e
fix: clear mypy errors in ImageProcessing and ImageCore
petercorke Nov 18, 2026
eb92a78
fix: clear mypy errors in Sources
petercorke Nov 18, 2026
240a3ad
fix: clear mypy errors in ImagePointFeatures
petercorke Nov 18, 2026
887637b
fix: clear mypy errors in VisualServo
petercorke Nov 18, 2026
0aa444c
fix: clear mypy errors in Camera
petercorke Nov 18, 2026
21cdb5c
feat: add py.typed marker so type checkers use the package's annotations
petercorke Nov 18, 2026
741738f
chore: merge main into feat/py-typed
petercorke Nov 18, 2026
c50392a
Merge branch 'main' into feat/py-typed
petercorke Nov 18, 2026
13df278
chore: tidy imports and asserts flagged by Codacy
petercorke Nov 18, 2026
119c74d
chore: remove more unused imports and locals flagged by Codacy
petercorke Nov 18, 2026
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
10 changes: 6 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ dependencies = [
# ocr - OCR support via pytesseract
# tool - dependencies for the mvtbtool interactive shell

dev = ["pytest", "pytest-timeout", "pytest-xvfb", "coverage", "ruff", "nbmake"]
dev = ["pytest", "pytest-timeout", "pytest-xvfb", "coverage", "ruff", "nbmake", "mypy"]

ros = ["rosbags", "roslibpy", "websockets"]

Expand Down Expand Up @@ -127,9 +127,11 @@ known-first-party = ["machinevisiontoolbox"]
# honours this file).
exclude_dirs = ["tests"]

[tool.pyright]
include = ["src"]
ignore = ["docs", "tests", "examples"]
[tool.mypy]
mypy_path = "src"
files = ["src/machinevisiontoolbox"]
ignore_missing_imports = true
warn_unused_ignores = true

[project.scripts]
mvtbtool = "machinevisiontoolbox.bin.mvtbtool:main"
Expand Down
22 changes: 12 additions & 10 deletions src/machinevisiontoolbox/BagOfWords.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def __init__(
features = images
else:
# passed images, compute the features
features = []
features = [] # type: ignore[assignment]
for image in images:
features += image.SIFT()
features.sort(by="scale", inplace=True)
Expand All @@ -117,7 +117,7 @@ def __init__(
if seed is not None:
cv2.setRNGSeed(seed)

ret, labels, centroids = cv2.kmeans(
ret, labels, centroids = cv2.kmeans( # type: ignore[call-overload]
data=features._descriptor,
K=k,
bestLabels=None,
Expand All @@ -131,7 +131,7 @@ def __init__(
self._words = labels.ravel()
self._labels = labels.ravel()
self._centroids = centroids
self._word_freq_vectors = None
self._word_freq_vectors: np.ndarray | None = None

self._nstopwords = nstopwords
if nstopwords > 0:
Expand All @@ -141,16 +141,16 @@ def __init__(

maxwords = self.k - self.nstopwords

W = []
Wcols = []
id = np.array(self._features.id)
for i in range(self.nimages):
# get the words associated with image i
words = self.words[id == i]

# create columns of the W
v = BagOfWords._word_freq_vector(words, maxwords)
W.append(v)
W = np.column_stack(W)
Wcols.append(v)
W = np.column_stack(Wcols)

N = self.nimages

Expand Down Expand Up @@ -200,12 +200,14 @@ def wwfv(self, i: int | None = None) -> np.ndarray:
.. note:: The word vector is expensive to compute so a lazy evaluation
is performed on the first call to this method.
"""
if self._word_freq_vectors is None:
raise ValueError("word frequency vectors have not been computed")
if i is not None:
v = self._word_freq_vectors[:, i]
if v.ndim == 1:
return np.c_[v]
else:
return self._word_freq_vectors
return v
return self._word_freq_vectors

@property
def nimages(self) -> int:
Expand Down Expand Up @@ -465,7 +467,7 @@ def retrieve(self, images: Image | _ImageQueries | np.ndarray) -> tuple[int, flo

S = self.similarity(images).ravel()
k = np.argmax(S)
return k, S[k]
return int(k), float(S[k])

def features(self, word: int) -> BaseFeature2D:
"""
Expand Down Expand Up @@ -587,7 +589,7 @@ def exemplars(
from machinevisiontoolbox import Image

exemplars = []
count = Counter()
count: Counter[Any] = Counter()
if images is None:
images = self._images
for feature in self.features(word):
Expand Down
19 changes: 11 additions & 8 deletions src/machinevisiontoolbox/BundleAdjust.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@

# pgraph 1.0 has a single Vertex class and deprecates UVertex; 0.6.x has only
# UVertex. A vertex has no direction of its own in 1.0, so they are equivalent.
_Vertex = getattr(pgraph, "Vertex", None) or pgraph.UVertex
_Vertex: Any = getattr(pgraph, "Vertex", None) or pgraph.UVertex


class _Common:
_index: int
_index2: int
_fixed: bool

@property
def index(self) -> int:
"""
Expand Down Expand Up @@ -209,11 +213,11 @@ def __init__(self, camera: CentralCamera) -> None:
self._nlandmarks = 0 # number of landmark points
self._nvarstate = 0

self.views = [] # list of view nodes
self.landmarks = [] # list of landmark nodes
self.views: list[Any] = [] # list of view nodes
self.landmarks: list[Any] = [] # list of landmark nodes

self.fixedviews = [] # list of view nodes that are fixed
self.fixedlandmarks = [] # list of landmark nodes that are fixed
self.fixedviews: list[Any] = [] # list of view nodes that are fixed
self.fixedlandmarks: list[Any] = [] # list of landmark nodes that are fixed

self.index_valid = False

Expand Down Expand Up @@ -595,9 +599,8 @@ def optimize(
print(f"Bundle adjustment cost {self.errors(x0):.3g} -- initial")
for i in range(iterations):
if animate:
if not retain:
plt.clf()
g2.plot()
plt.clf()
self.plot(block=False)
plt.pause(0.5)

ta = time.perf_counter()
Expand Down
Loading
Loading