AURobotServers  4
Classes | Public Types | Public Member Functions | Public Attributes | Protected Attributes | Private Member Functions | List of all members
UCalibrationComponents Class Reference

#include <ucalibrate.h>

Classes

struct  sPos
 

Public Types

typedef sPos UsPos
 

Public Member Functions

void clear ()
 
bool doFindCodeCellIntensity (int size, int sideFactor, UImage *source, int *borderIntensity, bool extraImages, UImage *destination, int codeNumber)
 
bool doFindCodeValue (int size, int sideFactor, int code[], int *codeLng, int maxCodeLng, unsigned long *intCode, bool debug, int splitIntensity, int *indexM, int *indexN)
 
bool doMakeCodeGrid (int k0, int k1, int k2, int k0dk1, int k0dk2, int k1dB, int k2dB, int size, int sideFactor, float stride, UCalibrationMarkSet *markSet, bool alignFrame, bool saveToFile)
 
int doMergeNearHits (float dist)
 
bool doOrderHits4 (int size, int *k0, int *k1, int *k2, int *k0dk1, int *k0dk2, int *k1dB, int *k2dB, bool extraImages, UImage *img, int pixFactor)
 
int DoSizeLimit (void)
 
bool EnumerateCalibrationDetections (UImage *cim, int connectivity)
 
bool EnumerateCalibrationDetections4 (UImage *cim, int connectivity)
 
bool findClosestNeighbors (float maxDistance, bool extraImages, UImage *source, UImage *destination)
 
int FindGridLimits ()
 
UCalibrationMark FindImagePosition (int sm, int sn)
 
int Pack ()
 
int PaintChartInImage (UImage *image, UPixel pix, UPosition *chartPos, UCamPar *cm, const char *matlabFilename)
 
int PaintGridInImage (UImage *image, UPixel pix)
 
int PaintHitsInImage (UImage *image, UPixel pix)
 
int SaveAllHits (char *filename)
 
int SaveCalibCoordinates (char *filename)
 
int SaveCalibPointsSquare (char *filename)
 
void toLog (const char *info, int significance, UTime *timestamp=NULL)
 
 UCalibrationComponents ()
 

Public Attributes

int centC
 
int centR
 
UCalibrationComponentgrid [MAX_CALIB_GRID_SIZE][MAX_CALIB_GRID_SIZE]
 
int hitCount
 
UCalibrationComponent hits [MAX_CALIBRATION_COMPONENTS]
 
int maskN
 
int maxC
 
int maxR
 

Protected Attributes

UsPos mCode [MAX_CELL_COUNT+MAX_CELL_FACTOR][MAX_CELL_COUNT+MAX_CELL_FACTOR]
 

Private Member Functions

int CenterCrossScore55 (int row, int col, bool inverse)
 
int CenterCrossScore66 (int row, int col)
 
int DoFindCenterCross (float strideL, float strideW)
 
void DoFindNSEW (int candidate)
 
bool DoFindNSEW4 (int candidate, float limit, FILE *fl=NULL)
 
void DoFindNSEWHead (int candidate, int head, UCalibBestArray *best)
 
int DoFindRowLength4 (int candidate, int *direction, int size)
 
void DoRemoveAndRetry (int candidate, int head, UCalibBestArray *best)
 
void DoValidateCandidates (int candidate, UCalibBestArray *best)
 
void findNextInThisDirection4 (int id, float dx, float dy, float dd, int *ID, float *vx, float *vy, int *n, int *next, int stopSize)
 
void GetClosestItems (int candidate, UCalibBestArray *best, float distanceLimitFactor, FILE *fl=NULL)
 
int SetRowColForNeighbors (int candidate)
 
int SetRowColFromNeighbor (int candidate)
 
bool testForFlatness (UCalibrationComponent *ht, UCalibrationComponent *ht1, UCalibrationComponent *ht2)
 

Detailed Description

Class to hold calibration points found in an image

Member Typedef Documentation

Temporary structure used when calculating center of gravity of cornetr position.

Constructor & Destructor Documentation

UCalibrationComponents::UCalibrationComponents ( )

Constructor

References clear().

Member Function Documentation

int UCalibrationComponents::CenterCrossScore55 ( int  row,
int  col,
bool  inverse 
)
private

Fold the center mask with 2 blocks missing over found grid and Return score

References grid.

Referenced by DoFindCenterCross().

int UCalibrationComponents::CenterCrossScore66 ( int  row,
int  col 
)
private

