sony
plantimager.sony Link
Camera Link
Camera(device_ip, api_port, timeout=10, postview=False, use_adb=False, use_flashair=False, flashair_host=None, camera_params=None, rotation=0)
Bases: AbstractCamera
Sony Remote Control API.
Provides a high‑level interface to a Sony camera over the network, allowing image capture and optional
post‑processing such as rotation.
Images are returned as plantimager.hal.DataItem objects with an rgb channel containing a NumPy array.
Attributes:
| Name | Type | Description |
|---|---|---|
sony_cam |
SonyCamAPI
|
Low‑level API wrapper handling direct camera communication. |
postview |
bool
|
Flag indicating whether postview mode is active. |
use_adb |
bool
|
Flag indicating whether ADB transfer is used. |
use_flashair |
bool
|
Flag indicating whether FlashAir transfer is used. |
flashair |
(FlashAirAPI, optional)
|
Instance of |
camera_params |
dict or None
|
Camera configuration dictionary passed to |
rotation |
int
|
Rotation angle (degrees counter‑clockwise) applied to images. |
Raises:
| Type | Description |
|---|---|
SonyCamError
|
If both |
See Also
SonyCamAPI : Low‑level API for Sony camera commands. FlashAirAPI : API for interacting with a FlashAir Wi‑Fi SD card.
Examples:
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from plantimager.sony import Camera
>>> # Capture a low‑resolution image using postview mode (Sony RX0):
>>> cam = Camera('192.168.122.1', '10000', postview=True, rotation=0)
>>> img = cam.grab(0)
>>> arr = img.channels['rgb'].data
>>> print(arr.shape)
(1440, 1080, 3)
>>> # Visualize the capture image:
>>> plt.imshow(arr)
>>> plt.show()
>>> # Capture a rotated low‑resolution image using postview mode (Sony RX0):
>>> cam = Camera('192.168.122.1', '10000', postview=True, rotation=270)
>>> img = cam.grab(0)
>>> arr = np.array(img.channels['rgb'].data)
>>> print(arr.shape)
(1080, 1440, 3)
>>> # Visualize the capture image:
>>> plt.imshow(arr)
>>> plt.show()
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_ip
|
str
|
IP address of the Sony camera. |
required |
api_port
|
str
|
Port number of the camera's API endpoint. |
required |
timeout
|
time_s
|
Network timeout (in seconds) for API calls. Default is |
10
|
postview
|
bool
|
If |
False
|
use_adb
|
bool
|
Use Android Debug Bridge (ADB) to transfer the picture.
Mutually exclusive with |
False
|
use_flashair
|
bool
|
Use a Wi‑Fi SD card (FlashAir) to transfer the picture.
Mutually exclusive with |
False
|
flashair_host
|
str
|
Host IP of the FlashAir device. Required when |
None
|
camera_params
|
dict
|
Dictionary of camera settings that are applied after entering shoot mode. |
None
|
rotation
|
int
|
Counter‑clockwise rotation (in degrees) applied to the captured image. Only multiples of 90° are supported; other values are reduced modulo 360. |
0
|
Source code in plantimager/sony.py
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 | |
grab Link
grab(idx, metadata=None)
Capture a single image from the Sony camera.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
int
|
Index assigned to the returned |
required |
metadata
|
dict
|
Arbitrary user‑defined metadata that will be attached to the resulting |
None
|
Returns:
| Type | Description |
|---|---|
DataItem
|
A data container with an |
Raises:
| Type | Description |
|---|---|
SonyCamError
|
|
Notes
- The method chooses the image transfer mechanism in the following priority order:
- Postview – low‑resolution image retrieved directly from the camera URL.
- ADB – uses Android Debug Bridge to pull the latest image from the camera’s internal storage.
- FlashAir – pulls the latest image from a Wi‑Fi SD card.
- File‑transfer mode – switches the camera to Contents Transfer mode and downloads the full‑resolution image via HTTP.
- If
rotationis non‑zero, the image is rotated counter‑clockwise in multiples of 90°.
Source code in plantimager/sony.py
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 | |
start Link
start()
Initialize the camera for shooting.
Raises:
| Type | Description |
|---|---|
SonyCamError
|
If the camera cannot be switched to shoot mode or if a configuration command fails. |
Source code in plantimager/sony.py
671 672 673 674 675 676 677 678 679 680 681 682 | |
SonyCamAPI Link
SonyCamAPI(device_ip, api_port, timeout=2)
Bases: object
High‑level Python wrapper for Sony Camera HTTP API.
This class abstracts the low‑level JSON‑RPC calls required to control a Sony camera over the network. It provides convenience methods for common actions such as starting recording mode, taking a picture, querying status, and transferring images via ADB.
Attributes:
| Name | Type | Description |
|---|---|---|
device_ip |
str
|
Stored IP address of the camera. |
api_port |
str
|
Stored API port. |
api_url |
str
|
Base URL built from |
timeout |
float
|
Timeout used for |
supported_methods |
list of str
|
List of method names supported by the camera, retrieved during
initialization via |
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_ip
|
str
|
IP address of the camera (e.g., |
required |
api_port
|
str
|
Port on which the camera's API service is listening (usually |
required |
timeout
|
float
|
Network timeout in seconds for each HTTP request. |
``2.0``
|
Source code in plantimager/sony.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
adb_transfer_pictures Link
adb_transfer_pictures(count=1)
Transfer the latest count pictures from the camera via ADB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
count
|
int
|
Number of most‑recent images to pull. |
``1``
|
Returns:
| Type | Description |
|---|---|
list of numpy.ndarray
|
Loaded images as NumPy arrays. |
Notes
- ADB shell must be enabled on the camera.
- Images are temporarily stored in
/tmp/before being read withimageio.imread. - The method prints each filename as it is transferred.
Source code in plantimager/sony.py
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
api_call Link
api_call(endpoint, method, params=[], version='1.0')
Perform a JSON‑RPC call to the Sony camera.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
API endpoint (e.g., |
required |
method
|
str
|
Remote method name to invoke. |
required |
params
|
list
|
Positional parameters for the remote method. |
``[]``
|
version
|
str
|
API version string. |
``'1.0'``
|
Returns:
| Type | Description |
|---|---|
list or dict
|
The |
Raises:
| Type | Description |
|---|---|
SonyCamError
|
If the remote API returns an |
Notes
The method serialises params to JSON and sends a POST request.
It decodes the response as UTF‑8 before parsing.
Source code in plantimager/sony.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
get_available_api_list Link
get_available_api_list()
List all API categories supported by the camera.
Returns:
| Type | Description |
|---|---|
list of str
|
API categories (e.g., |
Source code in plantimager/sony.py
275 276 277 278 279 280 281 282 283 | |
get_available_camera_function Link
get_available_camera_function()
Retrieve the list of camera functions supported by the device.
Source code in plantimager/sony.py
185 186 187 | |
get_available_shoot_mode Link
get_available_shoot_mode()
Return the list of supported shoot modes.
Returns:
| Type | Description |
|---|---|
list of str
|
Available shoot modes (e.g., |
Source code in plantimager/sony.py
380 381 382 383 384 385 386 387 | |
get_camera_function Link
get_camera_function()
Get the currently selected camera function.
Source code in plantimager/sony.py
189 190 191 | |
get_camera_status Link
get_camera_status()
Obtain the current camera status from the event stream.
Returns:
| Type | Description |
|---|---|
str
|
Status string such as |
Raises:
| Type | Description |
|---|---|
SonyCamError
|
If the status cannot be extracted from the event list. |
Source code in plantimager/sony.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
get_content_list Link
get_content_list(count, uri, stIdx=0, view='flat', sort='descending')
List media content under a specific uri.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
count
|
int
|
Maximum number of items to return. |
required |
uri
|
str
|
Base URI of the content container (e.g., |
required |
stIdx
|
int
|
Starting index for pagination. |
``0``
|
view
|
str
|
View mode; |
``'flat'``
|
sort
|
str
|
Sort order of results. |
``'descending'``
|
Returns:
| Type | Description |
|---|---|
list of dict
|
Content entries matching the query. |
Source code in plantimager/sony.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
get_event Link
get_event(long_polling=False, version='1.0')
Poll the camera for events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
long_polling
|
bool
|
If |
``False``
|
version
|
str
|
API version for the |
``'1.0'``
|
Returns:
| Type | Description |
|---|---|
list of dict
|
Event dictionaries returned by the camera. |
Source code in plantimager/sony.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
get_method_types Link
get_method_types(version='1.0')
Retrieve supported method names and their signatures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str
|
API version for the |
``'1.0'``
|
Returns:
| Type | Description |
|---|---|
list of tuple
|
Each tuple contains |
Source code in plantimager/sony.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
get_source_list Link
get_source_list()
Retrieve a list of available storage sources.
Returns:
| Type | Description |
|---|---|
list of dict
|
Each entry describes a storage source (e.g., |
Source code in plantimager/sony.py
218 219 220 221 222 223 224 225 226 | |
get_storage_information Link
get_storage_information()
Query storage details such as free space and total capacity.
Returns:
| Type | Description |
|---|---|
dict
|
Storage information dictionary as defined by the Sony API. |
Source code in plantimager/sony.py
208 209 210 211 212 213 214 215 216 | |
set_camera_function Link
set_camera_function(function)
Set the active camera function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
function
|
str
|
Desired camera function (e.g., |
required |
Returns:
| Type | Description |
|---|---|
str
|
Confirmation string returned by the API. |
Source code in plantimager/sony.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
set_shoot_mode Link
set_shoot_mode(mode)
Change the current shoot mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
Desired shoot mode identifier (must be one of the values returned by |
required |
Returns:
| Type | Description |
|---|---|
str
|
Confirmation string from the camera. |
Source code in plantimager/sony.py
389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
setup_camera Link
setup_camera(params)
Configure multiple camera settings in a single call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Mapping of setting names to desired values. Recognised keys are:
|
required |
Source code in plantimager/sony.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
start_movie_rec Link
start_movie_rec()
Begin video recording.
Returns:
| Type | Description |
|---|---|
list
|
Result payload from the |
Source code in plantimager/sony.py
404 405 406 407 408 409 410 411 412 | |
start_rec_mode Link
start_rec_mode()
Switch the camera to recording mode.
Returns:
| Type | Description |
|---|---|
list
|
The raw result returned by the |
Raises:
| Type | Description |
|---|---|
SonyCamError
|
Propagated from :meth: |
Source code in plantimager/sony.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
start_shoot_mode Link
start_shoot_mode()
Prepare the camera for still‑image shooting.
This method ensures the camera function is set to shooting mode and switches to recording mode if required.
It blocks until the camera reports 'IDLE' status.
Raises:
| Type | Description |
|---|---|
SonyCamError
|
Propagated from underlying API calls. |
Source code in plantimager/sony.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |
start_transfer_mode Link
start_transfer_mode()
Switch the camera to 'ContentsTransfer' mode for bulk download.
The method sets the camera function to transfer mode (if supported) and
blocks until the device reports 'ContentsTransfer' status.
Raises:
| Type | Description |
|---|---|
SonyCamError
|
Propagated from underlying API calls. |
Source code in plantimager/sony.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
stop_movie_rec Link
stop_movie_rec()
Stop an ongoing video recording.
Returns:
| Type | Description |
|---|---|
list
|
Result payload from the |
Source code in plantimager/sony.py
414 415 416 417 418 419 420 421 422 | |
take_picture Link
take_picture()
Capture a single still image.
The method polls the camera status until it becomes 'IDLE'.
If the camera is in 'ContentsTransfer' mode, a SonyCamError is raised.
Returns:
| Type | Description |
|---|---|
str
|
URL or file identifier of the captured picture (first element of the API |
Raises:
| Type | Description |
|---|---|
SonyCamError
|
If the camera is in content‑transfer mode or if the request fails. |
Source code in plantimager/sony.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |