AURobotServers  4
Public Member Functions | Public Attributes | Protected Member Functions | Private Attributes | List of all members
UCamRad Class Reference

#include <ucamrad.h>

Inheritance diagram for UCamRad:
Inheritance graph

Public Member Functions

virtual void createVars ()
 
UCamPargetCamPar ()
 
int getDefaultColFormat ()
 
bool getDefaultRemRadErr ()
 
bool getImageSnapshot (UImage *image)
 
bool removeRadialError (UImage *source, UImage *destination)
 
void saveRadialCorrectionMatrix (char *filename)
 
bool setCameraParameters (float hx, float hy, float k1, float k2, float focalLng)
 
void setDefaultRemRadErr (bool value)
 
bool setRadialErrorMatrix ()
 
 UCamRad (UCamDevBase *device)
 
void updateLensParams (const int height, const int width)
 
virtual ~UCamRad ()
 
- Public Member Functions inherited from UCamPanTiltDevice
int getPanMaxRange ()
 
int getPanMinRange ()
 
int getPanPos ()
 
int getTiltMaxRange ()
 
int getTiltMinRange ()
 
int getTiltPos ()
 
bool isPantiltSupported ()
 
bool isPantiltValid ()
 
bool pantiltSetPosition (bool relative, int pan, int tilt)
 
bool pantiltToHomePosition ()
 
bool pantiltUpdatePosition ()
 
bool setPantiltStatus ()
 
 UCamPanTiltDevice (UCamDevBase *device)
 
- Public Member Functions inherited from UCamBase
const char * getCamName ()
 
UCamDevBasegetDev ()
 
int getDevNum ()
 
virtual void gotNewImage (UImage *)
 
virtual void imgUpdated ()
 
virtual bool needNewPushData ()
 
void setTypeName (const char *newName)
 
void setVarPool (UVarPool *vpd)
 
 UCamBase (UCamDevBase *device)
 
virtual ~UCamBase ()
 

Public Attributes

UVarPoolvarBaseStruct
 

Protected Member Functions

bool getRadialU2DOffset (float xu, float yu, float *dxd, float *dyd)
 
UXYoffset getRadialU2DOffsetInt (int x, int y)
 
virtual void imageSizeChanged (double iResFactor)
 
bool lensParChanged ()
 
virtual bool logImage (UImage *)
 
bool removeRadialErrorOnePlane (unsigned char ps[], unsigned char pd[], unsigned int height, unsigned int width, float pixSize, bool halfRes)
 
bool removeRadialErrorPixels (UPixel ps[], UPixel pd[], unsigned int height, unsigned int width, float pixSize)
 
- Protected Member Functions inherited from UCamPanTiltDevice
bool protPantiltGetPosition ()
 
bool protPantiltGetRange ()
 
bool protPantiltReset (bool resetPan, bool resetTilt)
 

Private Attributes

int defaultColFormat
 
bool defaultRemRadErr
 
IplImage * mapx
 
IplImage * mapy
 
UCamPar par
 
UXYoffset radialOffset [MAX_IMAGE_HEIGHT_RAD_SQUARE][MAX_IMAGE_WIDTH_RAD_SQUARE]
 
bool radialOffsetValid
 
UVariablevarDistortion
 pointer to lens distortion parameters radial (k1, k2, k3) and tangential - ccd-chip not parallel to lens (p1, p2)) More...
 
UVariablevarIntrinsic
 pointer to intrinsic camera parameters (focal-length and head-point) More...
 

Additional Inherited Members

- Protected Attributes inherited from UCamBase
UCamDevBasedev
 
UVarPoolvars
 

Detailed Description

Class that includes camera functtions to remove radial error in the raw images. The calss is based on both the camera device 'UCamDevice' and camera parameters 'UCamPar'.

Author
Christian Andersen

Constructor & Destructor Documentation

UCamRad::UCamRad ( UCamDevBase device)
UCamRad::~UCamRad ( )
virtual

Destructor

References mapx, and mapy.

Member Function Documentation

void UCamRad::createVars ( )
virtual

Create locally maintained variables - if any

Reimplemented from UCamBase.

Reimplemented in UCamMounted, and UCamPush.

References UVarPool::addVarA(), UCamBase::createVars(), varDistortion, varIntrinsic, and UCamBase::vars.

Referenced by UCamMounted::createVars(), and setCameraParameters().

UCamPar* UCamRad::getCamPar ( )
inline
int UCamRad::getDefaultColFormat ( )
inline

Default color format if auto repeat is turned on. is set only when capturing an HDR image set.

bool UCamRad::getDefaultRemRadErr ( )
inline

Should radial error be removed by default when auto repeat is turned on. Is set when capturing an image

bool UCamRad::getImageSnapshot ( UImage image)

