Skip to content

Commit 3bf2e64

Browse files
Rakesh Ravi Shankarmsintov
authored andcommitted
VIC-4509: Added option to request high res images (#165)
1 parent 5dac4cc commit 3bf2e64

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

anki_vector/camera.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
from . import annotate, connection, util
3838
from .events import Events
39-
from .exceptions import VectorCameraFeedException
39+
from .exceptions import VectorCameraFeedException, VectorCameraImageCaptureException
4040
from .messaging import protocol
4141

4242
try:
@@ -129,6 +129,8 @@ def annotate_image(self, scale: float = None, fit_size: tuple = None, resample_m
129129
(fast) or :attr:`~anki_vector.annotate.RESAMPLE_MODE_BILINEAR` (slower,
130130
but smoother).
131131
"""
132+
if self._raw_image.size != (640, 360):
133+
raise VectorCameraImageCaptureException("Annotation is only supported for default resolution images.")
132134
return self._image_annotator.annotate_image(self._raw_image,
133135
scale=scale,
134136
fit_size=fit_size,
@@ -330,7 +332,7 @@ async def _request_and_handle_images(self) -> None:
330332
self.logger.debug('Camera feed task was cancelled. This is expected during disconnection.')
331333

332334
@connection.on_connection_thread()
333-
async def capture_single_image(self) -> CameraImage:
335+
async def capture_single_image(self, enable_high_resolution: bool = False) -> CameraImage:
334336
"""Request to capture a single image from the robot's camera.
335337
336338
This call requests the robot to capture an image and returns the
@@ -346,10 +348,16 @@ async def capture_single_image(self) -> CameraImage:
346348
with anki_vector.Robot() as robot:
347349
image = robot.camera.capture_single_image()
348350
image.raw_image.show()
351+
352+
:param enable_high_resolution: Enable/disable request for high resolution images. The default resolution
353+
is 640x360, while the high resolution is 1280x720.
349354
"""
350355
if self._enabled:
356+
self.logger.warning('Camera feed is enabled. Receiving image from the feed at default resolution.')
351357
return self._latest_image
352-
req = protocol.CaptureSingleImageRequest()
358+
if enable_high_resolution:
359+
self.logger.warning('Capturing a high resolution (1280*720) image. Image events for this frame need to be scaled.')
360+
req = protocol.CaptureSingleImageRequest(enable_high_resolution=enable_high_resolution)
353361
res = await self.grpc_interface.CaptureSingleImage(req)
354362
if res and res.data:
355363
image = _convert_to_pillow_image(res.data)

anki_vector/camera_viewer/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class TkCameraViewer: # pylint: disable=too-few-public-methods
4343

4444
def __init__(self, queue: mp.Queue, event: mp.Event, overlays: list = None, timeout: float = 10.0, force_on_top: bool = False):
4545
self.tk_root = tk.Tk()
46-
self.width = 640
47-
self.height = 360
46+
self.width = None
47+
self.height = None
4848
self.queue = queue
4949
self.event = event
5050
self.overlays = overlays
@@ -73,6 +73,7 @@ def _resize_window(self, evt: tk.Event) -> None:
7373
def draw_frame(self) -> None:
7474
"""Display an image on to a Tkinter label widget."""
7575
image = self.queue.get(True, timeout=self.timeout)
76+
self.width, self.height = image.size
7677
while image:
7778
if self.event.is_set():
7879
break

anki_vector/exceptions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
__all__ = ['VectorAsyncException',
2525
'VectorBehaviorControlException',
2626
'VectorCameraFeedException',
27+
'VectorCameraImageCaptureException',
2728
'VectorConfigurationException',
2829
'VectorConnectionException',
2930
'VectorControlException',
@@ -144,6 +145,10 @@ class VectorCameraFeedException(_VectorGenericException):
144145
Make sure to enable the camera feed either using Robot(show_viewer=True), or robot.camera.init_camera_feed()"""
145146

146147

148+
class VectorCameraImageCaptureException(_VectorGenericException):
149+
"""Image capture exception."""
150+
151+
147152
class VectorConfigurationException(_VectorGenericException):
148153
"""Invalid or missing configuration data."""
149154

anki_vector/vision.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ async def enable_face_detection(
143143
@connection.on_connection_thread()
144144
async def enable_motion_detection(self, detect_motion: bool = True):
145145
"""Enable motion detection on the robot's camera
146-
146+
147147
:param detect_motion: Specify whether we want the robot to detect motion.
148-
148+
149149
.. testcode::
150150
151151
import time
@@ -162,7 +162,7 @@ def on_robot_observed_motion(robot, event_type, event):
162162
163163
# If necessary, move Vector's Head and Lift to make it easy to see his face
164164
robot.behavior.set_head_angle(degrees(45.0))
165-
robot.behavior.set_lift_height(0.0)
165+
robot.behavior.set_lift_height(0.0)
166166
167167
robot.vision.enable_motion_detection(detect_motion=True)
168168

0 commit comments

Comments
 (0)