Skip to content

Commit

Permalink
hooks: skimage.feature: collect the file with ORB descriptor positions
Browse files Browse the repository at this point in the history
Have the hook for `skimage.feature` collect the
`orb_descriptor_positions.txt` file, which is required by
`skimage.feature.ORB`.

Add a basic test for ORB detector and descriptor extractor.
  • Loading branch information
rokm committed Dec 20, 2023
1 parent 8ff49f1 commit 4a48d55
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
3 changes: 3 additions & 0 deletions news/675.update.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Update hook for ``skimage.feature`` to collect the
``orb_descriptor_positions.txt`` data file, which is required by
the ``skimage.feature.ORB`` class.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
# The following missing module prevents import of skimage.feature with skimage 0.17.x.
hiddenimports = ['skimage.feature._orb_descriptor_positions', ]

# Collect the data file with ORB descriptor positions. In earlier versions of scikit-image, this file was in
# `skimage/data` directory, and it was moved to `skimage/feature` in v0.17.0. Collect if from wherever it is.
datas = collect_data_files('skimage', includes=['**/orb_descriptor_positions.txt'])

# As of scikit-image 0.22.0, we need to collect the __init__.pyi file for `lazy_loader`, as well as collect submodules
# due to lazy loading.
if is_module_satisfies("scikit-image >= 0.22.0"):
datas = collect_data_files("skimage.feature", includes=["*.pyi"])
datas += collect_data_files("skimage.feature", includes=["*.pyi"])
hiddenimports = collect_submodules('skimage.feature', filter=lambda name: name != 'skimage.feature.tests')
31 changes: 31 additions & 0 deletions src/_pyinstaller_hooks_contrib/tests/test_scikit_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,34 @@ def test_skimage(pyi_builder, submodule):
pyi_builder.test_source("""
import skimage.{0}
""".format(submodule))


# Test the ORB descriptor, which requires the data file with descriptor sample points.
@importorskip('skimage')
def test_skimage_feature_orb(pyi_builder):
pyi_builder.test_source("""
import skimage.feature
import numpy as np
# Prepare test images
img1 = np.zeros((100, 100))
img2 = np.zeros_like(img1)
rng = np.random.default_rng(1984)
square = rng.random((20, 20))
img1[40:60, 40:60] = square
img2[53:73, 53:73] = square
# ORB detector/descriptor extractor
detector_extractor1 = skimage.feature.ORB(n_keypoints=5)
detector_extractor2 = skimage.feature.ORB(n_keypoints=5)
# Process
detector_extractor1.detect_and_extract(img1)
detector_extractor2.detect_and_extract(img2)
matches = skimage.feature.match_descriptors(
detector_extractor1.descriptors,
detector_extractor2.descriptors,
)
print(matches)
""")

0 comments on commit 4a48d55

Please sign in to comment.