Overwrite get Image Snapshot to allow removal of radial error if such removal is possible and set as default. returns true if image were captured and radial error status were removed or not as requetsed. Result is always in URawImage YUV42 or Bayer RGGB format. If 'image' == NULL then an image is captured, and discarded.

References UCamBase::dev, UCamDevBase::getImageSnapshot(), UCamDevBase::isCameraOpen(), logImage(), and UCamDevBase::openDeviceDefault().

Referenced by UFuncCog::centerOfGravity(), UFuncFocus::doFocus(), UFunctionCam::handleCamPushCommand(), testCameraHDR(), testCameraSettings(), testMatrixVecBig(), testRadErr(), testVideo2(), and testVideo3().

bool UCamRad::getRadialU2DOffset ( float  xu,
float  yu,
float *  dxd,
float *  dyd 
)
protected

Same as above, but makes float calculations and return change in coordinates to dx, dy. to get the corresponding position in the raw image.

References UCamPar::getRadialU2D(), and par.

Referenced by getRadialU2DOffsetInt().

UXYoffset UCamRad::getRadialU2DOffsetInt ( int  x,
int  y 
)
protected

Calculate where to fetch a pixel in the distorted image (raw) to this corrected image position relative to this {x,y} position (+ is right and down). The returned result {X,Y} position is in 16 bit accuracy with fixed decimal point, i.e. multiplied with 'resultDecimalFactor' (probably 10). The decimal part should be used to interpolate between pixels in the raw image.

References UXYoffset::dx, UXYoffset::dy, getRadialU2DOffset(), resultDecimalFactor, and roundi().

Referenced by setRadialErrorMatrix().

void UCamRad::imageSizeChanged ( double  iResFactor)
protectedvirtual

Set the parameters derived from resolution, i.e. conversion matrix, radial error valeues etc.

Reimplemented from UCamBase.

References par, radialOffsetValid, UCamPar::setPixelSize(), setRadialErrorMatrix(), and updateLensParams().

bool UCamRad::lensParChanged ( )
protected

Has focal length, headpoint or lens parameters changed - i.e. must rectification matrix be re-calculated.

Returns
true if any of these parameters has changed.

References UVariable::getDouble(), UCamPar::getFocalLength(), UCamPar::getHx(), UCamPar::getHy(), UCamPar::getK1(), UCamPar::getK2(), UVariable::getValued(), par, varDistortion, and varIntrinsic.

Referenced by removeRadialError().

virtual bool UCamRad::logImage ( UImage )
inlineprotectedvirtual

A call to see if anyone need the image logged.

Parameters
imageis the newly captured image.
Returns
true if used.

Reimplemented in UCamMounted.

Referenced by getImageSnapshot().

bool UCamRad::removeRadialError ( UImage source,
UImage destination 
)

Remove radial error from this image. uses openCV cvRemap(..) function to remove error. Resolution of destination will be as source. Uses pre-calculated correction matrix, if image size or rectification parameters has changed, then the rectification matrix is recalculated.

Parameters
sourceis source image
destinationis destination image - both must exist at call.
Returns
true if rectified.

References UImage::copyMeta(), UImage::cvArr(), UImage::getColorType(), UCamBase::getDev(), UImage::getHeight(), UCamPar::getPixelSize(), UImage::getUline(), UImage::getVline(), UImage::getWidth(), UImage::getYline(), UCamPar::isValid(), lensParChanged(), mapx, mapy, par, PIX_PLANES_BGGR, PIX_PLANES_GBRG, PIX_PLANES_GRBG, PIX_PLANES_RGGB, PIX_PLANES_YUV420, UImage::radialErrorRemoved, removeRadialErrorOnePlane(), UImage::toBGR(), UImage::updated(), and updateLensParams().

Referenced by UFunctionCamBase::getCamAndRawImage(), and UFuncRectify::handleCommand().

bool UCamRad::removeRadialErrorOnePlane ( unsigned char  ps[],
unsigned char  pd[],
unsigned int  height,
unsigned int  width,
float  pixSize,
bool  halfRes 
)
protected

Remove radial error for one pixel plane - either Y, U or V. A source pointer to the top-left pixel must be provided for source and destination, and the size of the images. The decimal factor is the factor in the radial error matrix that desides the decimal point. At full resolution this will normally be 10, at half resolution 20 and so on. For YUV the U and V the height, width and pixel size must be given in half resolution and further 'halfRes' must be true

References absi(), UXYoffset::dx, UXYoffset::dy, UCamPar::getHx(), UCamPar::getHy(), par, radialOffset, resultDecimalFactor, and roundi().

Referenced by removeRadialError().

bool UCamRad::removeRadialErrorPixels ( UPixel  ps[],
UPixel  pd[],
unsigned int  height,
unsigned int  width,
float  pixSize 
)
protected

