get_next_frame()
  • 1 Minute to read

get_next_frame()


Article Summary

Take a snapshop from the selected camera.

Reference

Arguments

ArgumentTypeDefault value
camera_namestringName of the camera, see the list of cameras
compressedbooleanFalseWhen True, this method returns a jpeg compressed image

Important: Camera must be previously enabled with the enable_camera() method.

Return

  • When compressed == False:

Numpy array with shape (height, width, 3), where 3 represents RGB channels. height and width depend on the selected camera, see the list of cameras.

  • When compressed == True:

Unidimensional Numpy array with jpeg RGB compressed image.

Exceptions

ExceptionCondition
RayaInvalidCameraNameInvalid camera name.
RayaCameraNotEnabledSelected camera is not currently enabled.

See the Full List of Exceptions.

Examples

1. Take a snapshot and show it

This example takes a snapshot and show it for 3 seconds.

Only works for Linux users

This example only works for Linux users that runs the SDK on the host machine.

from raya.application_base import RayaApplicationBase
from raya.tools.image import show_image

class RayaApplication(RayaApplicationBase):
    async def setup(self):
        self.cameras = await self.enable_controller('cameras')
        await self.cameras.enable_color_camera('chest')

    async def loop(self):
        img = await self.cameras.get_next_frame('chest')
        show_image(img=img, title='Chedfs')
        await self.sleep(3.0)
        self.finish_app()

    async def finish(self):
        return None

2. Take a snapshot and save it

This example takes a snapshot and save it inside the ./dat/ application folder.

from raya.application_base import RayaApplicationBase
from raya.tools.image import save_image

class RayaApplication(RayaApplicationBase):
    async def setup(self):
        self.cameras = await self.enable_controller('cameras')
        self.cameras.enable_camera('chest')

    async def loop(self):
        img = self.cameras.take_snapshot('chest')
        save_image(img=img, filename='photo1.jpg')
        await self.finish_app()

    async def finish(self):
        pass

Was this article helpful?