AURobotServers  4
Public Member Functions | Protected Member Functions | Private Attributes | Static Private Attributes | List of all members
UFuncBall_improved Class Reference
Inheritance diagram for UFuncBall_improved:
Inheritance graph

Public Member Functions

virtual bool handleCommand (UServerInMsg *msg, void *extra)
 
 UFuncBall_improved ()
 
virtual ~UFuncBall_improved ()
 
- Public Member Functions inherited from UFunctionCamBase
virtual void createResources ()
 
UImagegetImage (UServerInMsg *msg, void *extra)
 
virtual bool setResource (UResBase *ressource, bool remove)
 
 UFunctionCamBase ()
 
virtual ~UFunctionCamBase ()
 
- Public Member Functions inherited from UFunctionImgBase
virtual void setCmdHandler (UCmdExe *cmdExe)
 
void showImagesAsDefault (bool show)
 
 UFunctionImgBase ()
 
virtual ~UFunctionImgBase ()
 
- Public Member Functions inherited from UFunctionBase
bool addResource (UResBase *resource, UFunctionBase *owner)
 
void closeLogfile ()
 
virtual const char * commandList ()
 
const char * getAliasName ()
 
const char * getLoadedFileName ()
 
void * getLoadedModuleRef ()
 
virtual bool gotAllResources (char *missingThese, int missingTheseCnt)
 
bool isMine (const char *cmdName)
 
bool isStatic ()
 is the module loaded as static A module is static if the ldFilename has a length of zero. More...
 
virtual const char * name ()
 
bool newCmd (UServerInMsg *newMsg, UDataBase *extra)
 
bool newCommand (UServerInMsg *newMsg, void *extra)
 
bool openLogfile (const char *name)
 
void print (const char *preString)
 
virtual void resourceUpdated ()
 
bool sendEndTag (UServerInMsg *msg)
 
bool sendEndTag ()
 
bool sendFullTag (const char *attributes)
 
bool sendHelpDone (UServerInMsg *msg)
 
bool sendHelpDone ()
 
bool sendHelpStart (UServerInMsg *msg, const char *subject)
 
bool sendHelpStart (const char *subject)
 
bool sendHelpStart ()
 
bool sendMsg (UServerInMsg *msg, const char *message, int size)
 
bool sendMsg (const char *message)
 
bool sendMsg (UServerInMsg *msg, const char *message)
 
bool sendMsg (int clientIdx, const char *message, int size)
 
bool sendMsgInt (int clientIdx, const char *message)
 
bool sendStartTag (const char *attributes)
 
bool sendText (UServerInMsg *msg, const char *text)
 
bool sendText (const char *text)
 
virtual void setAliasName (const char *name)
 
virtual void setCommand (const char *cmdList, const char *name, const char *note)
 
void setLoadedModuleRef (void *module, const char *moduleFileName)
 
virtual void setLoadTime (UTime)
 
void setName (const char *name)
 
void setVerbose (bool value)
 
 UFunctionBase ()
 
virtual ~UFunctionBase ()
 
- Public Member Functions inherited from UCallBack
bool addOnEvent (UOnEvent *dataObject)
 
virtual bool onEvent (const char *interface, const char *dataType, void *data)
 
 UCallBack ()
 
virtual ~UCallBack ()
 
- Public Member Functions inherited from UResVarPool
int addMethod (const char *formalName, const char *paramTypes, const char *comment)
 
int addMethodV (const char *formalName, const char *paramTypes, const char *comment)
 
UVarPooladdStruct (const char *name, const char *comment, bool copy=false)
 
UVariableaddVar (const char *name, const double initialValue, const char *type, const char *comment)
 
UVariableaddVar (const char *name, const char *initialValue, const char *type, const char *comment)
 
UVariableaddVarA (const char *name, const char *initialValue, const char *type, const char *comment)
 
bool callGlobal (const char *name, const char *paramOrder, char **strings, const double *doubles, double *value, UDataBase **returnStruct, int *returnStructCnt)
 
