Skip to content

Commit

Permalink
added the raw and decoded jpeg options from pull request zayfod#55 by…
Browse files Browse the repository at this point in the history
… ADebor
  • Loading branch information
reakain committed Sep 1, 2023
1 parent 076f73e commit b359ef1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
17 changes: 11 additions & 6 deletions pycozmo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def __init__(self,
protocol_log_messages: Optional[list] = None,
auto_initialize: bool = True,
enable_animations: bool = True,
enable_procedural_face: bool = True) -> None:
enable_procedural_face: bool = True,
enable_jpeg_decoding: bool = True) -> None:
super().__init__()
# Whether to automatically initialize the robot when connection is established.
self.auto_initialize = bool(auto_initialize)
Expand Down Expand Up @@ -93,6 +94,7 @@ def __init__(self,
self.client_drop_count = 0
# Camera state
self.last_image_timestamp = None
self.enable_jpeg_decoding = enable_jpeg_decoding
# Object state
self.available_objects = dict()
self.connected_objects = dict()
Expand Down Expand Up @@ -272,12 +274,15 @@ def _process_completed_image(self):
else:
data = camera.minigray_to_jpeg(data, width, height)

image = Image.open(io.BytesIO(data)).convert('RGB')
if self.enable_jpeg_decoding:
image = Image.open(io.BytesIO(data)).convert('RGB')

# Color images need to be resized to the proper resolution
if is_color_image:
size = camera.RESOLUTIONS[self._partial_image_resolution]
image = image.resize(size)
# Color images need to be resized to the proper resolution
if is_color_image:
size = camera.RESOLUTIONS[self._partial_image_resolution]
image = image.resize(size)
else:
image = data

self._latest_image = image
self.last_image_timestamp = self._partial_image_timestamp
Expand Down
6 changes: 4 additions & 2 deletions pycozmo/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def connect(
robot_log_level: Optional[str] = None,
auto_initialize: bool = True,
enable_animations: bool = True,
enable_procedural_face: bool = True) -> client.Client:
enable_procedural_face: bool = True,
*args, **kwargs) -> client.Client:

setup_basic_logging(log_level=log_level, protocol_log_level=protocol_log_level, robot_log_level=robot_log_level)

Expand All @@ -70,7 +71,8 @@ def connect(
protocol_log_messages=protocol_log_messages,
auto_initialize=auto_initialize,
enable_animations=enable_animations,
enable_procedural_face=enable_procedural_face)
enable_procedural_face=enable_procedural_face,
*args, **kwargs)
cli.start()
cli.connect()
cli.wait_for_robot()
Expand Down

0 comments on commit b359ef1

Please sign in to comment.