Fold the center mask with 4 blocks missing over found grid and Return score

References grid.

Referenced by DoFindCenterCross().

void UCalibrationComponents::clear ( void  )

Clear any existing components

References hitCount, hits, and MAX_CALIBRATION_COMPONENTS.

Referenced by UCalibrate::findGmk(), and UCalibrationComponents().

int UCalibrationComponents::DoFindCenterCross ( float  strideL,
float  strideW 
)
private

Look for center cross by folding a cross mask over grid area. Returns number of valid positions in grid, or -1 if no center was found. The candidates are then marked with position in grid relative to center of chart, using GRID_STRIDE spacing between markers in meters.

References centC, CenterCrossScore55(), CenterCrossScore66(), centR, UCalibrationComponent::col, grid, hitCount, hits, maskN, MAX_CALIB_GRID_SIZE, UCalibrationComponent::row, UCalibrationComponent::rx, UCalibrationComponent::ry, and toLog().

bool UCalibrationComponents::doFindCodeCellIntensity ( int  size,
int  sideFactor,
UImage source,
int *  borderIntensity,
bool  extraImages,
UImage destination,
int  codeNumber 
)

Find intensity value in each code grid cell. Source image is needed for average intensity along border. Paints result to 'destination' if 'extraImage' is true. Destination image is only needed if used. Returns true if successful.

References UPixel::asYUV(), UImage::cvArr(), UPixel::cvRGB(), UImage::getPix(), UImage::height(), UImage::inRange(), isWithinSquare(), maxf(), maxi(), mCode, minf(), mini(), UCalibrationComponents::sPos::n, PIX_PLANES_BGR, PIX_PLANES_RGB, roundi(), UPixel::set(), UImage::setPix(), UPixel::setRGBto(), UPixel::u, UCalibrationComponents::sPos::v, UPixel::v, UImage::width(), and UPixel::y.

bool UCalibrationComponents::doFindCodeValue ( int  size,
int  sideFactor,
int  code[],
int *  codeLng,
int  maxCodeLng,
unsigned long *  intCode,
bool  debug,
int  splitIntensity,
int *  indexM,
int *  indexN 
)

Extract barcode value to string. The size and side factor defines the barcode frame. The code is returned in the code[] array one (hex) number in each array element (up to 'maxCodeLng'). The last 8 code values are converted to a long integer (assumed 4 bytes) to be used for fast value. Returns true if code is captured.
The index corner has index (m='indexM',n='indexN') in the mCode[m][n] array (with pixel position mCode[m][n].x,mCode[m][n].y)

References getCellCode(), MAX_CELL_FACTOR, MAX_SIDE_LENGTH, mCode, and toLog().

void UCalibrationComponents::DoFindNSEW ( int  candidate)
private

Find candidate neighbors in 8 directions for one candidate.

References DoFindNSEWHead(), DoValidateCandidates(), and GetClosestItems().

bool UCalibrationComponents::DoFindNSEW4 ( int  candidate,
float  limit,
FILE *  fl = NULL 
)
private

Find up to 8 closest neighbors to this point all within the distance limit 'limit'. Returns true if at least one neighbor is found

References UCalibBestArray::count, UCalibXYStat::d, UCalibBestArrayElement::d, UCalibBestArrayElement::dx, UCalibBestArrayElement::dy, GetClosestItems(), hits, UCalibXYStat::id, UCalibBestArrayElement::id, UCalibBestArray::items, UCalibrationComponent::NSEW, UCalibXYStat::x, and UCalibXYStat::y.

Referenced by findClosestNeighbors().

void UCalibrationComponents::DoFindNSEWHead ( int  candidate,
int  head,
UCalibBestArray best 
)
private
int UCalibrationComponents::DoFindRowLength4 ( int  candidate,
int *  direction,
int  size 
)
private

Find length and number of hops for this corner point. Explores direction to all neighbors, and stores distance and number of hops in the NSEW part of the structure.

References UCalibXYStat::d, UCalibXYStat::endId, findNextInThisDirection4(), hits, UCalibXYStat::id, MAX_CALIBRATION_COMPONENTS, UCalibXYStat::n, UCalibrationComponent::NSEW, UCalibXYStat::vx, UCalibXYStat::vy, UCalibXYStat::x, and UCalibXYStat::y.

Referenced by doOrderHits4().

bool UCalibrationComponents::doMakeCodeGrid ( int  k0,
int  k1,
int  k2,
int  k0dk1,
int  k0dk2,
int  k1dB,
int  k2dB,
int  size,
int  sideFactor,
float  stride,
UCalibrationMarkSet markSet,
bool  alignFrame,
bool  saveToFile 
)

Finds grid positions ordered from the 3 cornerpoints ht, ht1, ht2, and the 4 direction direction statistics htT0k1, htTok2, k1ToB, ht2ToB. The positions are saved as a 'UCalibrationMarkSet' with corresponding chart positions and pixel positions. If 'alignFrame' is true then the pixel positions are moved to be on a straight line with the other on the same frame side. Returns true if successful.

References UCalibXYStat::d, findNextInThisDirection4(), U2Dline::getCrossing(), U2Dline::getOnLine(), hits, UCalibXYStat::id, MAX_SIDE_LENGTH, mCode, UCalibrationComponent::NSEW, UCalibrationComponents::sPos::px, UCalibrationComponents::sPos::py, U2Dline::set(), U2Dline::set2P(), UCalibrationMarkSet::setFramePositions(), UCalibXYStat::x, UCalibrationComponent::x, UCalibXYStat::y, and UCalibrationComponent::y.

int UCalibrationComponents::doMergeNearHits ( float  dist)

Test for loose components at the edge of others, and merge components if centers are within 'Dist' pixels. Returns number if valid components (<= HitCount)

References absf(), hitCount, hits, UCalibrationComponent::w, UCalibrationComponent::x, and UCalibrationComponent::y.

bool UCalibrationComponents::doOrderHits4 ( int  size,
int *  k0,
int *  k1,
int *  k2,
int *  k0dk1,
int *  k0dk2,
int *  k1dB,
int *  k2dB,
bool  extraImages,
UImage img,
int  pixFactor 
)
void UCalibrationComponents::DoRemoveAndRetry ( int  candidate,
int  head,
UCalibBestArray best 
)
private

An invalid neighbor candidate is found, so remove it and try to find a new. Used by DoValidateCandidates only.

References UCalibBestArray::count, DoFindNSEWHead(), hits, UCalibXYStat::id, UCalibBestArrayElement::id, UCalibBestArray::items, UCalibrationComponent::NSEW, and UCalibBestArrayElement::valid.

Referenced by DoValidateCandidates().

int UCalibrationComponents::DoSizeLimit ( void  )

In many cases some background elements looks like corners but most will be smaller or bigger than the desired ones, so remove all outside +/- 2 standard deviations (plus a bit) of all corners. Returns number of corners left.

References absf(), hitCount, hits, sqr(), and UCalibrationComponent::w.

void UCalibrationComponents::DoValidateCandidates ( int  candidate,
UCalibBestArray best 
)
private

Validate that candidate in each heading is in the right direction.

References UCalibXYStat::d, DoRemoveAndRetry(), hits, UCalibXYStat::id, UCalibrationComponent::NSEW, UCalibXYStat::x, and UCalibXYStat::y.

Referenced by DoFindNSEW().

bool UCalibrationComponents::EnumerateCalibrationDetections ( UImage cim,
int  connectivity 
)

Enumereate pixels in an image with intensity > 0. The method combines pixels using a connectivity of either 'connectivity' = 4, 8, 12 or 20. Each separate component are numbered and added to the component array. returns true cim is an image.

References UImage::getPixRef(), UImage::height(), hitCount, hits, MAX_CALIBRATION_COMPONENTS, MAX_IMAGE_HEIGHT, MAX_IMAGE_WIDTH, UCalibrationComponent::w, UImage::width(), UCalibrationComponent::x, UCalibrationComponent::y, and UPixel::y.

bool UCalibrationComponents::EnumerateCalibrationDetections4 ( UImage cim,
int  connectivity 
)

Enumereate pixels in an image with intensity > 0. Each of the 2x2 quadrants are treaded seperately, i.e. not combined with corner of opposite type. The method combines pixels using a connectivity of either 'connectivity' = 4, 8, 12 or 20. Each separate component are numbered and added to the component array. returns true cim is an image.

References dist, UCalibrationComponent::filter, UImage::getPixRef(), UImage::height(), hitCount, hits, MAX_CALIBRATION_COMPONENTS, MAX_IMAGE_HEIGHT, MAX_IMAGE_WIDTH, UPixel::u, UPixel::v, UCalibrationComponent::w, UImage::width(), UCalibrationComponent::x, UCalibrationComponent::y, and UPixel::y.

