-
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 (#29)
* decode JPEG image data to numpy array * moved image_decode.py into module folder. Added test file template. TODO: Finish writing tests when image encode is finished * added dummy variable * linter changes
- Loading branch information
Showing
3 changed files
with
54 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,24 @@ | ||
""" | ||
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 | ||
TODO: When encoding JPEG, make sure the input image only has 3 channels, | ||
if original picture was a PNG (filter out A channel) | ||
Returns: | ||
NDArray with in RGB format. Shape is (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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
Test image encode and decode. | ||
TODO: finish image encode and then write this test | ||
""" | ||
|
||
from lte.modules import image_decode | ||
|
||
|
||
def main() -> int: | ||
# TODO: Get test images and Encode | ||
raw_data = 0 | ||
|
||
# Decode | ||
img_array = image_decode.decode(raw_data) | ||
|
||
# Do checks | ||
# eg. check output shape | ||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
result_main = main() | ||
|
||
if result_main < 0: | ||
print(f"ERROR: Status code: {result_main}") | ||
|
||
print("Done!") |
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 | ||
|
||
|