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

#include <uimana.h>

Public Member Functions

bool findRoadPoly (bool debug, UImage *img, double balance, double limit, int x1, int y1, int x2, int y2, bool colorCorrect)
 
double getCromaTraceSD ()
 
CvPoint * getFloorPolygon ()
 
int getFloorPolygonCnt ()
 
int * getFloorPolygonCntP ()
 
char * getImageName (const char *list, const char *subdir, int n, char *buff, int buffLng)
 
bool * getObstacleFlags ()
 
bool imageContourMaha (UImage *img, UImage *imgC, unsigned int row, unsigned int col, UPixLinked *outlineBuffer, int *outlineBufferCnt, UMatrix4 *averageSeed, UMatrix4 *covarianceInv, double diff, double diffa)
 
bool imageContourMahaCroma (UImage *img, UImage *imgC, unsigned int row, unsigned int col, int x1, int y1, int x2, int y2, int maxH, UPixLinked *outlineBuffer, int *outlineBufferCnt, UMatrix4 *averageCroma, UMatrix4 *covarCromaInv, UMatrix4 *averageRgb, UMatrix4 *covarRgbInv, double ballance, double limit)
 
bool imageUsable (UImage *img)
 
double polygonArea (CvPoint *poly, int elements)
 
bool polygonReduce (UPixLinked *outlineBuffer, int *outlineBufferCnt, double tollerance, int topLine)
 
bool polygonReduce2 (UPixLinked *outlineBuffer, int *outlineBufferCnt, double tollerance, int topLine)
 
void setImagePool (UImagePool *imagePool)
 
void setStorage (CvMemStorage *mem)
 
 UImAna ()
 
 ~UImAna ()
 

Protected Member Functions

double getMahalonobisDist (UPixel *pix, UMatrix4 *average, UMatrix4 *covarianceInv)
 
double getMahalonobisDistCroma (UPixel *pix, UMatrix4 *average, UMatrix4 *covarianceInv, double averageY, bool useShadow)
 

Private Member Functions

int countContourEdges (CvSeq *contours)
 
int countContourLimits (CvSeq *contours, int *left, int *right, int *top, int *bottom, bool lookingLeft)
 
bool distFilt (UImage *simg, UImage *dimg, unsigned int maxW, unsigned int minW, unsigned int minR, unsigned int maxR)
 
bool distFiltH (UImage *simg, UImage *dimg, unsigned int maxW, unsigned int minW, unsigned int minR, unsigned int maxR, unsigned int maxMaskHeight)
 
int findContour (UImage *img, UImage *imgMask, UImage *dest, CvPoint *flp, int flpMax, bool *tooHigh, bool *tooSmall, bool lookingLeft)
 
int findContourPoly (UImage *img, UImage *imgM, UImage *imgC, bool *tooSmall, double lookingLeft, double pct1, double pct2)
 
int findContourPolyCroma (UImage *img, UImage *imgM, UImage *imgC, UImage *imgCroma, bool *tooSmall, int x1, int y1, int x2, int y2, int maxH, double ballance, double limit)
 
void findVertex (const UPixLinked *end1, const UPixLinked *end2, const int count, const int startNum, int **vertexList, int *vertexListCnt, const int listLength, const float toll, const int topLine)
 
bool getAvgVar (UImage *img, unsigned int x, unsigned int y, unsigned int w, unsigned int h, UMatrix4 *mE, UMatrix4 *mC)
 
double getRoadProbability (int r, int c, UImage *img, UImage *imgC, UMatrix4 *vECroma, UMatrix4 *averageCroma, UMatrix4 *covarCromaInv, double ballance, double averageY, bool useShadow)
 
bool paintRoadImage (int seedR, int seedC, UImage *img, UImage *imgC, UMatrix4 *vCroma, UMatrix4 *mCromaInv, UMatrix4 *vRgb, UMatrix4 *mRgbInv, double dyn, double abs)
 
int pixCmp (UPixel *p1, UPixel *p2)
 
UPixelpixSort (UPixel ***ps, int pixCnt)
 

Private Attributes

double cromaTrace
 
CvPoint * floorArea
 
int floorAreaCnt
 
UPixLinkedfloorOutline
 
int floorOutlineCnt
 
UImagePoolimgPool
 
bool * obst
 
CvMemStorage * storage
 

Detailed Description

Class for image analysis. Initially color statistics only.

Author
Christian Andersen

Constructor & Destructor Documentation

UImAna::UImAna ( )

Constructor

UImAna::~UImAna ( )

Destructor

Member Function Documentation

int UImAna::countContourEdges ( CvSeq *  contours)
private