bool UCalibrationComponents::findClosestNeighbors ( float  maxDistance,
bool  extraImages,
UImage source,
UImage destination 
)

This routine validates and orders the found cornerpoints assumed to be within the test following pattern 1 2 3 4 5 6 7 8 9 (9 cols x 11 rows - 8 = 91 corners) x x x x x x x x x 1 x x x x x x x x x 2 x x x x x x x x x 3 x x x x x x x 4 x x x x x x x 5 Painted on A4 with x x x x x x x x x 6 2cm between corners x x x x x x x 7 center pattern x x x x x x x 8 used for x x x x o o x x x 9 edge detection x x x x o o x x x 10 x x x x x x x x x 11 Method

  • first find candidate neighbors in 8 directions this will fail at edges, where some directions will find a wrong candidate
  • Check for direction of neighbors and fix
  • Renumber remaining candidates in a row-column grid starting with a candidate with 8 neighbors, and trust primarily neighbors with 8 or 7 neighbors for continued numbering edge candidates will only be numbered from a 7 or 8 neighbor candidate. Unnumbered candidates will be dropped.
  • Check that numbering is consistent.
  • Find center pattern and renumber to correct row and column. Adds corner position oncalibration chart to data set (using 'stride') Returns number of corners. Find nearest neighbors for barcode detection. The neighbors must be nearer than 'maxDistance' (in pixels). If 'extraImages' is true, then neighbor lines gets drawn in 'destination' image in top of a faded copy of 'source' image. Returns true if at least one neighbor is found.

References DoFindNSEW4(), UImage::height(), hitCount, hits, Pack(), UCalibrationComponent::PaintNeighbors(), PIX_PLANES_RGB, and UPixel::setRGBto().

int UCalibrationComponents::FindGridLimits ( )

Find maxR and maxC as limits for grid positions.

References grid, MAX_CALIB_GRID_SIZE, maxC, and maxR.

Referenced by SaveCalibCoordinates(), and SaveCalibPointsSquare().

UCalibrationMark UCalibrationComponents::FindImagePosition ( int  sm,
int  sn 
)

Find position in image using coordinates in found grid. Returns found positions in ix and iy, but not the corresponding position in chart coorfinates returns 0 if succesfull, and -1 if not.

References UCalibrationMark::col, UCalibrationMark::ix, UCalibrationMark::iy, mCode, UCalibrationComponents::sPos::px, UCalibrationComponents::sPos::py, and UCalibrationMark::row.

void UCalibrationComponents::findNextInThisDirection4 ( int  id,
float  dx,
float  dy,
float  dd,
int *  ID,
float *  vx,
float *  vy,
int *  n,
int *  next,
int  stopSize 
)
private

Search if candidate 'id' has a neighbor, in distance 'dd' and dirextion 'dx', 'dy' - all within 1/4 of 'dd' margin. If so increase hop-count 'n' and total distance 'vx' and 'vy'. Function is called recursively. Stop recursion, when n has reached 'stopSize'.

References UCalibXYStat::d, hits, UCalibXYStat::id, UCalibrationComponent::NSEW, sqr(), UCalibXYStat::x, and UCalibXYStat::y.

Referenced by DoFindRowLength4(), and doMakeCodeGrid().

void UCalibrationComponents::GetClosestItems ( int  candidate,
UCalibBestArray best,
float  distanceLimitFactor,
FILE *  fl = NULL 
)
private
int UCalibrationComponents::Pack ( )

Pack components, so that any non valid (w==0) ones are removed

References hitCount, and hits.

Referenced by findClosestNeighbors().

int UCalibrationComponents::PaintChartInImage ( UImage image,
UPixel  pix,
UPosition chartPos,
UCamPar cm,
const char *  matlabFilename 
)

Paint real chart positions in image where they should be if calibration was OK. Saves corner positions to in matlab format if matlabFilename != NULL. Return 0.

References UImage::cvArr(), UPixel::cvRGB(), UMatrix::expand(), UMatrix::get(), UCamPar::getItoP(), hitCount, hits, UMatrix::normalize(), roundi(), UCalibrationComponent::ry, UMatrix::set(), UPosition::x, UPosition::y, and UPosition::z.

int UCalibrationComponents::PaintGridInImage ( UImage image,
UPixel  pix 
)