bool callGlobalV (const char *name, const char *paramOrder, UVariable **params, UDataBase **returnStruct, int *returnStructCnt)
 Call a method from the root var pool scope It may be in the structure direct (no '.') or in any sub-structure that the 'name.subname' indicate. More...
 
bool callLocal (const char *name, const char *paramOrder, char **strings, const double *doubles, double *value, UDataBase **returnStruct, int *returnStructCnt)
 
bool callVS (const char *function, const char *stringParam)
 
int callVSCD (const char *function, const char *strPar, UDataBase *data, int cooSys)
 
void createBaseVar ()
 
virtual bool createVarSpace (const int varCnt, const int structCnt, const int methCnt, const char *note, bool copy=false)
 
bool getGlobalString (const char *name, const char **value)
 
bool getGlobalValue (const char *name, double *value)
 
bool getGlobalValue (const char *name, const char **value)
 
bool getGlobalValue (const char *name, bool *value)
 
bool getGlobalValue (const char *name, UTime *value)
 
bool getLocalValue (const char *name, double *value)
 get a value in this variable tree More...
 
bool getLocalValue (const char *name, bool *value)
 
bool getLocalValue (const char *name, UTime *value)
 
double getLocalValue (int idx)
 
UPosition getLocalValue3D (int idx)
 
UPosRot getLocalValue6D (int idx)
 
bool getLocalValueBool (int idx)
 
int getLocalValueInt (int idx)
 
UTime getLocalValueTime (int idx)
 
const char * getLogFileName ()
 
const char * getVarDescription (int idx)
 
UVarCalcgetVarPool ()
 
bool isLogFileOpen ()
 
bool isLogFileOpen (const char *structName)
 
bool isVarPoolUpdated (int lastCnt, int *newCnt)
 
void logFileClose ()
 
bool logFileOpen ()
 
void logFileStart (const char *structName, bool open)
 
virtual bool methodCall (const char *name, const char *paramOrder, char **strings, const double *doubles, double *value, UDataBase **returnStruct=NULL, int *returnStructCnt=NULL)
 
virtual const char * print (const char *preString, char *buff, int buffCnt)
 
bool setGlobalVar (const char *name, const double value, bool mayAdd)
 Assigns a value to a variable. The variable may be a part of a structure. More...
 
bool setLocalVar (int idx, double value, const int element)
 
bool setLocalVar (const char *name, const double value, bool mayAdd)
 Assigns a value to a variable. The variable may be a part of a structure. More...
 
bool setLocalVar3D (int idx, UPosition *value)
 
bool setLocalVar6D (int idx, UPosRot *value)
 
bool setLocalVarAdd (int idx, double value, const int element)
 
bool setLocalVarPose (int idx, UPose *value)
 
void setVarPool (UVarCalc *sharedVarPool)
 
int updateQTvars (int structIdx)
 
 UResVarPool ()
 
virtual ~UResVarPool ()
 
- Public Member Functions inherited from UResBase
void createReplayVar (UVarPool *pool)
 
UCmdExegetCorePointer ()
 
char * getLogFileName (char *fn, const int fnCnt)
 
int getResFuncIdx ()
 
const char * getResID ()
 
int getResVersion ()
 
bool isA (const char *idStr)
 
bool isAlsoA (const char *id)
 
virtual void saveSettings ()
 
void setCorePointer (UCmdExe *serverCore)
 
void setResFuncIdx (int idx)
 
virtual void setResID (const char *id, const int version)
 
virtual void stop (bool)
 
virtual void updateReplayStatus ()
 
 UResBase ()
 
virtual ~UResBase ()
 
- Public Member Functions inherited from UReplay
void addChild (UReplay *child)
 
virtual bool decodeReplayLine (char *)
 
char * getLogFileName (char *fn, const int fnCnt)
 
char * getReplayFileName (char *fn, const int fnCnt)
 
int getReplayLogLine ()
 