Removes radial error based on offset array in full resolution as produced by 'setRadialErrorMatrix()'. Image pointers must be buffers of 'UPixel' ordered one row at a time, so that the next row follows imidiately after the first. A source pointer to the top-left pixel must be provided for source and destination, and the size of the images. The decimal factor is the factor in the radial error matrix that desides the decimal point. A pixel size must be provide for correct scaling of offset matrix values.

References absi(), UXYoffset::dx, UXYoffset::dy, UCamPar::getHx(), UCamPar::getHy(), par, radialOffset, resultDecimalFactor, roundi(), UPixel::u, UPixel::v, and UPixel::y.

void UCamRad::saveRadialCorrectionMatrix ( char *  filename)

Make textfile with radial correction values. Saves pixel offset values for the last used resolution.

References UCamBase::dev, UXYoffset::dx, UXYoffset::dy, UCamPar::getHx(), UCamPar::getHy(), UCamPar::getK1(), UCamPar::getK2(), UCamPar::getPixelSize(), UCamDevBase::MAX_IMAGE_WIDTH, par, radialOffset, radialOffsetValid, and resultDecimalFactor.

bool UCamRad::setCameraParameters ( float  hx,
float  hy,
float  k1,
float  k2,
float  focalLng 
)

Set camera internal parameters and redo the matrix for radial error removal and for conversion in camera coordinates (pixel to 3D and reverse). Parameters are expected to be in scale 1, i.e. 640x480 image size focal length, hx, hy (headpoint) are all in pixels and pixSizeFactor is pixel size relative to 640x480, i.e. 320x240 gives a pixSizeFactor of 2.0. Returns true if successful.

References createVars(), UCamBase::dev, UCamDevBase::getPixelSize(), par, UCamPar::setCameraParameters(), UVariable::setDouble(), setRadialErrorMatrix(), updateLensParams(), varDistortion, and varIntrinsic.

Referenced by UFuncPiCam::run(), UComCamSml::setCamDevice(), and testRadErr().

void UCamRad::setDefaultRemRadErr ( bool  value)
inline

Should radial error be removed by default when auto repeat is turned on. Is set when capturing an image

bool UCamRad::setRadialErrorMatrix ( )

Removal of radial error is done in according to calibration information in the referenced camera. Removal follows the guidelines in Image Analysis, Vision and Computer Graphics DTU/IMM publication by Jens Michael Carstensen Lyngby 2001, page 75.
focus length, Head-point (hx and hy) and correction factors (k1 and k2) are always in 640x480 resolution.

References UXYoffset::dx, UCamPar::getHx(), UCamPar::getHy(), UCamPar::getPixelSize(), getRadialU2DOffsetInt(), MAX_IMAGE_HEIGHT_RAD_SQUARE, MAX_IMAGE_WIDTH_RAD_SQUARE, par, radialOffset, radialOffsetValid, and UCamPar::setPixelSize().

Referenced by imageSizeChanged(), and setCameraParameters().

void UCamRad::updateLensParams ( const int  height,
const int  width 
)

Update lens parameters and setup distortion correction matrix - as used by openCV. and as used by the old correction scheme - in the UCamPar structure. Parameters are assumed to be loaded into the corresponding clobal variables

Parameters
heightis the actual image height in pixels.
widthis the actual width of image in pixels.

References UMatrix::cvMat(), UCamBase::getDev(), UVariable::getDouble(), UCamPar::getFocalLength(), UCamPar::getHx(), UCamPar::getHy(), UCamPar::getK1(), UCamPar::getK2(), UCamDevBase::getPixelSize(), UVariable::getValued(), UVariable::getValuesd(), mapx, mapy, par, UCamPar::setCameraParameters(), UMatrix::setMat(), varDistortion, and varIntrinsic.

Referenced by imageSizeChanged(), removeRadialError(), and setCameraParameters().

Member Data Documentation

int UCamRad::defaultColFormat
private

Default color format if auto repeat is turned on.

Referenced by UCamRad().

bool UCamRad::defaultRemRadErr
private

Should radial error be removed by default when auto repeat is turned on.

Referenced by UCamRad().

IplImage* UCamRad::mapx
private
IplImage* UCamRad::mapy
private
UCamPar UCamRad::par
private
bool UCamRad::radialOffsetValid
private

Is the radial error table calculated

Referenced by imageSizeChanged(), saveRadialCorrectionMatrix(), setRadialErrorMatrix(), and UCamRad().

UVarPool* UCamRad::varBaseStruct

structure for variables for this camera

UVariable* UCamRad::varDistortion
private

pointer to lens distortion parameters radial (k1, k2, k3) and tangential - ccd-chip not parallel to lens (p1, p2))

Referenced by createVars(), lensParChanged(), setCameraParameters(), UCamRad(), and updateLensParams().

UVariable* UCamRad::varIntrinsic
private

pointer to intrinsic camera parameters (focal-length and head-point)

Referenced by createVars(), lensParChanged(), setCameraParameters(), UCamRad(), and updateLensParams().


The documentation for this class was generated from the following files: