Overview

ALVideoDevice, formerly called Video Input Module (V.I.M.), is architectured in order to provide every module related to vision, called Generic Video Module (G.V.M.), a direct access to raw images from video source, or an access to images transformed in the requested format.
Extension name of the methods providing images depends on wether modules are local (dynamic library) or remote (executable).


Methods inherited from ALModule

void exit ()

Exits and unregisters the module.

string version ()

Returns the version of the module.

Returns

A string containing the version of the module.

bool ping ()

Just a ping. Always returns true

Returns

returns true

vector<string> getMethodList ()

Retrieves the module's method list.

Returns

An array of method names.

AL::ALValue getMethodHelp (const string& methodName)

Retrieves a method's description.

methodName

The name of the method.

Returns

A structure containing the method's description.

AL::ALValue getModuleHelp ()

Retrieves the module's description.

Returns

A structure describing the module.

string getBrokerName ()

Gets the name of the parent broker.

Returns

The name of the parent broker.

string getUsage (const string& name)

Gets the method usage string. This summarise how to use the method.

name

The name of the method.

Returns

A string that summarises the usage of the method.


Methods inherited from ALVisionVideoInput

int startFrameGrabber ()

Advanced method that opens and initialize video source device if it was not before.
Note that the first module subscribing to ALVideoDevice will launch it automatically.

Returns

true if success

Example in C++ :

  #Create a proxy on the video input module (V.I.M.)
  ALPtr<ALProxy> fCamera = getParentBroker()->getProxy( "ALVideoDevice" );
  #Start the frame grabber in the default mode.
  fCamera->startFrameGrabber();

int stopFrameGrabber ()

Advanced method that close video source device.

Returns

true if success

Example in C++ :

  fCamera->stopFrameGrabber();

int isFrameGrabberOff ()

Advanced method that asks if the framegrabber is off.

Returns

true if off

string subscribe (const string& gvmName, const int& resolution, const int& colorSpace, const int& fps)

