Video camera
============

.. image:: ../../../media/sensors/video_camera.png
  :align: center
  :width: 600


**A camera capturing RGBA image**


This sensor emulates a single video camera. It generates a series of
RGBA images.  Images are encoded as binary char arrays, with 4 bytes
per pixel.

The cameras make use of Blender's **bge.texture** module, which
requires a graphic card capable of GLSL shading.  Also, the 3D view
window in Blender must be set to draw **Textured** objects.

Camera calibration matrix
-------------------------

The camera configuration parameters implicitly define a geometric camera in
blender units. Knowing that the **cam_focal** attribute is a value that
represents the distance in Blender unit at which the largest image dimension is
32.0 Blender units, the camera intrinsic calibration matrix is defined as

  +--------------+-------------+---------+
  | **alpha_u**  |      0      | **u_0** |
  +--------------+-------------+---------+
  |       0      | **alpha_v** | **v_0** |
  +--------------+-------------+---------+
  |       0      |      0      |    1    |
  +--------------+-------------+---------+

where:

- **alpha_u** == **alpha_v** = **cam_width** . **cam_focal** / 32 (we suppose
  here that **cam_width** > **cam_height**. If not, then use **cam_height** in
  the formula)
- **u_0** = **cam_height** / 2
- **v_0** = **cam_width** / 2


.. cssclass:: properties morse-section

Configuration parameters for video camera
-----------------------------------------


You can set these properties in your scripts with ``<component>.properties(<property1>=..., <property2>=...)``.

- ``cam_width`` (default: ``256``)
	(no documentation available yet)
- ``cam_height`` (default: ``256``)
	(no documentation available yet)
- ``cam_focal`` (default: ``25.0``)
	(no documentation available yet)
- ``cam_near`` (default: ``0.1``)
	(no documentation available yet)
- ``cam_far`` (default: ``100.0``)
	(no documentation available yet)
- ``Vertical_Flip`` (default: ``False``)
	(no documentation available yet)
- ``noocclusion`` (bool, default: ``False``)
	Do not check for objects possibly hiding each others (faster but less realistic behaviour)


.. cssclass:: fields morse-section

Data fields
-----------


This sensor exports these datafields at each simulation step:

- ``image`` (buffer, initial value: ``none``)
	Z-Buffer captured by the camera, converted in meters. memoryview of float of size ``(cam_width * cam_height * sizeof(float))`` bytes.
- ``intrinsic_matrix`` (mat3<float>, initial value: ``none``)
	The intrinsic calibration matrix, stored as a 3x3 row major Matrix.
- ``points`` (memoryview, initial value: ``none``)
	List of 3D points from the depth camera. memoryview of a set of float(x,y,z). The data is of size ``(nb_points * 12)`` bytes (12=3*sizeof(float).
- ``nb_points`` (int, initial value: ``0``)
	the number of points found in the points list. It must be inferior to cam_width * cam_height

*Interface support:*

- :tag:`socket`  as a JSON-encoded image (:py:mod:`morse.middleware.sockets.video_camera.VideoPublisher`)
- :tag:`pocolibs`  as `ViamImageBank <http://trac.laas.fr/git/viam-genom/tree/viamStruct.h?h=viam-genom-1#n346>`_ (:py:mod:`morse.middleware.pocolibs.sensors.viam.ViamPoster`)
- :tag:`ros`  as VideoCameraPublisher (:py:mod:`morse.middleware.ros.video_camera.VideoCameraPublisher`)
- :tag:`yarp`  as yarp::ImageRGBA (:py:mod:`morse.middleware.yarp_datastream.YarpImagePublisher`)


.. cssclass:: services morse-section

Services for Video camera
-------------------------

- ``capture(n)`` (non blocking)
    Capture **n** images
    
    
  - Parameters

    - ``n``: the number of images to take. A negative number means           take image indefinitely

- ``get_local_data()`` (blocking)
    Returns the current data stored in the sensor.
    
    
  - Return value

    a dictionary of the current sensor's data 



.. cssclass:: examples morse-section

Examples
--------


The following example shows how to use this component in a *Builder* script:

.. code-block:: python


    from morse.builder import *
    
    robot = ATRV()
    
    # creates a new instance of the sensor
    videocamera = VideoCamera()

    # place your component at the correct location
    videocamera.translate(<x>, <y>, <z>)
    videocamera.rotate(<rx>, <ry>, <rz>)
    
    robot.append(%(var)s)
    
    # define one or several communication interface, like 'socket'
    videocamera.add_interface(<interface>)

    env = Environment('empty')
    

.. cssclass:: files morse-section

Other sources of examples
+++++++++++++++++++++++++

- `Source code <../../_modules/morse/sensors/video_camera.html>`_
- `Unit-test <../../_modules/base/video_camera_testing.html>`_




*(This page has been auto-generated from MORSE module morse.sensors.video_camera.)*
