Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ dmypy.json
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
.vscode

# Generated files
.idea/**/contentModel.xml
Expand Down
29 changes: 29 additions & 0 deletions detecto/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,35 @@ def read_image(path):

return rgb_image

def read_folder(path):
"""Helper function that reads in a folder of images as a
generator of `NumPy <https://numpy.org/>`_ arrays. Equivalent to using
read_image on each file in the folder as a a generator.

:param path: The path to the image folder.
:type path: str
:return: Image in NumPy array format
:rtype: Generator[ndarray,None,None]

**Example**::

>>> import matplotlib.pyplot as plt
>>> from detecto.utils import read_folder

>>> images = read_folder('images')
>>> for im in images:
>>> plt.imshow(im)
>>> plt.show()
"""

if not os.path.isdir(path):
raise ValueError(f'Could not find folder {path}')

for im in os.scandir(path):
yield read_image(im.path)




def reverse_normalize(image):
"""Reverses the normalization applied on an image by the
Expand Down