-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
decode JPEG image data to numpy array
- Loading branch information
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
""" | ||
Decodes images from JPEG bytes to numpy array. | ||
""" | ||
|
||
import io | ||
|
||
from PIL import Image | ||
import numpy as np | ||
|
||
|
||
def decode(data: "io.BytesIO | bytes") -> np.ndarray: | ||
""" | ||
Decodes a JPEG encoded image and returns it as a numpy array. | ||
Args: | ||
data: bytes object containing the JPEG encoded image | ||
Returns: | ||
NDArray with in RGB format (Height, Width, 3) | ||
""" | ||
image = Image.open(data, formats=['JPEG']) | ||
|
||
return np.asarray(image) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,9 @@ pytest | |
opencv-python | ||
numpy | ||
|
||
# Module lte | ||
Pillow | ||
|
||
# Module mavlink | ||
dronekit | ||
|
||
|