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

#include <uimagepoly.h>

Public Member Functions

bool findRoadPoly (UImage *img, 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)
 
bool makeSimilarImage2 (UImage *img, unsigned int x, unsigned int y, unsigned int w, unsigned int h, int imgPoolNum)
 intended for YUV image with a seed area More...
 
bool makeSimilarImage3 (UImage *img, unsigned int x, unsigned int y, unsigned int w, unsigned int h, UImage *resultImg, bool debug, int imgNum, char *imgN)
 
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 setImagePool (UImagePool *imagePool)
 
void setStorage (CvMemStorage *mem)
 
 UImagePoly ()
 
 ~UImagePoly ()
 

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 findContourPolyCroma (UImage *img, 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)
 
bool getAvgVar2 (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
 
UImagePoolimgPool
 
bool * obst
 
CvMemStorage * storage
 

Detailed Description

Class for image analysis. Initially color statistics only.

Author
Christian Andersen

Constructor & Destructor Documentation

UImagePoly::UImagePoly ( )

Constructor

UImagePoly::~UImagePoly ( )

Destructor

Member Function Documentation

int UImagePoly::countContourEdges ( CvSeq *  contours)
private

Count edges in contour sequebnce

int UImagePoly::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 UImagePoly::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 UImagePoly::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 UImagePoly::findContourPolyCroma ( UImage img,
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

Find contour of maksked area. and paint result in destination image. 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. Find contour polygon using cromaticity

Todo:
try to remove small appendices from the road outline

References UPixelLinked::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(), UPixelLinked::px, UPixelLinked::r, roundi(), UImage::setNameAndExt(), UImage::setPix(), UMatrix::setRC(), UMatrix::setRow(), UMatrix::setSize(), SHADOW_COMPENSATION_FACTOR, sqr(), UMatrix::trace(), and UImage::width().

bool UImagePoly::findRoadPoly ( UImage img,
bool  debug,
int  camDev,
char *  imgN,
double  ballance,
double  limit,
double  lookingLeft,
int  x1,
int  y1,
int  x2,
int  y2,
bool  colorCorrect 
)

Find road as area that matches this start area. Paint result in result image if in debug mode. Find road by filtering alone Find road using new outline search algorithem

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 UFuncImgPoly::findAreaFromSeedRGB().

void UImagePoly::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 UImagePoly::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().

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

Get average and covariance matrix for this part of image using plane 2 and 3 only (YUV). Returns true if image is valid.

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

double UImagePoly::getCromaTraceSD ( )
inline

Get the cromaticity SD from the seed area.

Referenced by UFuncImgPoly::findAreaFromSeedRGB().

CvPoint* UImagePoly::getFloorPolygon ( )
inline

Get estimated floor polygon

Referenced by UFuncImgPoly::findAreaFromSeedRGB().

int UImagePoly::getFloorPolygonCnt ( )
inline

Get number of vertexes in floor polygon .

Referenced by UFuncImgPoly::findAreaFromSeedRGB().

int* UImagePoly::getFloorPolygonCntP ( )
inline

Get pointer to number of vertexes in floor polygon .

char * UImagePoly::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* UImagePoly::getImageName2 ( int  i)

Set image Get image name - static for test purpose only

double UImagePoly::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 UImagePoly::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* UImagePoly::getObstacleFlags ( )
inline

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

Referenced by UFuncImgPoly::findAreaFromSeedRGB().

double UImagePoly::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 UImagePoly::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 UImagePoly::imageContourMaha ( UImage img,
UImage imgC,
unsigned int  row,
unsigned int  col,
UPixelLinked outlineBuffer,
int *  outlineBufferCnt,
UMatrix4 averageSeed,
UMatrix4 covarianceInv,
double  diff,
double  diffa 
)
bool UImagePoly::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 UImagePoly::imageUsable ( UImage img)
bool UImagePoly::makeSimilarImage2 ( UImage img,
unsigned int  x,
unsigned int  y,
unsigned int  w,
unsigned int  h,
int  imgPoolNum 
)

intended for YUV image with a seed area

Find road as area that matches this start area. using just 2 challels (UV part of YUV). Paint result in result image if in debug mode.

References UPixelLinked::c, UImage::copy(), UImage::copyMeta(), UMatrix::cvArr(), UImage::cvArr(), fire(), UImage::getLine(), UMatrix::getRow(), UImage::height(), UMatrix::inverse(), UPixel::p2, UPixel::p3, UPixelLinked::r, UMatrix::set(), and UImage::width().

Referenced by UFuncImgPoly::handleImgPolyCommand().

bool UImagePoly::makeSimilarImage3 ( UImage img,
unsigned int  x,
unsigned int  y,
unsigned int  w,
unsigned int  h,
UImage resultImg,
bool  debug,
int  imgNum,
char *  imgN 
)

Find road as area that matches this start area.

  • using all 3 color channels (assumed RGB) Paint result in result image if in debug mode.

References UPixelLinked::c, UImage::copy(), UImage::copyMeta(), UMatrix::cvArr(), UImage::cvArr(), fire(), UImage::getLine(), UImage::height(), imagePath, UPixel::p1, UPixel::p2, UPixel::p3, UPixelLinked::r, UImage::saveBMP(), UMatrix::set(), UImage::setSize(), and UImage::width().

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

Remove closed appendix areas

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

void UImagePoly::setImagePool ( UImagePool imagePool)
inline

Set image pool

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

Referenced by UFuncImgPoly::initializeFindPath().

void UImagePoly::setStorage ( CvMemStorage *  mem)
inline

Set storage pointer

References img.

Referenced by UFuncImgPoly::initializeFindPath().

Member Data Documentation

double UImagePoly::cromaTrace
private

Seed area cromaticity standard deviation

CvPoint* UImagePoly::floorArea
private

Array of CvPoint, that holds the the floor contour

int UImagePoly::floorAreaCnt
private

Number of points in contour

UPixelLinked* UImagePoly::floorOutline
private

Array of points and directions in floor outline

int UImagePoly::floorOutlineCnt
private

Count of elements in outline

UImagePool* UImagePoly::imgPool
private

Reference to image pool

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

Image to be analized Storage used by openCV


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