Register to ALVideoDevice (formerly Video Input Module/V.I.M.). When a General Video Module(G.V.M.) registers to ALVideoDevice, a buffer of the requested image format is added to the buffers list.
Returns the name under which the G.V.M. is registered to ALVideoDevice (useful when two G.V.M. try to register using the same name

gvmName

Name of the registering G.V.M.

resolution

Resolution requested. { 0 = kQQVGA, 1 = kQVGA, 2 = kVGA }

colorSpace

Colorspace requested. { 0 = kYuv, 9 = kYUV422, 10 = kYUV, 11 = kRGB, 12 = kHSY, 13 = kBGR }

fps

Fps (frames per second) requested. { 5, 10, 15, 30 }

Returns

Name under which the G.V.M. is known from ALVideoDevice, 0 if failed.

Example in C++ :

  #Register a G.V.M. to ALVideoDevice, starting the frame grabber if it was not started before.
  std::string pId, pGVMName = "my_GVM";
  pId = fCamera->call<std::string>( "subscribe", pGVMName , pResolution, pColorSpace, pFps );

void unsubscribe (const string& id)

Used to unregister a G.V.M. from ALVideoDevice.

id

Name under which the G.V.M. is known from ALVideoDevice.

Example in C++ :

  fCamera->callVoid( "unsubscribe", pId );

void * getImageLocal (const string& id)

Applies transformations to the last image from video source and returns a pointer to a locked ALImage.
When image is not necessary anymore, a call to releaseImage() is requested.
If the G.V.M. didn't release preceding image, returns NULL.

id

Name under which the G.V.M. is known from ALVideoDevice (formerly called V.I.M.)

Returns

Pointer of the locked image buffer, NULL if error.Warning, image pointer is valid only for C++ dynamic library.

Example in C++ :

  ALImage *pointer;
  pointer = (ALImage*)fCamera->getImageLocal(pId);

int releaseImage (const string& id)

Release image buffer locked by getImageLocal().
If G.V.M. had no locked image buffer, does nothing.

id

Name under which the G.V.M. is known from ALVideoDevice.

Returns

true if success

Example in C++ :

  #Release image (does nothing if image was already released).
  fCamera->releaseImage(pId);

AL::ALValue getImageRemote (const string& id)

Applies transformations to the last image from video source and fills pFrameOut.

id

Name under which the G.V.M. is known from ALVideoDevice.

Returns

Array containing image informations :
[0] : width;
[1] : height;
[2] : number of layers;
[3] : ColorSpace;
[4] : time stamp (highest 32 bits);
[5] : time stamp (lowest 32 bits);
[6] : array of size height * width * nblayers containing image data;
[7] : camera ID;

Example in C++ :

  ALValue results;
  results.arrayReserve(8);
  results = fCamera->call<ALValue>( "getImageRemote", pId );
  const unsigned char* imageData =  static_cast<const unsigned char*>(results[6].GetBinary());

void * getDirectRawImageLocal (const string& id)

Returns a pointer to a locked ALImage, with data array pointing directly to raw data. No format conversion and no copy of the raw buffer.
When image is not necessary anymore, a call to releaseDirectRawImage() is requested.
Warning: 1. when using this mode for several G.V.M., if they need raw data for more than 25ms check that you have strictly less G.V.M. modules in this mode than the amount of kernel buffers!! 2. Release all kernel buffers before any action requesting a modification in camera running mode (e.g. resolution, switch between cameras).

id

Name under which the G.V.M. is known from ALVideoDevice.

Returns

Pointer to the locked image buffer, NULL if error. Warning, image pointer is valid only for C++ dynamic library.

Example in C++ :

  ALImage *pointer;
  pointer = fCamera->getDirectRawImageLocal(pId);

int releaseDirectRawImage (const string& id)

Release image buffer locked by getDirectRawImageLocal().
If G.V.M. had no locked image buffer, does nothing.

id

Name under which the G.V.M. is known from the V.I.M.

Returns

true if success

Example in C++ :

  #Release raw image (does nothing if image was already released).
  fCamera->releaseDirectRawImage(pId);

AL::ALValue getDirectRawImageRemote (const string& id)

Fills pFrameOut with data coming directly from raw buffer (no format conversion).
No need to call releaseDirectRawImage() because it is done automatically at the end of data transmission.

id

Name under which the G.V.M. is known from ALVideoDevice.

Returns

Array containing image informations :
[0] : width;
[1] : height;
[2] : number of layers;
[3] : ColorSpace;
[4] : time stamp (highest 32 bits);
[5] : time stamp (lowest 32 bits);
[6] : array of size height * width * nblayers containing image data;
[7] : camera ID;

Example in C++ :

  ALValue results;
  results.arrayReserve(8);
  results = fCamera->call<ALValue>( "getDirectRawImageRemote", pId );
  const unsigned char* imageData =  static_cast<const unsigned char*>(results[6].GetBinary());

bool setResolution (const string& id, const int& size)

Set the size of the output image.

id

Name under which the G.V.M. is known from ALVideoDevice.

size

{ 0 = kQQVGA, 1 = kQVGA, 2 = kVGA }

Returns

true if success

Example in C++ :

  fCamera->setResolution(pId, kQVGA);

bool setFrameRate (const string& id, const int& frameRate)

Set the required frame rate.

id

Name under which the G.V.M. is known from ALVideoDevice.

frameRate

images per seconds { 5, 10, 15, 30 }

Returns

true if success

Example in C++ :

  fCamera->setFrameRate(pId, 30);

bool setColorSpace (const string& id, const int& colorSpace)

Set the colorspace of the output image.

id

Name under which the G.V.M. is known from ALVideoDevice.

colorSpace

{ 0 = kYuv, 9 = kYUV422, 10 = kYUV, 11 = kRGB, 12 = kHSY, 13 = kBGR }

Returns

true if success

Example in C++ :

  fCamera->setColorSpace(pId, kYUVColorSpace);

int getVIMResolution ()

Get the resolution of the video source image.

Returns

{ 0 = kQQVGA, 1 = kQVGA, 2 = kVGA } -1: can't access video source

Example in C++ :

  int videoSourceResolution = fCamera->getVIMResolution();

int getVIMColorSpace ()

Get the color space of the video source image.

Returns

{ 0 = kYuv, 9 = kYUV422, 10 = kYUV, 11 = kRGB, 12 = kHSY, 13 = kBGR } -1 can't access video source

Example in C++ :

  int videoSourceColorSpace = fCamera->getVIMColorSpace();

int getVIMFrameRate ()

Get the frame rate of the video source image.

Returns

{ 5, 10, 15, 30 } -1: can't access video source

Example in C++ :

  int videoSourceFps = fCamera->getVIMFrameRate();

int getGVMResolution (const string& id)

Get the resolution of the requested G.V.M.

id

Name under which the G.V.M. is known from ALVideoDevice.

Returns

{ 0 = kQQVGA, 1 = kQVGA, 2 = kVGA } -1: can't access video source

Example in C++ :

  int moduleResolution = fCamera->getGVMResolution(pId);

int getGVMColorSpace (const string& id)

Get the color space of the requested G.V.M.

id

Name under which the G.V.M. is known from ALVideoDevice.

Returns

{ 0 = kYuv, 9 = kYUV422, 10 = kYUV, 11 = kRGB, 12 = kHSY, 13 = kBGR } -1: can't access video source

Example in C++ :

  int moduleColorSpace = fCamera->getGVMColorSpace(pId);

int getGVMFrameRate (const string& id)

Get the frame rate of the requested G.V.M.

id

Name under which the G.V.M. is known from ALVideoDevice.

Returns

{ 5, 10, 15, 30 } -1: can't access video source

Example in C++ :

  int moduleFps = fCamera->getGVMFrameRate(pId);

void setParam (const int& param, const int& newValue)

Sets the value of a specific parameter for the video source.

param

Parameter's reference among:
kCameraBrightnessID,
kCameraContrastID,
kCameraSaturationID,
kCameraHueID,
kCameraRedChromaID,
kCameraBlueChromaID,
kCameraGainID,
kCameraHFlipID,
kCameraVFlipID,
kCameraLensXID (not managed by camera),
kCameraLensYID (not managed by camera),
kCameraAutoExpositionID,
kCameraAecAlgorithmID [0:average-based; 1:histogram-based],
kCameraExposureCorrectionID [-6; 6] (correction by n/3 EV, switch automatically in average-based AEC algorithm if n!=0 and back to histogram-based for n=0),
kCameraExposureID,
kCameraAutoWhiteBalanceID,
kCameraAutoGainID,
kCameraSelectID [0:top camera; 1:bottom camera],
kCameraResolutionID,
kCameraFrameRateID (not managed currently),
kCameraBufferSizeID,
kCameraSharpnessID (0-1: no sharpness - 2: medium sharpness - 3-5: high sharpness),
kCameraFastSwitchID : advanced method that needs both camera to run same format. Parameter value has no meaning.
Remarks: Disabled camera (freezed actually) will get back to auto gain/exposure/white balance settings after a while. This is a camera issue.
Fast switch usually switchs between cameras in 66ms (33ms for waked up sensor exposure + 33ms for data transfer) after previous image completion. However, sometimes we can observe a clipped image from the former camera after 66ms. This is an electronical issue and so we suggest to considere only images after 100ms

newValue

Parameter's new value.

Example in C++ :

  fCamera->setParam(pParam, pNewValue);

void setParamDefault (const int& param)

Sets a specific parameter for the video source at its default value.

param

Parameter's reference.

Example in C++ :

  fCamera->setParamDefault(pParam);

vector<float> getAngPosFromImgPos (const vector<float>& imgPos)

Returns angles relative to camera axis given a normalized position in the image.

imgPos

normalized position in the image [0.0 - 1.0]

Returns

corresponding angles values in radians.

Example in C++ :

  std::vector<float> posUV;
  posUV.push_back(x / imageWidth);.
  posUV.push_back(y / imageHeight);
  std::vector<float> camAngles = fCamera->getAngPosFromImgPos(posUV);

vector<float> getImgPosFromAngPos (const vector<float>& angPos)

Returns normalized image position from camera angles in radians.

angPos

camera angle values in radians.

Returns

corresponding normalized position in the image [0.0 - 1.0]

Example in C++ :

  std::vector<float> camAngles;
  camAngles.push_back(0.1f);
  camAngles.push_back(0.1f);
  std::vector<float> imgPos = fCamera->getImgPosFromAngPos(camAngles);

vector<float> getAngSizeFromImgSize (const vector<float>& imgSize)

Returns angles relative to camera axis given a normalized position in the image.

imgSize

normalized position in the image [0.0 - 1.0]

Returns

corresponding angles values in radians.

Example in C++ :

  std::vector<float> posUV;
  posUV.push_back(sizeX / imageWidth);
  posUV.push_back(sizeY / imageHeight);
  std::vector<float> angSize = fCamera->getAngSizeFromImgSize(posUV);

vector<float> getImgSizeFromAngSize (const vector<float>& angSize)

Returns normalized image position from camera angles in radians.

angSize

camera angle values in radians.

Returns

corresponding normalized position in the image [0.0 - 1.0]

Example in C++ :

  std::vector<float> camAngles;
  camAngles.push_back(0.1f);
  camAngles.push_back(0.1f);
  std::vector<float> imgPos = fCamera->getImgPosFromAngles(camAngles);

vector<float> getImgInfoFromAngInfo (const vector<float>& angles)

Returns normalized image info from angles info in radians (as returned by vision extractors).

angles

camera angle values in radians.

Returns

corresponding normalized position info.

vector<float> getImgInfoFromAngInfoWithRes (const vector<float>& angInfo, const int& arg2)

Returns image info from angles info in radians (as returned by vision extractors). Express image info in the requested resolution.

angInfo

camera angle values in radians.

arg2

arg

Returns

corresponding position info.

AL::ALValue resolutionToSizes (const int& resolution)

return the width and the height of a resolution

resolution

{ 0 = kQQVGA, 1 = kQVGA, 2 = kVGA }

Returns

array of sizes: (return [-1;-1] if the format is invalid)
[0] : width;
[1] : height;

Example in C++ :

  ALValue size = fCamera->resolutionToSizes(kVGA);

int sizesToResolution (const int& width, const int& height)

return the resolution from sizes

width

width of the image

height

height of the image

Returns

{ 0 = kQQVGA, 1 = kQVGA, 2 = kVGA } or -1 if the inputs are invalid

Example in C++ :

  int resolution = fCamera->sizesToResolution(640, 480);

bool recordVideo (const string& id, const string& path, const int& totalNumber, const int& period)

BETA - background record of an .arv raw format video from the images processed by a G.V.M.

id

Name under which the G.V.M. is known from the V.I.M.

path

path/name of the video to be recorded

totalNumber

number of images to be recorded. 0xFFFFFFFF for "unlimited"

period

one image recorded every pPeriod images

Returns

true if success

bool stopVideo (const string& id)

BETA - stop writing the video sequence

id

Name under which the G.V.M. is known from ALVideoDevice.

Returns

true if success

void onClientDisconnected (const string& eventName, const AL::ALValue& eventContents, const string& message)

Callback when client is disconnected

eventName

The echoed event name

eventContents

The name of the client that has disconnected

message

The message give when subscribing.

int getParam (const int& pParam)

Get the value of a video source specific parameter.

pParam

Parameter's reference among kCameraBrightnessID,
kCameraContrastID,
kCameraSaturationID,
kCameraHueID,
kCameraRedChromaID,
kCameraBlueChromaID,
kCameraGainID,
kCameraHFlipID,
kCameraVFlipID,
kCameraLensXID,
kCameraLensYID,
kCameraAutoExpositionID,
kCameraAecAlgorithmID [0:average-based; 1:histogram-based],
kCameraExposureCorrectionID [-6; 6] (correction by n/3 IL, switch automatically in average-based AEC algorithm if n!=0 and back to histogram-based for n=0),
kCameraExposureID,
kCameraAutoWhiteBalanceID,
kCameraAutoGainID,
kCameraSelectID [0:top camera; 1:bottom camera],
kCameraResolutionID,
kCameraFrameRateID,
kCameraBufferSizeID,
kCameraFastSwitchID (need both camera to run same format/ parameter value has no signification),
kCameraSharpnessID (0-1: no sharpness - 2: medium sharpness - 3-5: high sharpness)

Returns

Parameter's value.

Example in C++ :

  int pVal = fCamera->getParam(pParam);
  #More explanations in the documentation...

int getActiveCamera ()

Get the active camera

Returns

0: top camera - 1: bottom camera

Example in C++ :

  int activeCam = fCamera->getActiveCamera();


Example Code

Example in C++ :

  #Create a proxy on the video input module (V.I.M.)
  ALPtr<ALProxy> fCamera = getParentBroker()->getProxy( "ALVideoDevice" );
  #Register a Generic Video Module (G.V.M.) to the V.I.M.
  std::string pGVMNameId = "my_GVM";
  pGVMNameId = fCamera->call<std::string>( "subscribe", pGVMNameId , pResolution, pColorSpace, pFps );
  #Get a pointer to the video source image and release the image when process is finished
  ALImage *pointer = (ALImage*)AL::ALVideoDeviceProxy(getParentBroker()).getImageLocal(pGVMNameId);
  ...process...
  fCamera->call<int>( "releaseImage", pGVMNameId);
  #Unregister the G.V.M.
  fCamera->callVoid( "unsubscribe", pGVMNameId );

Example in Python :

  #Create a proxy on the video input module (V.I.M.)
  camProxy = ALProxy("ALVideoDevice", "10.8.252.149", 9559)
  #Register a Generic Video Module (G.V.M.) to the V.I.M.
  nameId = camProxy.subscribe("python_GVM", resolution, colorSpace, fps)
  #Get a pointer to the video source image and release the image when process is finished
  camProxy.getImageLocal(nameId)
  ...process...
  camProxy.releaseImage(nameId)
  #Unregister the G.V.M.
  camProxy.unsubscribe(nameId)

Copyright © 2010 Aldebaran Robotics - All rights reserved