bool isReplay ()
 
bool isReplayFileOpen ()
 
void removeChild (UReplay *child)
 
virtual void replayAdvanceTime (UTime untilTime)
 
void replaySetBaseFileName (const char *name, const char *preName="")
 
void replaySetFileName (const char *name)
 
virtual bool replayStep ()
 
int replayStep (int steps)
 
virtual bool replayToTime (UTime untilTime)
 
void setParent (UReplay *parent)
 
bool setReplay (bool value)
 
 UReplay ()
 
virtual ~UReplay ()
 
- Public Member Functions inherited from ULock
bool lock ()
 
void lockInit ()
 
void post ()
 
bool tryLock ()
 
bool tryWait ()
 
 ULock ()
 
void unlock ()
 
bool wait ()
 
 ~ULock ()
 
- Public Member Functions inherited from UVarMethodImplement
virtual bool methodCallV (const char *name, const char *paramOrder, UVariable *params[], UDataBase **returnStruct, int *returnStructCnt)
 
virtual ~UVarMethodImplement ()
 

Protected Member Functions

bool calculateBallPosition (UCamPush *cam, UImage *ellImg, double ballDiam)
 
void createBaseVar ()
 
void filterMask (UImage *src, UImage *dst)
 
bool findBall (UCamPush *cam, UImage *img, bool debug, bool blue)
 
bool findBallCandidates (UImage *img, UImage *ellImg)
 
double getBallSize ()
 
int getCnt ()
 
UPosition getPos ()
 
void maskColors (UImage *srcImg, UImage *dstImg, bool blue)
 
- Protected Member Functions inherited from UFunctionCamBase
UCamPushgetCam (int imgDevice, const char *posName)
 
UCamPushgetCam (int camDevNum)
 
bool getCamAndRawImage (UCamPush **cam, UImage **imgRaw, int *imgDevice, void *imgBase, const char *posName, int rectfiedImg)
 
int getDefaultCamDevice ()
 
- Protected Member Functions inherited from UFunctionImgBase
bool sendImage (UServerInMsg *msg, const char *tagName, UImage *imgRgb, int imgLeft=0, int imgTop=0, int imgWidth=640, int imgHeight=480, int imgSource=-1, bool isCodecBin=true, bool imgIsBW=false, bool imgGetNum=true, bool imgGetTod=true, bool imgGetTime=false, const char *posName=NULL, bool imgGetName=true, bool silent=false)
 
- Protected Member Functions inherited from UFunctionBase
int getCmdIndex ()
 
UResBasegetStaticResource (const char *resName, bool mayCreate, bool staticOnly=true)
 get a pointer to a static resource. More...
 
bool isClientAlive (int clientIdx, double holdOffTime)
 
bool sendDebug (UServerInMsg *msg, const char *debugText)
 
bool sendDebug (const char *debugText)
 
bool sendError (UServerInMsg *msg, const char *errorText)
 
bool sendError (const char *errorText)
 
bool sendHelp (UServerInMsg *msg, const char *infoText)
 
bool sendHelp (const char *infoText)
 
bool sendInfo (UServerInMsg *msg, const char *infoText)
 
bool sendInfo (const char *infoText)
 
bool sendWarning (UServerInMsg *msg, const char *warningText)
 
bool sendWarning (const char *warningText)
 
UResBasesetThisResource (const char *ID, UResBase *resource, bool remove, bool *changed, UResBase *currentResPtr, bool *isLocal)
 
- Protected Member Functions inherited from UResVarPool
void setDescription (const char *note, bool copy=false)
 
- Protected Member Functions inherited from UResBase
UResBasegetStaticResource (const char *resName, bool mayCreate, bool staticOnly=true)
 get a pointer to a static resource. More...
 

Private Attributes

UPosition ballPos
 most likely ball position in robot coordinates More...
 
CvBox2D32f ell [MAX_ELL_CNT]
 resulting ellipses found in image More...
 
