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

#include <uimageana.h>

Public Member Functions

bool findRoad (unsigned int x, unsigned int y, unsigned int w, unsigned int h, UImage *resultImg, bool debug, int imgNum, char *imgN)
 
bool findRoadCroma (unsigned int x, unsigned int y, unsigned int w, unsigned int h, UImage *resultImg, bool debug, int imgNum, char *imgN, int pct)
 
bool findRoadFill (unsigned int x, unsigned int y, unsigned int w, unsigned int h, UImage *resi, bool debug, int camDev, char *imgName, int pct, bool lookingLeft)
 
bool findRoadPoly (bool debug, int camDev, char *imgN, double ballance, double limit, double lookingLeft, 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)
 
const char * getImageName2 (int i)
 
bool * getObstacleFlags ()
 
bool imageContour2 (UImage *img, UImage *imgC, unsigned int row, unsigned int col, UPixelLinked *outlineBuffer, int *outlineBufferCnt, double diff, double diffa)
 
bool imageContourMaha (UImage *img, UImage *imgC, unsigned int row, unsigned int col, UPixelLinked *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, UPixelLinked *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 (UPixelLinked *outlineBuffer, int *outlineBufferCnt, double tollerance, int topLine)
 
bool polygonReduce2 (UPixelLinked *outlineBuffer, int *outlineBufferCnt, double tollerance, int topLine)
 
void setImage (UImage *toImg)
 
void setImagePool (UImagePool *imagePool)
 
void setStorage (CvMemStorage *mem)
 
 UImageAna ()
 
 ~UImageAna ()
 

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 *imgMask, UImage *dest, CvPoint *flp, int flpMax, bool *tooHigh, bool *tooSmall, bool lookingLeft)
 
int findContourPoly (UImage *imgM, UImage *imgC, bool *tooSmall, double lookingLeft, double pct1, double pct2)
 
int findContourPolyCroma (UImage *imgM, UImage *imgC, UImage *imgCroma, bool *tooSmall, double lookingLeft, int x1, int y1, int x2, int y2, int maxH, double ballance, double limit)
 