Count edges in contour sequebnce

int UImAna::countContourLimits ( CvSeq *  contours,
int *  left,
int *  right,
int *  top,
int *  bottom,
bool  lookingLeft 
)
private

Find square limits of found contour returns the point cont, and if limit pointers != NULL the left, right, top and bottol limits of the points in the sequence.

References UPixLinked::r.

bool UImAna::distFilt ( UImage simg,
UImage dimg,
unsigned int  maxW,
unsigned int  minW,
unsigned int  minR,
unsigned int  maxR 
)
private

Filter image based on row number

References UPixLinked::c, UImage::copy(), UImage::getLine(), UPixLinked::r, and UImage::width().

bool UImAna::distFiltH ( UImage simg,
UImage dimg,
unsigned int  maxW,
unsigned int  minW,
unsigned int  minR,
unsigned int  maxR,
unsigned int  maxMaskHeight 
)
private

Median filter with variable mask width and maximum mask height. Mask height must be smaller than or equal to 5 (od number). Mask width must be smaller than or equal to 40.

References UPixLinked::c, UImage::copy(), UImage::getLine(), UImage::height(), mini(), UPixLinked::r, and UImage::width().

int UImAna::findContour ( UImage img,
UImage imgMask,
UImage dest,
CvPoint *  flp,
int  flpMax,
bool *  tooHigh,
bool *  tooSmall,
bool  lookingLeft 
)
private

Find contour of maksked area. and paint result in destination image.

References UImage::cvArr(), UImage::height(), mini(), UTime::Now(), and UImage::width().

int UImAna::findContourPoly ( UImage img,
UImage imgM,
UImage imgC,
bool *  tooSmall,
double  lookingLeft,
double  pct1,
double  pct2 
)
private

Find contour of area, using own routine, and reduction using Douglas-Peucker. LookingLeft decides seed-point 1.0 seed is full right, -1.0 seed is full left. Parameters are pct1 is dynamic edge size and pct2 is absolute from reference point. Resulting polygon is returned in floorArea with floorAreaCnt points. floorOutline buffer is used during calculation and holds the same information on return. too-small is set trus if outline is less that 100 pixels. Returns true if a proper area is found.

References UPixLinked::c, UImage::copy(), UImage::getLine(), UImage::getPixRef(), UImage::height(), UImage::imgTime, UMatrix4::inversed(), MAX_POLYGON_OUTLINE_POINTS, MAX_POLYGON_POINTS, maxi(), mini(), UTime::Now(), UPixel::p1, UPixel::p2, UPixel::p3, UMatrix::print(), UPixLinked::r, roundi(), UImage::setNameAndExt(), UMatrix::setRow(), UMatrix::setSize(), and UImage::width().

int UImAna::findContourPolyCroma ( UImage img,
UImage imgM,
UImage imgC,
UImage imgCroma,
bool *  tooSmall,
int  x1,
int  y1,
int  x2,
int  y2,
int  maxH,
double  ballance,
double  limit 
)
private

Find contour polygon using cromaticity

Parameters
imgis source image
imgM?? image
imgCcontour image
imgCromacromaticity source image
tooSmallis ???
x1,y1,x2,y2is seed area top-left to button right
balanceis ???
limitis ??
Returns
false on error
Todo:
try to remove small appendices from the road outline

References UPixLinked::c, UImage::copyMeta(), UImage::cvArr(), UTime::GetDateString(), UImage::getLine(), UImage::getPixRef(), UTime::GetTimeAsString(), UImage::height(), UImage::imgTime, UMatrix::init(), UMatrix4::inversed(), MAX_POLYGON_OUTLINE_POINTS, MAX_POLYGON_POINTS, maxi(), mini(), UMatrix::mult(), UImage::name, UTime::Now(), UPixel::p1, UPixel::p2, UPixel::p3, UPixel::pixRGB(), UMatrix::print(), UPixLinked::px, UPixLinked::r, roundi(), UImage::setNameAndExt(), UImage::setPix(), UMatrix::setRC(), UMatrix::setRow(), UMatrix::setSize(), SHADOW_COMPENSATION_FACTOR, sqr(), UMatrix::trace(), and UImage::width().

bool UImAna::findRoadPoly ( bool  debug,
UImage img,
double  balance,
double  limit,
int  x1,
int  y1,
int  x2,
int  y2,
bool  colorCorrect 
)

Find road using new outline search algorithem