Paints components in grid[row][col] array on this image using the color in pix. Pix is in YUV format
Paint in lines connecting rows and cols when consecutive Returns 0.

References UImage::cvArr(), UPixel::cvRGB(), grid, MAX_CALIB_GRID_SIZE, PIX_PLANES_RGB, roundi(), UPixel::setRGBto(), UCalibrationComponent::x, and UCalibrationComponent::y.

int UCalibrationComponents::PaintHitsInImage ( UImage image,
UPixel  pix 
)

Paints components in hits[] array on this image using the base color in pix. Pix is in YUV format, and intensity are set from weight (hits[].w).
Returns 0.

References UImage::cvArr(), UPixel::cvRGB(), hitCount, hits, mini(), and UPixel::y.

int UCalibrationComponents::SaveAllHits ( char *  filename)

Save selected hit information to file

References hitCount, and hits.

int UCalibrationComponents::SaveCalibCoordinates ( char *  filename)

Save calibration coordinates in MATLAB format, as needed by camera calibratution routine: p = [chart x (left), y (up), z (0.0), image col (left), row (down), 0, 0, 1; ...];
...
chart x (left), y (up), z (0.0), image col (left), row (down), 0, 0, 1];
filename should end on '.m', as a MATLAB file. Returns 0 if OK, else -1.

References FindGridLimits(), grid, maxC, maxR, UCalibrationComponent::rx, UCalibrationComponent::ry, UCalibrationComponent::x, and UCalibrationComponent::y.

int UCalibrationComponents::SaveCalibPointsSquare ( char *  filename)

Save grid coordinates to a file for verification of correct numbering ('txt' file).

References FindGridLimits(), grid, maxC, and maxR.

int UCalibrationComponents::SetRowColForNeighbors ( int  candidate)
private

Set row and column for all neighbors without one, assuming this candidate has a number. Continues numbering using breast first and setting the numbers using 'SetRowColFromNeighbor(n)' to ensure best consistency, when there is conflicts. Returns 0.

References hits, UCalibXYStat::id, MAX_CALIBRATION_COMPONENTS, UCalibrationComponent::NSEW, and SetRowColFromNeighbor().

int UCalibrationComponents::SetRowColFromNeighbor ( int  candidate)
private

Give this item a row/col number based on neighbor oppinion

References UCalibrationComponent::col, hits, UCalibXYStat::id, UCalibrationComponent::NSEW, UCalibrationComponent::row, and UCalibrationComponent::SetRc().

Referenced by SetRowColForNeighbors().

bool UCalibrationComponents::testForFlatness ( UCalibrationComponent ht,
UCalibrationComponent ht1,
UCalibrationComponent ht2 
)
private

Test if the square formed by the 3 corners are too flat to be a usable square. Returns true if size is usable.

Todo:
There should be a parameter to decide what is usable, but for now a fixed value of 14 pixels wide is used.

References absf(), U2Dline::distanceSigned(), U2Dline::set2P(), UCalibrationComponent::x, and UCalibrationComponent::y.

Referenced by doOrderHits4().

void UCalibrationComponents::toLog ( const char *  info,
int  significance,
UTime timestamp = NULL 
)
inline

Member Data Documentation

int UCalibrationComponents::centC

Referenced by DoFindCenterCross().

int UCalibrationComponents::centR

center (5x5) or 1,1 cm (6x6) position

Referenced by DoFindCenterCross().

int UCalibrationComponents::hitCount
UCalibrationComponent UCalibrationComponents::hits[MAX_CALIBRATION_COMPONENTS]
int UCalibrationComponents::maskN

found mask: 0 = 6x6, 1= 5x5 portrait, 2= 5x5 landscape

Referenced by DoFindCenterCross().

int UCalibrationComponents::maxC

Max column when grid is filled. -1 if not found

Referenced by FindGridLimits(), SaveCalibCoordinates(), and SaveCalibPointsSquare().

int UCalibrationComponents::maxR

Max rov when grid is filled. -1 if not found

Referenced by FindGridLimits(), SaveCalibCoordinates(), and SaveCalibPointsSquare().

UsPos UCalibrationComponents::mCode[MAX_CELL_COUNT+MAX_CELL_FACTOR][MAX_CELL_COUNT+MAX_CELL_FACTOR]
protected

Grid of corner positions in a barcode frame grid

Referenced by doFindCodeCellIntensity(), doFindCodeValue(), doMakeCodeGrid(), and FindImagePosition().


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