void findVertex (const UPixelLinked *end1, const UPixelLinked *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
 
UPixelLinkedfloorOutline
 
int floorOutlineCnt
 
UImageimg
 
UImagePoolimgPool
 
bool * obst
 
CvMemStorage * storage
 

Detailed Description

Class for image analysis. Initially color statistics only.

Author
Christian Andersen

Constructor & Destructor Documentation

UImageAna::UImageAna ( )

Constructor

References img.

UImageAna::~UImageAna ( )

Destructor

Member Function Documentation

int UImageAna::countContourEdges ( CvSeq *  contours)
private

Count edges in contour sequebnce

int UImageAna::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 UPixelLinked::r.

bool UImageAna::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 UPixelLinked::c, UImage::copy(), UImage::getLine(), UPixelLinked::r, and UImage::width().

bool UImageAna::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 UPixelLinked::c, UImage::copy(), UImage::getLine(), UImage::height(), mini(), UPixelLinked::r, and UImage::width().

int UImageAna::findContour ( 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(), img, mini(), UTime::Now(), and UImage::width().

int UImageAna::findContourPoly ( 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 UPixelLinked::c, UImage::copy(), UImage::getLine(), UImage::getPixRef(), UImage::height(), img, UImage::imgTime, UMatrix4::inversed(), MAX_POLYGON_OUTLINE_POINTS, MAX_POLYGON_POINTS, maxi(), mini(), UTime::Now(), UPixel::p1, UPixel::p2, UPixel::p3, UMatrix::print(), UPixelLinked::r, roundi(), UImage::setNameAndExt(), UMatrix::setRow(), UMatrix::setSize(), and UImage::width().

int UImageAna::findContourPolyCroma ( UImage imgM,
UImage imgC,
UImage imgCroma,
bool *  tooSmall,
double  lookingLeft,
int  x1,
int  y1,
int  x2,
int  y2,
int  maxH,
double  ballance,
double  limit 
)
private
bool UImageAna::findRoad ( unsigned int  x,
unsigned int  y,
unsigned int  w,
unsigned int  h,
UImage resultImg,
bool  debug,
int  imgNum,
char *  imgN 
)
bool UImageAna::findRoadCroma ( unsigned int  x,
unsigned int  y,
unsigned int  w,
unsigned int  h,
UImage resultImg,
bool  debug,
int  imgNum,
char *  imgN,
int  pct 
)
bool UImageAna::findRoadFill ( unsigned int  x,
unsigned int  y,
unsigned int  w,
unsigned int  h,
UImage resi,
bool  debug,
int  camDev,
char *  imgName,
int  pct,
bool  lookingLeft 
)
bool UImageAna::findRoadPoly ( bool  debug,
int  camDev,
char *  imgN,
double  ballance,
double  limit,
double  lookingLeft,
int  x1,
int  y1,
int  x2,
int  y2,
bool  colorCorrect 
)
void UImageAna::findVertex ( const UPixelLinked end1,
const UPixelLinked 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 UPixelLinked::c, mini(), UPixelLinked::r, sqr(), and sqri().

bool UImageAna::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(), UPixelLinked::c, UMatrix::clear(), UImage::getLine(), UMatrix::mult(), UPixel::p1, UPixel::p2, UPixel::p3, UPixelLinked::r, UMatrix::set(), UMatrix::sub(), and UMatrix::transpose().

double UImageAna::getCromaTraceSD ( )
inline

Get the cromaticity SD from the seed area.

References img.

Referenced by UFunctionCamPath::findPath().

CvPoint* UImageAna::getFloorPolygon ( )
inline

Get estimated floor polygon

Referenced by UFunctionCamPath::findPath().

int UImageAna::getFloorPolygonCnt ( )
inline

Get number of vertexes in floor polygon .

Referenced by UFunctionCamPath::findPath().

int* UImageAna::getFloorPolygonCntP ( )
inline

Get pointer to number of vertexes in floor polygon .

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

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.

const char* UImageAna::getImageName2 ( int  i)

Get image name - static for test purpose only

double UImageAna::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 UImageAna::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, UPixelLinked::r, UMatrix::setRow(), UMatrix::setSize(), and SHADOW_COMPENSATION_FACTOR.

bool* UImageAna::getObstacleFlags ( )
inline

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

Referenced by UFunctionCamPath::findPath().

double UImageAna::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 UImageAna::imageContour2 ( UImage img,
UImage imgC,
unsigned int  row,
unsigned int  col,
UPixelLinked outlineBuffer,
int *  outlineBufferCnt,
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. Bufer size should be at least 4000 points for a 320x240 image. Returns true if images are valid

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

bool UImageAna::imageContourMaha ( UImage img,
UImage imgC,
unsigned int  row,
unsigned int  col,
UPixelLinked outlineBuffer,
int *  outlineBufferCnt,
UMatrix4 averageSeed,
UMatrix4 covarianceInv,
double  diff,
double  diffa 
)
bool UImageAna::imageContourMahaCroma ( UImage img,
UImage imgC,
unsigned int  row,
unsigned int  col,
int  x1,
int  y1,
int  x2,
int  y2,
int  maxH,
UPixelLinked 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(), UPixelLinked::c, UMatrix::get(), UPixelLinked::getNext(), UImage::getPixRef(), UPixelLinked::nx, UPixel::p1, UPixel::p2, UPixel::p3, UPixelLinked::px, UPixelLinked::r, and UImage::width().

bool UImageAna::imageUsable ( UImage img)
bool UImageAna::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 UPixelLinked::c, UMatrix::copy(), UImage::height(), UPixelLinked::r, and UImage::width().

int UImageAna::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 * UImageAna::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 UImageAna::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 UImageAna::polygonReduce ( UPixelLinked 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 UImageAna::polygonReduce2 ( UPixelLinked outlineBuffer,
int *  outlineBufferCnt,
double  tollerance,
int  topLine 
)

Remove closed appendix areas

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

void UImageAna::setImage ( UImage toImg)
inline

Set image

References img.

Referenced by UFunctionCamPath::findPath().

void UImageAna::setImagePool ( UImagePool imagePool)
inline

Set image pool

References UPixelLinked::c, and UPixelLinked::r.

Referenced by UFunctionCamPath::initializeFindPath().

void UImageAna::setStorage ( CvMemStorage *  mem)
inline

Set storage pointer

Referenced by UFunctionCamPath::initializeFindPath().

Member Data Documentation

double UImageAna::cromaTrace
private

Seed area cromaticity standard deviation

CvPoint* UImageAna::floorArea
private

Array of CvPoint, that holds the the floor contour

int UImageAna::floorAreaCnt
private

Number of points in contour

UPixelLinked* UImageAna::floorOutline
private

Array of points and directions in floor outline

int UImageAna::floorOutlineCnt
private

Count of elements in outline

UImage* UImageAna::img
private

Image to be analized

UImagePool* UImageAna::imgPool
private

Reference to image pool

bool* UImageAna::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* UImageAna::storage
private

Storage used by openCV


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