Parameters
debugproduce more debug messages and images
camdev is number of camera device (to be found in camera pool
imgNis image number to analyze
balanceis ?? [0..1]
limitis ?? [0..2]
x1,y1,x2,y2is seed area
colorCorrectis ?
Returns
true if success

References UImage::copy(), UImage::copyMeta(), UImage::cvArr(), UImage::getLine(), UImage::height(), img, UImage::imgUpdated(), maxi(), mini(), UImage::name, UTime::Now(), UPixel::p1, UPixel::p2, UPixel::p3, UImage::setNameAndExt(), UImage::toBGR(), and UImage::width().

Referenced by UFuncImSeg::findSegments().

void UImAna::findVertex ( const UPixLinked end1,
const UPixLinked end2,
const int  count,
const int  startNum,
int **  vertexList,
int *  vertexListCnt,
const int  listLength,
const float  toll,
const int  topLine 
)
private

Find the most distant vertex from the line between these endpoints and recursively find all vertexes in between. Adds the index to the found verteces to the vertex list. This needs to be sorted at the end.

References UPixLinked::c, mini(), UPixLinked::r, sqr(), and sqri().

bool UImAna::getAvgVar ( UImage img,
unsigned int  x,
unsigned int  y,
unsigned int  w,
unsigned int  h,
UMatrix4 mE,
UMatrix4 mC 
)
private

Clear openCv storeage area Get average and covariance matrix for this part of image. Returns true if image is valid.

References UMatrix::add(), UPixLinked::c, UMatrix::clear(), UImage::getLine(), UMatrix::mult(), UPixel::p1, UPixel::p2, UPixel::p3, UPixLinked::r, UMatrix::set(), UMatrix::sub(), and UMatrix::transpose().

double UImAna::getCromaTraceSD ( )
inline

Get the cromaticity SD from the seed area.

CvPoint* UImAna::getFloorPolygon ( )
inline

Get estimated floor polygon

int UImAna::getFloorPolygonCnt ( )
inline

Get number of vertexes in floor polygon .

int* UImAna::getFloorPolygonCntP ( )
inline

Get pointer to number of vertexes in floor polygon .

char * UImAna::getImageName ( const char *  list,
const char *  subdir,
int  n,
char *  buff,
int  buffLng 
)

Set image Get image name - static for test purpose only Get image name from a 'ls *.bmp >imgListLog' list in file 'list' in subdirectory 'subdir' in the imagePath. The n'th filename in the list is extracted and stored in 'buff'. The buffer 'buffer' has space for buffCnt characters. If no name is found, then the returned string is empty, and NULL is returned. else a pointer to the filename is returned. The filename must be a *.bmp file and the '.bmp' is removed from the filename. There is no path (imagePath nor subdir) in the filename.

References imagePath.

double UImAna::getMahalonobisDist ( UPixel pix,
UMatrix4 average,
UMatrix4 covarianceInv 
)
protected

Find the distance weighted (sqr) distance from this pixel value (RGB) using the provided covariance matrix as weight (Mahalonibis) Average must be a 1x3 vector and covariance must be 3x3 vector.

References UMatrix::get(), UPixel::p1, UPixel::p2, UPixel::p3, UMatrix::setRow(), and UMatrix::setSize().

double UImAna::getMahalonobisDistCroma ( UPixel pix,
UMatrix4 average,
UMatrix4 covarianceInv,
double  averageY,
bool  useShadow 
)
protected

Find the distance weighted (sqr) distance from this pixel value (CROMATICITY) using the provided covariance matrix as weight (Mahalonibis). Average must be a 1x2 vector and covariance must be 2x2 vector. If useShadow then the red value is shadow compensated.

References UMatrix::get(), UPixel::p1, UPixel::p2, UPixel::p3, UPixLinked::r, UMatrix::setRow(), UMatrix::setSize(), and SHADOW_COMPENSATION_FACTOR.

bool* UImAna::getObstacleFlags ( )
inline

Get boolean flag array to indicate that the vertex is part of an obstacle.

double UImAna::getRoadProbability ( int  r,
int  c,
UImage img,
UImage imgC,
UMatrix4 vECroma,
UMatrix4 averageCroma,
UMatrix4 covarCromaInv,
double  ballance,
double  averageY,
bool  useShadow 
)
private

Get road probability value for pixel at (r, c). If useShadow then a compensation for shadow is attempted.

References UImage::getPixRef(), UPixel::getSum(), UImage::height(), maxi(), mini(), and UImage::width().

bool UImAna::imageContourMaha ( UImage img,
UImage imgC,
unsigned int  row,
unsigned int  col,
UPixLinked outlineBuffer,
int *  outlineBufferCnt,
UMatrix4 averageSeed,
UMatrix4 covarianceInv,
double  diff,
double  diffa 
)

Find contour of image 'img' from a seed point by traversing from seedpoint clockwise until seedpoint is again reached. NB! must start at an bottom or right edge, as first test is down and there must be no way to loop back to start point clockwise. Finds an outline of area, but discards islands, that is only connected to "mainland" with one pixel. Buffer size should be at least 4000 points for a 320x240 image. Returns true if images are valid Same as above, but using Mahalonobis distance

References bool2str(), UPixLinked::c, UPixLinked::getNext(), UImage::getPixRef(), UImage::height(), UPixLinked::nx, UPixel::p1, UPixel::p2, UPixel::p3, UPixLinked::px, UPixLinked::r, UImage::setPix(), and UImage::width().

bool UImAna::imageContourMahaCroma ( UImage img,
UImage imgC,
unsigned int  row,
unsigned int  col,
int  x1,
int  y1,
int  x2,
int  y2,
int  maxH,
UPixLinked outlineBuffer,
int *  outlineBufferCnt,
UMatrix4 averageCroma,
UMatrix4 covarCromaInv,
UMatrix4 averageRgb,
UMatrix4 covarRgbInv,
double  ballance,
double  limit 
)

Same as above, but using Mahalonobis cromaticity distance Ballance is range [0..1] - default = 0.5. limit range 2.0 (no road) to 0.0 (all road) .

References bool2str(), UPixLinked::c, UMatrix::get(), UPixLinked::getNext(), UImage::getPixRef(), UPixLinked::nx, UPixel::p1, UPixel::p2, UPixel::p3, UPixLinked::px, UPixLinked::r, and UImage::width().

bool UImAna::imageUsable ( UImage img)
bool UImAna::paintRoadImage ( int  seedR,
int  seedC,
UImage img,
UImage imgC,
UMatrix4 vCroma,
UMatrix4 mCromaInv,
UMatrix4 vRgb,
UMatrix4 mRgbInv,
double  dyn,
double  abs 
)
private

Paint base image with road detection

References UPixLinked::c, UMatrix::copy(), UImage::height(), UPixLinked::r, and UImage::width().

int UImAna::pixCmp ( UPixel p1,
UPixel p2 
)
private

Compare pixels for intensity. Returns positive if p1 > p2, and 0 if equal, and negative if p2 > p1.

References a, UPixel::p1, UPixel::p2, and UPixel::p3.

UPixel * UImAna::pixSort ( UPixel ***  ps,
int  pixCnt 
)
private

Order this number of pixels after intensity in all channels (try), Returns the center element. NB! no range checks

double UImAna::polygonArea ( CvPoint *  poly,
int  elements 
)

Finds area of a polygon. The area is signed - positive if clockwise. Calculated as A = 0.5 * sum(a(i)) over all i in [0, n-1], where a(i) = x(i) * y(i-1) - x(i-1) * y(i), where the first element (i=0) uses the last element (n-1) i.s.f. (i-1). http://homepages.borland.com/efg2lab/Graphics/PolygonArea.htm.

References a.

bool UImAna::polygonReduce ( UPixLinked outlineBuffer,
int *  outlineBufferCnt,
double  tollerance,
int  topLine 
)

Reduce vertex count using a Douglas-Peuker reduction method. Method from: http://geometryalgorithms.com/Archive/algorithm_0205

References MAX_POLYGON_POINTS, and sqr().

bool UImAna::polygonReduce2 ( UPixLinked outlineBuffer,
int *  outlineBufferCnt,
double  tollerance,
int  topLine 
)

Remove closed appendix areas

References a, UPixLinked::c, mini(), and UPixLinked::r.

void UImAna::setImagePool ( UImagePool imagePool)
inline

Set image pool

References UPixLinked::c, and UPixLinked::r.

Referenced by UFuncImSeg::findSegments().

void UImAna::setStorage ( CvMemStorage *  mem)
inline

Set storage pointer

References img.

Member Data Documentation

double UImAna::cromaTrace
private

Seed area cromaticity standard deviation

CvPoint* UImAna::floorArea
private

Array of CvPoint, that holds the the floor contour

int UImAna::floorAreaCnt
private

Number of points in contour

UPixLinked* UImAna::floorOutline
private

Array of points and directions in floor outline

int UImAna::floorOutlineCnt
private

Count of elements in outline

UImagePool* UImAna::imgPool
private

Reference to image pool

bool* UImAna::obst
private

List of obstacle vertex. If two connected vertwx are non obstacle the the line between are not a detected obstacle, if on vertex is an obstacle, then it mustbe assumed to be so.

CvMemStorage* UImAna::storage
private

Image to be analized Storage used by openCV


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