int ellCnt
 number of ellipses found More...
 
int imgSizeH
 size of source image in pixels More...
 
int imgSizeW
 size of source image in pixels More...
 
UVariablevarBallSize
 pointer to known size of ball More...
 
UVariablevarBlueCnt
 pointer to number of balls found in image More...
 
UVariablevarBlueLim
 pointer to limiting red values uMin, uMax, vMin, vMax More...
 
UVariablevarBluePos
 pointer to ball position {x,y,z} More...
 
UVariablevarBlueTime
 pointer to time of detection More...
 
UVariablevarFac
 Maximum size for an estimated ball. More...
 
UVariablevarMajMinRatio
 minimum ratio metween major and minor axis of ellipse More...
 
UVariablevarMaxSize
 Maximum size for an estimated ball. More...
 
UVariablevarMinSize
 Maximum size for an estimated ball. More...
 
UVariablevarPoolImg
 pointer to limiting red values redMin, redMax, greenMin, greenMax More...
 
UVariablevarRedCnt
 pointer to number of balls found in image More...
 
UVariablevarRedLim
 pointer to limiting red values redMin, redMax, greenMin, greenMax More...
 
UVariablevarRedPos
 pointer to ball position {x,y,z} More...
 
UVariablevarRedTime
 pointer to time of detection More...
 
UVariablevarTopLine
 topmost line in image More...
 

Static Private Attributes

static const int MAX_ELL_CNT = 100
 

Additional Inherited Members

- Static Public Member Functions inherited from UResVarPool
static const char * getResClassID ()
 
- Public Attributes inherited from UFunctionBase
bool silent
 is reply to client and console to be limited More...
 
- Public Attributes inherited from UReplay
bool replayTimeAdvancePending
 
UTime replayTimeNow
 
- Static Public Attributes inherited from UFunctionBase
static const int MAX_ID_LENGTH = 30
 
static const int MAX_RESOURCE_LIST_SIZE = 250
 
- Protected Attributes inherited from UFunctionCamBase
UCamPoolcamPool
 
- Protected Attributes inherited from UFunctionImgBase
UImagePoolimgPool
 
- Protected Attributes inherited from UFunctionBase
char aliasName [MAX_ID_LENGTH]
 
UCmdExecmdHandler
 
char * cmdToks [20]
 
int cmdToksCnt
 
char commandsHandled [MAX_RESOURCE_LIST_SIZE]
 
UServerInMsgmsg
 
char pluginName [MAX_RESOURCE_LIST_SIZE]
 
bool verboseMessages
 
- Protected Attributes inherited from UResBase
int resFuncIdx
 
char resID [MAX_RESOURCE_ID_LENGTH]
 
char resIsAlso [MAX_RESOURCE_ISALSO_LENGTH]
 
int resVersion
 
- Protected Attributes inherited from UReplay
bool replay
 
FILE * replayFile
 
char replayFileName [REPLAY_FILE_NAME_LENGTH]
 replay filename More...
 
char replayLine [MAX_LOG_LINE_LENGTH]
 
int replayLogLine
 
UReplayreplayParent
 
UTime replayTimeNext
 
- Static Protected Attributes inherited from UReplay
static const int MAX_LOG_LINE_LENGTH = 10000
 
static const int REPLAY_FILE_NAME_LENGTH = 264
 max length of replay filename More...
 

Detailed Description

Example plugin to find balls in camera image

Author
Christian Andersen

Constructor & Destructor Documentation

UFuncBall_improved::UFuncBall_improved ( )
inline

Constructor

References createBaseVar(), ellCnt, and UFunctionBase::setCommand().

virtual UFuncBall_improved::~UFuncBall_improved ( )
inlinevirtual

Destructor - to delete the resource (etc) when finished

Member Function Documentation

bool UFuncBall_improved::calculateBallPosition ( UCamPush cam,
UImage ellImg,
double  ballDiam 
)
inlineprotected

