AURobotServers
4
|
#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) |
UPixel * | pixSort (UPixel ***ps, int pixCnt) |
Private Attributes | |
double | cromaTrace |
CvPoint * | floorArea |
int | floorAreaCnt |
UPixelLinked * | floorOutline |
int | floorOutlineCnt |
UImagePool * | imgPool |
bool * | obst |
CvMemStorage * | storage |
Class for image analysis. Initially color statistics only.
UImagePoly::UImagePoly | ( | ) |
Constructor
UImagePoly::~UImagePoly | ( | ) |
Destructor
|
private |
Count edges in contour sequebnce
|
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.
|
private |
Filter image based on row number
References UPixelLinked::c, UImage::copy(), UImage::getLine(), UPixelLinked::r, and UImage::width().
|
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().
|
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
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().
|
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().
|
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().
|
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().
|
inline |
Get the cromaticity SD from the seed area.
Referenced by UFuncImgPoly::findAreaFromSeedRGB().
|
inline |
Get estimated floor polygon
Referenced by UFuncImgPoly::findAreaFromSeedRGB().
|
inline |
Get number of vertexes in floor polygon .
Referenced by UFuncImgPoly::findAreaFromSeedRGB().
|
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
|
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().
|
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.
|
inline |
Get boolean flag array to indicate that the vertex is part of an obstacle.
Referenced by UFuncImgPoly::findAreaFromSeedRGB().
|
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 | ||
) |
Same as above, but using Mahalonobis distance
References 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::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 | ) |
Test image for illumination sanity Returns true if statistics seems OK
References UPixelLinked::c, UImage::getPix(), UImage::height(), UImage::isValid(), UImage::isYUV(), UImage::isYUV420(), UPixel::p1, UPixel::p2, UPixel::p3, UPixelLinked::px, UPixelLinked::r, UImage::width(), and UPixel::y.
Referenced by UFuncImgPoly::findAreaFromSeedRGB().
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.
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().
|
private |
Paint base image with road detection
References UPixelLinked::c, UMatrix::copy(), UImage::height(), UPixelLinked::r, and UImage::width().
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.
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.
|
inline |
Set image pool
References UPixelLinked::c, and UPixelLinked::r.
Referenced by UFuncImgPoly::initializeFindPath().
|
inline |
|
private |
Seed area cromaticity standard deviation
|
private |
Array of CvPoint, that holds the the floor contour
|
private |
Number of points in contour
|
private |
Array of points and directions in floor outline
|
private |
Count of elements in outline
|
private |
Reference to image pool
|
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.
|
private |
Image to be analized Storage used by openCV