AURobotServers
4
|
#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 |
UCalibrationComponent * | grid [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) |
Class to hold calibration points found in an image
typedef sPos UCalibrationComponents::UsPos |
Temporary structure used when calculating center of gravity of cornetr position.
UCalibrationComponents::UCalibrationComponents | ( | ) |
Constructor
References clear().
|
private |
Fold the center mask with 2 blocks missing over found grid and Return score
References grid.
Referenced by DoFindCenterCross().
|
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().
|
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().
|
private |
Find candidate neighbors in 8 directions for one candidate.
References DoFindNSEWHead(), DoValidateCandidates(), and GetClosestItems().
|
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().
|
private |
Find the best candidate in a given direction from this list of up to 12 candidates.
References UCalibXYStat::clear(), UCalibBestArray::count, UCalibXYStat::d, UCalibBestArrayElement::d, UCalibrationComponent::GetDefaultOffset(), hits, UCalibXYStat::id, UCalibBestArrayElement::id, UCalibrationComponent::IsInRightQuadrant(), UCalibBestArray::items, UCalibrationComponent::NSEW, roundi(), sqr(), UCalibBestArrayElement::valid, UCalibXYStat::x, UCalibrationComponent::x, UCalibXYStat::y, and UCalibrationComponent::y.
Referenced by DoFindNSEW(), and DoRemoveAndRetry().
|
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 | ||
) |
Order hits from neighbors for a 2D barcode image detection
References UImage::cvArr(), UCalibXYStat::d, DoFindRowLength4(), UCalibXYStat::endId, hitCount, hits, UCalibXYStat::id, UCalibXYStat::n, NON_PARALLEL_FACTOR, UCalibrationComponent::NSEW, roundi(), sqr(), testForFlatness(), UCalibXYStat::vx, UCalibXYStat::vy, UCalibrationComponent::x, and UCalibrationComponent::y.
|
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.
|
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
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.
|
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().
|
private |
Find a list of close neighbors to this candidate and plase then in the best array.
References UCalibBestArray::AddCandidate(), UCalibBestArray::count, UCalibBestArrayElement::d, UCalibBestArray::DoLimitCandidates(), UCalibBestArrayElement::dx, UCalibBestArrayElement::dy, UCalibrationComponent::GetMaxBlockDist(), hitCount, hits, UCalibBestArrayElement::id, UCalibBestArray::items, and MAX_BEST_ARRAY_SIZE.
Referenced by DoFindNSEW(), and DoFindNSEW4().
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.
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.
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 | ) |
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.
|
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().
|
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().
|
private |
Test if the square formed by the 3 corners are too flat to be a usable square. Returns true if size is usable.
References absf(), U2Dline::distanceSigned(), U2Dline::set2P(), UCalibrationComponent::x, and UCalibrationComponent::y.
Referenced by doOrderHits4().
|
inline |
Save this message in logfile if significance is less than logLevel. Print also to console (debug feature) if verbose messages. Timestamp is optional, if not used, then Now() is used in logfile.
References dist, img, UCalibXYStat::n, toLogGmk(), UCalibXYStat::vx, and UCalibXYStat::vy.
Referenced by UCalibrationMarkSets::doEstimateCameraParameters(), UCalibrationMarkSets::doEstimateCameraParametersBinary(), UCalibrationMarkSets::doEstimateCameraParametersCarpet(), DoFindCenterCross(), doFindCodeValue(), UCalibrationMarkSet::evaluateChartPosRot(), UCalibrationMarkSets::evaluatek1PixError(), UCalibrationMarkSet::evaluatePosRot(), UCalibrate::findGmk(), UCalibrationMarkSet::info(), and UCalibrationMarkSet::saveMarksToFile().
int UCalibrationComponents::centC |
Referenced by DoFindCenterCross().
int UCalibrationComponents::centR |
center (5x5) or 1,1 cm (6x6) position
Referenced by DoFindCenterCross().
UCalibrationComponent* UCalibrationComponents::grid[MAX_CALIB_GRID_SIZE][MAX_CALIB_GRID_SIZE] |
hits ordered in grid
Referenced by CenterCrossScore55(), CenterCrossScore66(), DoFindCenterCross(), FindGridLimits(), PaintGridInImage(), SaveCalibCoordinates(), and SaveCalibPointsSquare().
int UCalibrationComponents::hitCount |
Number of used entries in 'hits[]'
Referenced by clear(), DoFindCenterCross(), doMergeNearHits(), doOrderHits4(), DoSizeLimit(), EnumerateCalibrationDetections(), EnumerateCalibrationDetections4(), findClosestNeighbors(), GetClosestItems(), Pack(), PaintChartInImage(), PaintHitsInImage(), and SaveAllHits().
UCalibrationComponent UCalibrationComponents::hits[MAX_CALIBRATION_COMPONENTS] |
List of calibration components
Referenced by clear(), DoFindCenterCross(), DoFindNSEW4(), DoFindNSEWHead(), DoFindRowLength4(), doMakeCodeGrid(), doMergeNearHits(), doOrderHits4(), DoRemoveAndRetry(), DoSizeLimit(), DoValidateCandidates(), EnumerateCalibrationDetections(), EnumerateCalibrationDetections4(), findClosestNeighbors(), findNextInThisDirection4(), GetClosestItems(), Pack(), PaintChartInImage(), PaintHitsInImage(), SaveAllHits(), SetRowColForNeighbors(), and SetRowColFromNeighbor().
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().
|
protected |
Grid of corner positions in a barcode frame grid
Referenced by doFindCodeCellIntensity(), doFindCodeValue(), doMakeCodeGrid(), and FindImagePosition().