Find the best of the estimated ball candidate and calculate the ball position relalive to the robot. Expect estimate ellipses that may be balls in the array 'ell' with ellCnt ellipses found. The result is converted to first camera coordinates using the camera focal length and a known ball size. There is no radial error correction applied, so some error must be expected. The camera coordinates are transformed to robot coordinates using a known camera pose (from the camera structure). The result is saved in the 'ballPos' variable in meters relative to the robot. If the ball is close to the edge of the image and partially out of the image, then one of the flags isOutL or isOutR is set to true.

Parameters
camis a pointer to a camera device with camera position and lens parameters
ellImgoptional image for debug paint, emmits also more printout to console
ballDiamis the known diameter of the ball (in meter)
Returns
true if possible - and if true, then the ballPos, isOutL and isOutR is set.

References ballPos, UImage::cvArr(), ell, ellCnt, UCamRad::getCamPar(), UCamPar::getFocalLength(), UCamPar::getHx(), UCamPar::getHy(), UCamMounted::getPosRot(), UPosRot::getRtoMMatrix(), UPosition::print(), UPosition::x, UPosition::y, and UPosition::z.

Referenced by findBall().

void UFuncBall_improved::createBaseVar ( )
inlineprotected
void UFuncBall_improved::filterMask ( UImage src,
UImage dst 
)
inlineprotected

filter the image. Source and destination image may be the same.

Parameters
srcis the source image
dstis the destination image

References UImage::copyMeta(), UImage::cvArr(), UImagePool::getImage(), UVariable::getInt(), UFunctionBase::getStaticResource(), UFunctionImgBase::imgPool, and varPoolImg.

Referenced by findBall().

bool UFuncBall_improved::findBall ( UCamPush cam,
UImage img,
bool  debug,
bool  blue 
)
inlineprotected

Find red ball in image, using parameters from global var pool

Parameters
camcamera from wich the image was taken (has focal length and camera pose)
imgis a pointer to the image to be analized
debugif true, then more images are producen in the image pool
blueif true, then the blue color values are used (else the red values)
Returns
true if at least one red ball is found

References ballPos, calculateBallPosition(), UImage::copy(), ellCnt, filterMask(), findBallCandidates(), UTime::getDecSec(), UImagePool::getImage(), UVariable::getInt(), UFunctionBase::getStaticResource(), UVariable::getValued(), UImage::height(), UFunctionImgBase::imgPool, imgSizeH, imgSizeW, UImage::imgTime, maskColors(), UVariable::set3D(), UImage::setName(), UVariable::setValued(), UImage::tone(), UImage::updated(), varBallSize, varBlueCnt, varBluePos, varBlueTime, varPoolImg, varRedCnt, varRedPos, varRedTime, and UImage::width().

Referenced by handleCommand().

bool UFuncBall_improved::findBallCandidates ( UImage img,
UImage ellImg 
)
inlineprotected

Find balls in this image. This function is almost a direct copy of the 'fitellipse.c' example from the opencv package.

Parameters
imgis a pointer to a BW mask image with interesting pixels beeing > 0
ellImgoptional image where found ellipses are drawn (for debug)
Returns
true if at least one ball candidate is found.

References UImage::cvArr(), ell, ellCnt, UVariable::getDouble(), UVariable::getInt(), MAX_ELL_CNT, varMajMinRatio, varMaxSize, and varMinSize.

Referenced by findBall().

double UFuncBall_improved::getBallSize ( )
inlineprotected

Get the ball size - from global variable store

References UVariable::getValued(), and varBallSize.

int UFuncBall_improved::getCnt ( )
inlineprotected

Get number of balls found in image

References ellCnt.

Referenced by handleCommand().

UPosition UFuncBall_improved::getPos ( )
inlineprotected

Get position of this estimated ball position

Returns
the position as a UPosition structure

References ballPos.

Referenced by handleCommand().

