Skip to content

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.

Examples:

>>> import numpy as np
>>> from plantimager.sony import Camera
>>> cam = Camera('192.168.122.1', '10000', postview=True, rotation=0)
>>> img = cam.grab(0)
>>> arr = img.channels['rgb'].data
>>> arr.shape
>>> cam = Camera('192.168.122.1', '10000', postview=True, rotation=270)
>>> img = cam.grab(0)
>>> arr = np.array(img.channels['rgb'].data)
>>> arr.shape
Source code in plantimager/sony.py
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
def __init__(self, device_ip: str,
             api_port: str,
             timeout: time_s = 10,
             postview: bool = False,
             use_adb: bool = False,
             use_flashair: bool = False,
             flashair_host: str = None,
             camera_params: dict = None,
             rotation: int = 0):

    self.sony_cam = SonyCamAPI(device_ip, api_port, timeout=timeout)
    self.postview = postview
    self.use_flashair = use_flashair
    self.use_adb = use_adb
    if use_flashair and use_adb:
        raise SonyCamError("Cannot use both flashair and adb for transfer")
    if use_flashair:
        if flashair_host is None:
            raise SonyCamError("Must provide flashair host IP")
        self.flashair = FlashAirAPI(flashair_host)

    self.camera_params = camera_params
    self.rotation = rotation  # degrees counter-clockwise
    self.start()

SonyCamAPI Link

SonyCamAPI(device_ip, api_port, timeout=2)

Bases: object

Source code in plantimager/sony.py
46
47
48
49
50
51
52
def __init__(self, device_ip, api_port, timeout=2):
    self.device_ip = device_ip
    self.api_port = api_port
    self.api_url = 'http://' + device_ip + ':' + api_port + '/sony/'
    self.timeout = timeout
    method_types = self.get_method_types()
    self.supported_methods = [x[0] for x in method_types]

adb_transfer_pictures Link

adb_transfer_pictures(count=1)

Transfer the latest count pictures from the camera ADB shell must be enabled on the camera

Source code in plantimager/sony.py
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
def adb_transfer_pictures(self, count=1):
    """
    Transfer the latest count pictures from the camera
    ADB shell must be enabled on the camera
    """
    subprocess.run(['adb', 'connect', self.device_ip])
    x = subprocess.run(['adb', 'shell', 'ls /sdcard/DCIM/100MSDCF'], capture_output=True)
    files = x.stdout.split()
    files = list(map(lambda x: x.decode(), files))
    files.sort()
    files = files[-count:]
    images = []
    for f in files:
        subprocess.run(['adb', 'pull', '/sdcard/DCIM/100MSDCF/' + f, '/tmp/'])
        im = imageio.imread('/tmp/' + f)
        images.append(im)
        print(f)
    return images