本文整理汇总了C++中BinaryImage类的典型用法代码示例。如果您正苦于以下问题:C++ BinaryImage类的具体用法?C++ BinaryImage怎么用?C++ BinaryImage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BinaryImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OperatorControl
/**
* Runs the motors with arcade steering.
*/
void OperatorControl(void)
{
HSLImage *Himage;
Threshold targetThreshold(247, 255, 60, 140, 10, 50);
BinaryImage *matchingPixels;
vector<ParticleAnalysisReport> *pReport;
//myRobot->SetSafetyEnabled(true);
Saftey->SetEnabled(false);
AxisCamera &mycam = AxisCamera::GetInstance("10.15.10.11");
mycam.WriteResolution(AxisCamera::kResolution_640x480);
mycam.WriteCompression(20);
mycam.WriteBrightness(25);
Wait(3.0);
dsLCD = DriverStationLCD::GetInstance();
dsLCD->Clear();
float X[2];
float Y[2];
float Z[2];
while(IsOperatorControl())
{
X[1] = Stick1->GetX();
X[2] = Stick2->GetX();
Y[1] = Stick1->GetY();
Y[2] = Stick2->GetY();
Z[1] = Stick1->GetZ();
Z[2] = Stick2->GetZ();
Jaguar1->Set(Y[1]);
Jaguar2->Set(Y[2]);
Wait(0.005);
if (mycam.IsFreshImage())
{
Himage = mycam.GetImage();
matchingPixels = Himage->ThresholdHSL(targetThreshold);
pReport = matchingPixels->GetOrderedParticleAnalysisReports();
for (unsigned int i = 0; i < pReport->size(); i++)
{
printf("Index: %d X Center: %d Y Center: %d \n", i, (*pReport)[i].center_mass_x, (*pReport)[i].center_mass_y);
}
delete Himage;
delete matchingPixels;
delete pReport;
}
}
//myRobot->ArcadeDrive(stick); // drive with arcade style (use right stick)
//Wait(0.005); // wait for a motor update time
}
示例2: DoImageProcessing
bool JankyTargeting::DoImageProcessing(void)
{
bool isSuccessful = false;
BinaryImage* firstBinaryImage = NULL;
BinaryImage* readyForConvexHull = NULL;
firstBinaryImage = hsl.ThresholdHSL(120,186,60,255,0,255);
if (firstBinaryImage !=NULL)
{
// Prune down # particles by removing all small stuff before convexHull.
readyForConvexHull = firstBinaryImage->RemoveSmallObjects(false, 2);
if (readyForConvexHull != NULL)
{
samwise = readyForConvexHull->ConvexHull(false);
if (samwise != NULL)
isSuccessful = true;
}
}
if (readyForConvexHull)
delete readyForConvexHull;
if (firstBinaryImage)
delete firstBinaryImage;
return isSuccessful;
}
示例3: throw
OpenBinaryImage::OpenBinaryImage(const BinaryImage& anImg,
unsigned int anOpenSize)
throw(QgarErrorDomain)
: BinaryImage(anImg)
{
int sqsize = (2 * anOpenSize) + 1; // Effective mask size
if ((sqsize > anImg.width()) || (sqsize > anImg.height()))
{
std::ostringstream os;
os << "Opening size ["
<< sqsize
<< " X "
<< sqsize
<< "] too large for image ["
<< anImg.width()
<< " X "
<< anImg.height()
<< "]";
throw QgarErrorDomain(__FILE__, __LINE__,
"void qgar::OpenBinaryImage::OpenBinaryImage(const qgar::BinaryImage&, unsigned int)",
os.str());
}
perform(this, anOpenSize);
}
示例4: main
//简单的测试程序,运行ok,结果ok
int main()
{
BinaryImage a(4, 5); //新建一张图片
a.setIndexValue(0, 0, 1); a.setIndexValue(0, 1, 0); a.setIndexValue(0, 2, 0); a.setIndexValue(0, 3, 1); a.setIndexValue(0, 4, 0);
a.setIndexValue(1, 0, 1); a.setIndexValue(1, 1, 1); a.setIndexValue(1, 2, 1); a.setIndexValue(1, 3, 0); a.setIndexValue(1, 4, 0);
a.setIndexValue(2, 0, 1); a.setIndexValue(2, 1, 0); a.setIndexValue(2, 2, 1); a.setIndexValue(2, 3, 1); a.setIndexValue(2, 4, 0);
a.setIndexValue(3, 0, 1); a.setIndexValue(3, 1, 0); a.setIndexValue(3, 2, 0); a.setIndexValue(3, 3, 0); a.setIndexValue(3, 4, 1);
Element b(2, 2); //新建一个结构元素
b.ptr[0][0] = 1; b.ptr[0][1] = 1;
b.ptr[1][0] = 1; b.ptr[1][1] = 0;
b.originX = 1;
b.originY = 1;
BinaryImage* k=a.dilation(b); //dilation
for (int i = 0; i < k->getRow(); i++)
{
for (int j = 0; j < k->getCol(); j++)
cout << k->getIndexValue(i, j) << " ";
cout << endl;
}
cout << "******************************" << endl;
BinaryImage* l = a.erosion(b); //erosion
for (int i = 0; i < l->getRow(); i++)
{
for (int j = 0; j < l->getCol(); j++)
cout <<l->getIndexValue(i, j) << " ";
cout << endl;
}
cout << "******************************" << endl;
system("pause");
}
示例5: throw
ErodedBinaryImage::ErodedBinaryImage(BinaryImage& anImg,
unsigned int anEroSize)
throw(QgarErrorDomain)
: BinaryImage(anImg)
{
int sqsize = (2 * anEroSize) + 1; // Effective mask size
if ((sqsize > anImg.width()) || (sqsize > anImg.height()))
{
std::ostringstream os;
os << "Erosion size ("
<< sqsize
<< " X "
<< sqsize
<< ") too large for an image "
<< anImg.width()
<< " X "
<< anImg.height();
throw QgarErrorDomain(__FILE__, __LINE__,
"qgar::ErodedBinaryImage::ErodedBinaryImage(qgar::BinaryImage&, unsigned int)",
os.str());
}
perform(this, anEroSize);
}
示例6: BinaryImage
BinaryImage *BinaryImage::RemoveLargeObjects(bool connectivity8, int erosions)
{
BinaryImage *result = new BinaryImage();
int success = imaqSizeFilter(result->GetImaqImage(), m_imaqImage, connectivity8, erosions, IMAQ_KEEP_SMALL, NULL);
wpi_setImaqErrorWithContext(success, "Error in RemoveLargeObjects");
return result;
}
示例7: calculate
Camera* Camera::calculate(void)
{
AxisCamera &cam = AxisCamera::GetInstance("10.8.54.11");
if (!cam.IsFreshImage())
return this;
take = false;
int i = cam.GetImage(&ci);
if (i) cerr << "image worked" << endl;
else cerr << "image didn't work" << endl;
//ci.Write("/colorimage.jpg");
BinaryImage *bi = ci.ThresholdHSL(200, 55,
0, 255,
0, 200);
//BinaryImage *bi = ci.ThresholdHSL(Constants::hueMin, Constants::hueMax,
// Constants::satMin, Constants::satMax,
// Constants::lumMin, Constants::lumMax);
//BinaryImage *biggerObjects = bi->RemoveSmallObjects(false, 2);
vector <ParticleAnalysisReport> *particleAnalysisList = bi->GetOrderedParticleAnalysisReports();
Rect biggestRectangle = particleAnalysisList->at(0).boundingRect;
int x = biggestRectangle.left + biggestRectangle.width/2;
int y = biggestRectangle.top + biggestRectangle.height/2;
cerr << "T: (" << x << "," << y << ")" << endl;
bi->Write("/image.bmp");
//delete bi;
//delete particleAnalysisList;
return this;
}
示例8: checkAlignedImage
static bool checkAlignedImage(
ConnCompEraserExt const& eraser, BinaryImage const& nonaligned)
{
BinaryImage const aligned(eraser.computeConnCompImageAligned());
int const pad = aligned.width() - nonaligned.width();
if (pad < 0) {
return false;
}
BinaryImage test1(nonaligned);
BinaryImage empty1(test1.size());
empty1.fill(WHITE);
rasterOp<RopXor<RopSrc, RopDst> >(test1, test1.rect(), aligned, QPoint(pad, 0));
if (test1 != empty1) {
return false;
}
if (pad > 0) {
// Check that padding is white.
BinaryImage test2(pad, nonaligned.height());
BinaryImage empty2(test2.size());
empty2.fill(WHITE);
rasterOp<RopSrc>(test2, test2.rect(), aligned, QPoint(0, 0));
if (test2 != empty2) {
return false;
}
}
return true;
}
示例9: GetDistanceToBall
double CameraHandler::GetDistanceToBall ()
{
unsigned x;
int ballNum;
double objAngle;
double largestArea;
double sizeRatio;
BinaryImage* binImg;
vector<ParticleAnalysisReport>* particles;
// ----- Get Image -----
camera->GetImage(img);
// ----- Filter out background -----
if (m_ds->GetAlliance() == DriverStation::kBlue)
binImg = img->ThresholdHSV(160, 184, 120, 255, 14, 233);
else
binImg = img->ThresholdRGB(88, 255, 0, 74, 0, 31);
// Make picture clear
frcMorphology(binImg->GetImaqImage(),binImg->GetImaqImage(),IMAQ_PCLOSE);
frcMorphology(binImg->GetImaqImage(),binImg->GetImaqImage(),IMAQ_ERODE);
particles = binImg->GetOrderedParticleAnalysisReports();
SmartDashboard::PutNumber("DEBUG Particle size: ", particles->size());
if (particles->size() > 0 && particles->size() < 30)
{
sort(particles->begin(),particles->end(),particleSort);
//Find ball
largestArea = 25.0;
ballNum = -1;
for (x = 0; ((x < particles->size()) && x < 5); x++)
{
sizeRatio = (double)(*particles)[x].boundingRect.height/(*particles)[x].boundingRect.width;
if (((*particles)[x].particleArea > largestArea) && (sizeRatio > 0.75 && sizeRatio < 1.25))
{
largestArea = (*particles)[x].particleArea;
ballNum = x;
}
}
}
if (ballNum >= 0)
{
objAngle = 0.5*((*particles)[ballNum].boundingRect.width)*(CAMERA_ANGLE/(*particles)[ballNum].imageWidth);
return 1/tan(objAngle);
}
else
return -1.0;
}
示例10: BinaryImage
BinaryImage*
ConnectedComponents::makeBinaryImg
(const std::vector<Component::label_type>& aLabSet)
{
// Create the resulting image
BinaryImage* pImgBin = new BinaryImage(componentImg_.width(),
componentImg_.height());
// Pointers to pixel maps
Component::label_type* pMapCC = componentImg_.pPixMap();
BinaryImage::pointer pMapBin = pImgBin->pPixMap();
// Current label and color
Component::label_type currLab = Component::LABEL_NO_;
QGEbw currColor = QGE_BW_WHITE;
// Number of pixels of both images
int size = componentImg_.width() * componentImg_.height();
// For each pixel of the component image
for (int iCnt = 0 ; iCnt< size ; ++iCnt, ++pMapCC, ++pMapBin)
{
if (*pMapCC != currLab)
{
// The new pixel belongs to a new component
currLab = *pMapCC;
std::vector<Component::label_type>::const_iterator it =
find(aLabSet.begin(), aLabSet.end(), currLab);
if ( (it == aLabSet.end())
|| ((*this)[currLab].color() == QGE_BW_WHITE))
{
// Current label does not belong to the given set
// or belongs to a WHITE component
currColor = QGE_BW_WHITE;
}
else
{
// Current label belongs to a BLACK component
currColor = QGE_BW_BLACK;
}
}
// Set the corresponding pixel of the resulting image
// to current color
*pMapBin = currColor;
} // END for iCnt
// Return a pointer to the resulting image
return pImgBin;
}
示例11: GetBlock
BinaryImage BinaryImage::GetBlock(int iS, int iE, int jS, int jE)
{
BinaryImage mat;
mat.MM = iE - iS + 1;
mat.NN = jE - jS + 1;
mat.data = new double[mat.MM * mat.NN];
for (int i = 0; i < mat.MM; i++)
for (int j = 0; j < mat.NN; j++)
mat.Set(i, j, Get(i + iS, j + jS));
return mat;
}
示例12: BinaryImage
/**
* Perform a threshold operation on a ColorImage.
* Perform a threshold operation on a ColorImage using the ColorMode supplied
* as a parameter.
* @param colorMode The type of colorspace this operation should be performed in
* @returns a pointer to a binary image
*/
BinaryImage *ColorImage::ComputeThreshold(ColorMode colorMode,
int low1, int high1,
int low2, int high2,
int low3, int high3)
{
BinaryImage *result = new BinaryImage();
Range range1 = {low1, high1},
range2 = {low2, high2},
range3 = {low3, high3};
int success = imaqColorThreshold(result->GetImaqImage(), m_imaqImage, 1, colorMode, &range1, &range2, &range3);
wpi_setImaqErrorWithContext(success, "ImaqThreshold error");
return result;
}
示例13:
BinaryImage::BinaryImage(const BinaryImage& rhs)
{
//cout<<"BinaryImage::BinaryImage(const BinaryImage&) is invoked...";
m = rhs.getm();
n = rhs.getn();
data = new double[m * n];
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
data[i * n + j] = rhs.get(i, j);
}
}
}
示例14: seed
void
TextLineTracer::sanitizeBinaryImage(BinaryImage& image, QRect const& content_rect)
{
// Kill connected components touching the borders.
BinaryImage seed(image.size(), WHITE);
seed.fillExcept(seed.rect().adjusted(1, 1, -1, -1), BLACK);
BinaryImage touching_border(seedFill(seed.release(), image, CONN8));
rasterOp<RopSubtract<RopDst, RopSrc> >(image, touching_border.release());
// Poor man's despeckle.
BinaryImage content_seeds(openBrick(image, QSize(2, 3), WHITE));
rasterOp<RopOr<RopSrc, RopDst> >(content_seeds, openBrick(image, QSize(3, 2), WHITE));
image = seedFill(content_seeds.release(), image, CONN8);
// Clear margins.
image.fillExcept(content_rect, WHITE);
}
示例15: calcScale
void
PolynomialSurface::prepareEquationsAndDataPoints(
GrayImage const& image, BinaryImage const& mask,
std::vector<double>& equations,
std::vector<double>& data_points) const
{
int const width = image.width();
int const height = image.height();
double const xscale = calcScale(width);
double const yscale = calcScale(height);
uint8_t const* image_line = image.data();
int const image_bpl = image.stride();
uint32_t const* mask_line = mask.data();
int const mask_wpl = mask.wordsPerLine();
int const last_word_idx = (width - 1) >> 5;
int const last_word_mask = ~uint32_t(0) << (31 - ((width - 1) & 31));
for (int y = 0; y < height; ++y) {
double const y_adjusted = y * yscale;
int idx = 0;
// Full words.
for (; idx < last_word_idx; ++idx) {
processMaskWord(
image_line, mask_line[idx], idx, y,
y_adjusted, xscale, equations, data_points
);
}
// Last word.
processMaskWord(
image_line, mask_line[idx] & last_word_mask,
idx, y, y_adjusted, xscale, equations, data_points
);
image_line += image_bpl;
mask_line += mask_wpl;
}
}