virtual bool UFuncBall_improved::handleCommand ( UServerInMsg msg,
void *  extra 
)
inlinevirtual
void UFuncBall_improved::maskColors ( UImage srcImg,
UImage dstImg,
bool  blue 
)
inlineprotected

Find balls in this image. Most of the code used is from the original code example.

Parameters
srcImgis a pointer to the image to be analyzed
dstImgis where the pixels with the ball color is saved.
debugif true, then more images are produced in the image pool
blueare we looking for a blue ball (else a red)

References UImage::copyMeta(), UImage::getHeight(), UVariable::getInt(), UImage::getLine(), UImage::getWidth(), UImage::isRGB(), UPixel::p1, UPixel::p2, UPixel::p3, UImage::setName(), UImage::setSize(), UImage::toRGB(), UImage::updated(), UResBase::var, varBlueLim, varRedLim, and varTopLine.

Referenced by findBall().

Member Data Documentation

UPosition UFuncBall_improved::ballPos
private

most likely ball position in robot coordinates

Referenced by calculateBallPosition(), findBall(), and getPos().

CvBox2D32f UFuncBall_improved::ell[MAX_ELL_CNT]
private

resulting ellipses found in image

Referenced by calculateBallPosition(), and findBallCandidates().

int UFuncBall_improved::ellCnt
private

number of ellipses found

Referenced by calculateBallPosition(), findBall(), findBallCandidates(), getCnt(), and UFuncBall_improved().

int UFuncBall_improved::imgSizeH
private

size of source image in pixels

Referenced by findBall().

int UFuncBall_improved::imgSizeW
private

size of source image in pixels

Referenced by findBall().

const int UFuncBall_improved::MAX_ELL_CNT = 100
staticprivate

Referenced by findBallCandidates().

UVariable* UFuncBall_improved::varBallSize
private

pointer to known size of ball

Referenced by createBaseVar(), findBall(), and getBallSize().

UVariable* UFuncBall_improved::varBlueCnt
private

pointer to number of balls found in image

Referenced by createBaseVar(), and findBall().

UVariable* UFuncBall_improved::varBlueLim
private

pointer to limiting red values uMin, uMax, vMin, vMax

Referenced by createBaseVar(), and maskColors().

UVariable* UFuncBall_improved::varBluePos
private

pointer to ball position {x,y,z}

Referenced by createBaseVar(), and findBall().

UVariable* UFuncBall_improved::varBlueTime
private

pointer to time of detection

Referenced by createBaseVar(), and findBall().

UVariable* UFuncBall_improved::varFac
private

Maximum size for an estimated ball.

Referenced by createBaseVar().

UVariable* UFuncBall_improved::varMajMinRatio
private

minimum ratio metween major and minor axis of ellipse

Referenced by createBaseVar(), and findBallCandidates().

UVariable* UFuncBall_improved::varMaxSize
private

Maximum size for an estimated ball.

Referenced by createBaseVar(), and findBallCandidates().

UVariable* UFuncBall_improved::varMinSize
private

Maximum size for an estimated ball.

Referenced by createBaseVar(), and findBallCandidates().

UVariable* UFuncBall_improved::varPoolImg
private

pointer to limiting red values redMin, redMax, greenMin, greenMax

Referenced by createBaseVar(), filterMask(), findBall(), and handleCommand().

UVariable* UFuncBall_improved::varRedCnt
private

pointer to number of balls found in image

Referenced by createBaseVar(), and findBall().

UVariable* UFuncBall_improved::varRedLim
private

pointer to limiting red values redMin, redMax, greenMin, greenMax

Referenced by createBaseVar(), and maskColors().

UVariable* UFuncBall_improved::varRedPos
private

pointer to ball position {x,y,z}

Referenced by createBaseVar(), and findBall().

UVariable* UFuncBall_improved::varRedTime
private

pointer to time of detection

Referenced by createBaseVar(), and findBall().

UVariable* UFuncBall_improved::varTopLine
private

topmost line in image

Referenced by createBaseVar(), and maskColors().


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