本文整理汇总了C++中Blob::getLeftTopX方法的典型用法代码示例。如果您正苦于以下问题:C++ Blob::getLeftTopX方法的具体用法?C++ Blob::getLeftTopX怎么用?C++ Blob::getLeftTopX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Blob
的用法示例。
在下文中一共展示了Blob::getLeftTopX方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
/* As part of our roundness checking we scan the midlines of the blob.
In principle every pixel should be the right color.
@param b candidate blob
@return a pair containing the number of good and bad pixels
*/
pair<int, int> Ball::scanMidlinesForRoundnessInformation(Blob b) {
int w = b.width();
int h = b.height();
int x = b.getLeftTopX();
int y = b.getLeftTopY();
int pix;
int goodPix = 0, badPix = 0;
for (int i = 0; i < h; i++) {
pix = thresh->getThresholded(y+i,x + w/2);
if (pix == ORANGE || pix == ORANGERED || pix == ORANGEYELLOW) {
goodPix++;
} else if (pix != GREY)
badPix++;
}
for (int i = 0; i < w; i++) {
pix = thresh->getThresholded(y+h/2,x + i);
if (pix == ORANGE || pix == ORANGERED || pix == ORANGEYELLOW) {
goodPix++;
} else if (pix != GREY) {
badPix++;
}
}
pair<int, int> info;
info.first = goodPix;
info.second = badPix;
return info;
}
示例2: checkSizeAgainstPixEstimate
/* Returns whether true when the size of the cross is reasonable when tested
against the pixEstimated distance.
@param b the candidate cross
@return if the size is reasonable
*/
bool Cross::checkSizeAgainstPixEstimate(Blob b) {
int x = b.getLeftTopX();
int y = b.getLeftTopY();
int w = b.width();
int h = b.height();
// before we spend a lot of time processing, let's see if it is a reasonable size
if (w > 3 * h || h > 2 * w) {
return false;
}
estimate e = vision->pose->pixEstimate(x, y, 0.0);
if (CROSSDEBUG) {
cout << "Distance check: " << e.dist << " " << w << endl;
}
if (e.dist < 100.0f && w < 20) {
return false;
} else if (e.dist < 150.0f && w < 12) {
return false;
} else if (e.dist < 200.0f && w < 8) {
return false;
}
if (e.dist > 200.0f && w > 20) {
return false;
}
return true;
}
示例3: drawBlob
/* Draws the outline of a blob in the specified color.
* @param b the blob
* @param c the color to paint
*/
void Ball::drawBlob(Blob b, int c) {
#ifdef OFFLINE
thresh->drawLine(b.getLeftTopX(), b.getLeftTopY(),
b.getRightTopX(), b.getRightTopY(),
c);
thresh->drawLine(b.getLeftTopX(), b.getLeftTopY(),
b.getLeftBottomX(), b.getLeftBottomY(),
c);
thresh->drawLine(b.getLeftBottomX(), b.getLeftBottomY(),
b.getRightBottomX(), b.getRightBottomY(),
c);
thresh->drawLine(b.getRightTopX(), b.getRightTopY(),
b.getRightBottomX(), b.getRightBottomY(),
c);
#endif
}
示例4: rightBlobColor
/* Checks out how much of the blob is of the right color.
* If it is enough returns true, if not false.
* @param tempobj the blob we're checking (usually a post)
* @param minpercent how good it needs to be
* @return was it good enough?
*/
bool Ball::rightBlobColor(Blob tempobj, float minpercent) {
int x = tempobj.getLeftTopX();
int y = tempobj.getLeftTopY();
int spanX = tempobj.width();
int spanY = tempobj.height();
if (spanX < 2 || spanY < 2) return false;
int ny, nx, starty, startx;
int good = 0, total = 0;
for (int i = 0; i < spanY; i++) {
starty = y + i;
startx = x;
for (int j = 0; j < spanX; j++) {
nx = startx + j;
ny = starty;
if (ny > -1 && nx > -1 && ny < IMAGE_HEIGHT && nx < IMAGE_WIDTH) {
total++;
if (thresh->thresholded[ny][nx] == color) {
good++;
}
}
}
}
float percent = (float)good / (float) (total);
if (percent > minpercent) {
return true;
}
return false;
}
示例5: checkForLineIntersection
/* Determines if a line intersects the candidate cross, if so it
is thrown out.
@param b the candidate cross
@return whether a line intersects
*/
bool Cross::checkForLineIntersection(Blob b) {
int x = b.getLeftTopX();
int y = b.getLeftTopY();
int w = b.width();
int h = b.height();
point <int> plumbLineTop, plumbLineBottom, line1start, line1end;
plumbLineTop.x = x + w / 2; plumbLineTop.y = y;
plumbLineBottom.x = x; plumbLineBottom.y = y + h;
const vector <boost::shared_ptr<VisualLine> >* lines =
vision->fieldLines->getLines();
for (vector <boost::shared_ptr<VisualLine> >::const_iterator k =
lines->begin();
k != lines->end(); k++) {
pair<int, int> foo = Utility::plumbIntersection(plumbLineTop,
plumbLineBottom,
(*k)->getStartpoint(),
(*k)->getEndpoint());
if (foo.first != Utility::NO_INTERSECTION && foo.second !=
Utility::NO_INTERSECTION) {
if (CROSSDEBUG)
cout << "Throwing out blob that is part of a line" << endl;
return true;
}
}
return false;
}
示例6: printBlob
/* Print debugging information for a blob.
* @param b the blob
*/
void Ball::printBlob(Blob b) {
#if defined OFFLINE
cout << "Blob Top Left Corner " << b.getLeftTopX() << " " << b.getLeftTopY()
<< endl;
cout << "Width/height " << b.width() << " " << b.height();
cout << " Amount of orange " << b.getPixels() << endl;
#endif
}
示例7: scanAroundPerimeter
/* Scans around the outside of the blob looking for green. Ideally the
cross will have only green around it. White is a big problem, so is
having the cross near the edge. This is because our version of the
cross is so simple - we don't look at its shape at all! Instead we
just look for white blobs with the right general properties.
@param b the candidate cross
@return the amount of green in the perimeter (white gives a huge
negative penalty)
*/
bool Cross::scanAroundPerimeter(Blob b) {
const float greenThreshold = 0.75f;
int x = b.getLeftTopX();
int y = b.getLeftTopY();
int w = b.width();
int h = b.height();
int counter = 0, count = 0;
// first scan the sides
for (int i = max(0, y - 2); i < min(IMAGE_HEIGHT - 1, y + h + 2); i++) {
if (x > 3) {
if (Utility::isGreen(thresh->getThresholded(i,x - 4))) {
count++;
} else if (Utility::isWhite(thresh->getThresholded(i,x - 4))) {
count-=3;
}
counter++;
} else return false;
if (x + w + 4 < IMAGE_WIDTH) {
if (Utility::isGreen(thresh->getThresholded(i,x + w+ 4))) {
count++;
} else if (Utility::isWhite(thresh->getThresholded(i,x + w+ 4))) {
count-=3;
}
counter++;
} else return false;
}
// now scan above and below
for (int i = max(0, x - 2); i < min(IMAGE_WIDTH - 1, x + w + 2); i++) {
if (y > 1) {
if (Utility::isGreen(thresh->getThresholded(y - 2,i))) {
count++;
} else if (Utility::isUndefined(thresh->getThresholded(y - 2,i))) {
count--;
} else if (Utility::isWhite(thresh->getThresholded(y - 2,i))) {
count-=3;
}
counter++;
} else return false;
if (y + h + 2 < IMAGE_HEIGHT) {
if (Utility::isGreen(thresh->getThresholded(y+h+2,i))) {
count++;
} else if (Utility::isWhite(thresh->getThresholded(y+h+2,i))) {
count-=3;
}
counter++;
} else return false;
}
if (count > (float)counter * greenThreshold) {
if (CROSSDEBUG) {
cout << "White stats: " << count << " " << counter << endl;
}
return true;
}
return false;
}
示例8: printBlob
/* Print debugging information for a blob.
* @param b the blob
*/
void Robots::printBlob(Blob b) {
#if defined OFFLINE
cout << "Outputting blob" << endl;
cout << b.getLeftTopX() << " " << b.getLeftTopY() << " " << b.getRightTopX() << " "
<< b.getRightTopY() << endl;
cout << b.getLeftBottomX() << " " << b.getLeftBottomY() << " " << b.getRightBottomX()
<< " " << b.getRightBottomY() << endl;
#endif
}
示例9: updateRobot
/**
* Update the robot values from the blob
*
* @param b The blob to update our object from.
*/
void VisualRobot::updateRobot(Blob b)
{
setLeftTopX(b.getLeftTopX());
setLeftTopY(b.getLeftTopY());
setLeftBottomX(b.getLeftBottomX());
setLeftBottomY(b.getLeftBottomY());
setRightTopX(b.getRightTopX());
setRightTopY(b.getRightTopY());
setRightBottomX(b.getRightBottomX());
setRightBottomY(b.getRightBottomY());
setX(b.getLeftTopX());
setY(b.getLeftTopY());
setWidth(dist(b.getRightTopX(), b.getRightTopY(), b.getLeftTopX(),
b.getLeftTopY()));
setHeight(dist(b.getLeftTopX(), b.getLeftTopY(), b.getLeftBottomX(),
b.getLeftBottomY()));
setCenterX(getLeftTopX() + ROUND2(getWidth() / 2));
setCenterY(getRightTopY() + ROUND2(getHeight() / 2));
setDistance(1);
}
示例10: rightHalfColor
// only called on really big orange blobs
float Ball::rightHalfColor(Blob tempobj)
{
const float COLOR_THRESH = 0.15f;
const float POOR_VALUE = 0.10f;
int x = tempobj.getLeftTopX();
int y = tempobj.getLeftTopY();
int spanY = tempobj.height() - 1;
int spanX = tempobj.width() - 1;
int good = 0, good1 = 0, good2 = 0;
int pix;
if (rightColor(tempobj, ORANGE) < COLOR_THRESH) return POOR_VALUE;
for (int i = spanY / 2; i < spanY; i++) {
for (int j = 0; j < spanX; j++) {
pix = thresh->thresholded[y + i][x + j];
if (y + i > -1 && x + j > -1 && (y + i) < IMAGE_HEIGHT &&
x + j < IMAGE_WIDTH && (pix == ORANGE || pix == ORANGERED ||
pix == ORANGEYELLOW)) {
good++;
}
}
}
for (int i = 0; i < spanY; i++) {
for (int j = 0; j < spanX / 2; j++) {
pix = thresh->thresholded[y + i][x + j];
if (y + i > -1 && x + j > -1 && (y + i) < IMAGE_HEIGHT &&
x + j < IMAGE_WIDTH && (pix == ORANGE || pix == ORANGERED ||
pix == ORANGEYELLOW)) {
good1++;
}
}
}
for (int i = 0; i < spanY; i++) {
for (int j = spanX / 2; j < spanX; j++) {
pix = thresh->thresholded[y + i][x + j];
if (y + i > -1 && x + j > -1 && (y + i) < IMAGE_HEIGHT &&
x + j < IMAGE_WIDTH && (pix == ORANGE || pix == ORANGERED ||
pix == ORANGEYELLOW)) {
good2++;
}
}
}
if (BALLDEBUG) {
cout << "Checking half color " << good << " " << good1 << " " <<
good2 << " " << (spanX * spanY / 2) << endl;
}
float percent = (float)max(max(good, good1), good2) /
(float) (spanX * spanY / 2);
return percent;
}
示例11: min
/* As part of roundness checking we scan the diagonals of the blob.
We know that there is a predictible transition point from no ball
to ball and categorize each pixel accordingly
@param b the blob
@return a pair containing the number of good pixels, and bad ones
*/
pair<int, int> Ball::scanDiagonalsForRoundnessInformation(Blob b) {
const float CORNER_CHUNK_DIV = 6.0f;
int w = b.width();
int h = b.height();
int x = b.getLeftTopX();
int y = b.getLeftTopY();
int pix;
int goodPix = 0, badPix = 0;
int d = ROUND2(static_cast<float>(std::max(w, h)) /
CORNER_CHUNK_DIV);
int d3 = min(w, h);
pair<int, int> info;
for (int i = 0; i < d3; i++) {
pix = thresh->getThresholded(y+i,x+i);
if (i < d || (i > d3 - d)) {
if (pix == ORANGE || pix == ORANGERED) {
//drawPoint(x+i, y+i, BLACK);
badPix++;
} else {
goodPix++;
}
} else {
if (pix == ORANGE || pix == ORANGERED || pix == ORANGEYELLOW) {
goodPix++;
} else if (pix != GREY) {
badPix++;
//drawPoint(x+i, y+i, PINK);
}
}
pix = thresh->getThresholded(y+i,x+w-i);
if (i < d || (i > d3 - d)) {
if (pix == ORANGE || pix == ORANGERED) {
//drawPoint(x+w-i, y+i, BLACK);
badPix++;
}
else {
goodPix++;
}
} else if (pix == ORANGE || pix == ORANGERED ||
pix == ORANGEYELLOW) {
goodPix++;
} else if (pix != GREY) {
badPix++;
}
}
info.first = goodPix;
info.second = badPix;
return info;
}
示例12: printBall
/* Prints a bunch of ball information about the best ball candidate (or any one).
* @param b the candidate ball
* @param c how confident we are its a ball
* @param p how many occlusions
* @param o what the occlusions are if any
* @param bg where around the ball there is green
*/
void Ball::printBall(Blob b, int c, float p, int o) {
#ifdef OFFLINE
if (BALLDEBUG) {
cout << "Ball info: " << b.getLeftTopX() << " " << b.getLeftTopY()
<< " " << b.width() << " " << b.height() << endl;
cout << "Confidence: " << c << " Orange Percent: " << p
<< " Occlusions: ";
if (o == NOOCCLUSION) cout << "none";
if (o % LEFTOCCLUSION == 0) cout << "left ";
if (o % RIGHTOCCLUSION == 0) cout << "right ";
if (o % TOPOCCLUSION == 0) cout << "top ";
if (o % BOTTOMOCCLUSION == 0) cout << "bottom ";
cout << endl;
}
#endif
}
示例13: ballNearGreen
int Ball::ballNearGreen(Blob b)
{
const int EXTRA_LINES = 6;
// first check the bottom
int w = b.width();
int h = b.height();
int where = NOGREEN;
if (greenCheck(b))
where = where * GREENBELOW;
// now try the sides - happily the ball is round so we don't have to worry
// about scan angles
int x = b.getLeftTopX();
int y = b.getLeftTopY();
for (int i = 0; i < h && y + i < IMAGE_HEIGHT && where % GREENLEFT != 0;
i= i+2) {
for (int j =-1; j < EXTRA_LINES && x + j > -1 && where % GREENLEFT != 0;
j++) {
if (thresh->thresholded[i+y][x - j] == GREEN) {
where = where * GREENLEFT;
}
}
}
for (int i = 0; i < w && x + i < IMAGE_WIDTH && where % GREENABOVE != 0;
i= i+2) {
for (int j = 0; j < EXTRA_LINES && y - j > 0 && where % GREENABOVE != 0;
j++) {
if (thresh->thresholded[i+y][j+x] == GREEN) {
where = where * GREENABOVE;
}
}
}
x = b.getRightTopX();
y = b.getRightTopY();
for (int i = 0; i < h && y + i < IMAGE_HEIGHT && where % GREENRIGHT != 0;
i= i+2) {
for (int j = 0; j < EXTRA_LINES && x + j < IMAGE_WIDTH &&
where % GREENRIGHT != 0; j++) {
if (thresh->thresholded[i+y][j+x] == GREEN) {
where = where * GREENRIGHT;
}
}
}
// put in the case where we don't have any, but want to check the corners
return where;
}
示例14: blobOk
/* When we process blobs we start them with BAD_VALUE such that we can easily
* tell if whatever processing we did worked out. Here we make that check.
* @param b the blob we worked on.
* @return true when the processing worked, false otherwise
*/
bool Ball::blobOk(Blob b) {
if (b.getLeftTopX() > BAD_VALUE && b.getLeftBottomX() > BAD_VALUE &&
b.width() > 2)
return true;
return false;
}
示例15: rightColor
float Ball::rightColor(Blob tempobj, int col)
{
const int MIN_BLOB_SIZE = 1000;
const float RED_PERCENT = 0.10f;
const float ORANGE_PERCENT = 0.20f;
const float ORANGEYELLOW_PERCENT = 0.40f;
const float GOOD_PERCENT = 0.65f;
int x = tempobj.getLeftTopX();
int y = tempobj.getLeftTopY();
int spanY = tempobj.height();
int spanX = tempobj.width();
if (spanX < 2 || spanY < 2) return false;
int good = 0;
int ogood = 0;
int orgood = 0;
int oygood = 0;
int red = 0;
for (int i = 0; i < spanY; i++) {
for (int j = 0; j < spanX; j++) {
int pix = thresh->thresholded[y + i][x + j];
if (y + i > -1 && x + j > -1 && (y + i) < IMAGE_HEIGHT &&
x + j < IMAGE_WIDTH && (pix == ORANGE || pix == ORANGERED ||
pix == ORANGEYELLOW)) {
good++;
if (pix == ORANGE)
ogood++;
else if (pix == ORANGEYELLOW)
oygood++;
else
orgood++;
} else if (pix == RED)
red++;
}
}
// here's a big hack - if we have a ton of orange, let's say it is enough
// unless the percentage is really low
if (BALLDEBUG) {
cout << "Orange " << ogood << " " << orgood << " " << red << " "
<< tempobj.getArea() << endl;
}
if (tempobj.getArea() > MIN_BLOB_SIZE) return (float) good /
(float) tempobj.getArea();
//if (ogood < 2 * orgood) return 0.1; // at least two thirds of the "orange"
// pixels should be orange
if (red > static_cast<float>(spanX * spanY) * RED_PERCENT) {
if (BALLDEBUG)
cout << "Too much red" << endl;
// before giving up let's try and salvage this one
if (ogood < static_cast<float>(spanX * spanY) * ORANGE_PERCENT)
return RED_PERCENT;
if (greenCheck(tempobj) && greenSide(tempobj) && roundness(tempobj) !=
BAD_VALUE) {
return GOOD_PERCENT;
}
return RED_PERCENT;
}
/*if (ogood < static_cast<float>(spanX * spanY) * ORANGE_PERCENT) {
if (BALLDEBUG)
cout << "Not enough pure orange" << endl;
return RED_PERCENT;
}*/
if (tempobj.getArea() > MIN_BLOB_SIZE &&
ogood + oygood > (static_cast<float>(spanX * spanY) * ORANGEYELLOW_PERCENT)
&& good < ( static_cast<float>(spanX * spanY) * GOOD_PERCENT))
return GOOD_PERCENT;
float percent = (float)good / (float) (spanX * spanY);
if (col == GREEN)
return (float)good;
return percent;
}