本文整理汇总了C++中ImageGray::data方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageGray::data方法的具体用法?C++ ImageGray::data怎么用?C++ ImageGray::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageGray
的用法示例。
在下文中一共展示了ImageGray::data方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: percentageBlack
double CheckPatterns::percentageBlack(const ImageGray & sourceImage, int xleft, int ytop, int xright, int ybottom)
{
std::pair<int, int> topleft = {
Extensions::getValueFromPercentage(sourceImage.width(), xleft),
Extensions::getValueFromPercentage(sourceImage.height(), ytop),
};
std::pair<int, int> bottomright = {
Extensions::getValueFromPercentage(sourceImage.width(), xright),
Extensions::getValueFromPercentage(sourceImage.height(), ybottom),
};
std::pair<int, int> size = {
bottomright.first - topleft.first,
bottomright.second - topleft.second
};
unsigned int numBlack = 0;
auto pxl_ptr = sourceImage.data(topleft.first, topleft.second);
for (int y = size.second; y > 0; --y) {
for (int x = size.first; x > 0; --x) {
numBlack += *pxl_ptr < thresholdValue;
pxl_ptr++;
}
pxl_ptr = sourceImage.data(topleft.first, topleft.second + y);
}
return Extensions::getWeightFromPercentage(Extensions::getPercentage(numBlack, size.first * size.second));
}
示例2: countBlackPixelsPerLineVertical
double CheckPatterns::countBlackPixelsPerLineVertical(const ImageGray &sourceImage, int percentage)
{
//bt->reset();
//bt->start();
if (percentage > 100)
{
percentage = 100;
}
else if (percentage < 0)
{
percentage = 0;
}
//int x = (int)(sourceImage.width() / 100.0 * percentage);
int x = Extensions::getValueFromPercentage(sourceImage.width(), percentage);
int blackPixels = 0;
auto end_ptr = sourceImage.data(x, sourceImage.height());
for (auto pxl_ptr = sourceImage.data(x, 0); pxl_ptr < end_ptr; pxl_ptr += sourceImage.width())
{
blackPixels += (int)(*pxl_ptr < thresholdValue);
}
//bt->stop();
//std::cout << "Time for the countBlackPixelsPerLineVertical function: " << //bt->elapsedMicroSeconds() << " Microseconds (" << //bt->elapsedMilliSeconds() << "ms)" << std::endl;
//return blackPixels;
//return (int)(blackPixels / (double)(sourceImage.height()) * 100);
return Extensions::getWeightFromPercentage(Extensions::getPercentage(blackPixels, sourceImage.height()));
}
示例3: countBlackWhiteTransisitionVertical
double CheckPatterns::countBlackWhiteTransisitionVertical(const ImageGray &sourceImage, int percentage)
{
//bt->reset();
//bt->start();
int x = Extensions::getValueFromPercentage(sourceImage.width(), percentage);
int pixelCounter = 0;
// set oldpixel to 1 because white is 1 and every ImageGray starts with white
int oldPixel = 1;
auto end_ptr = sourceImage.data(x, sourceImage.height());
bool oldpixel = 1;
for (auto pxl_ptr = sourceImage.data(x, 0); pxl_ptr < end_ptr; pxl_ptr += sourceImage.width()) {
bool currentPixel = (*pxl_ptr > thresholdValue);
pixelCounter += (int)(currentPixel != oldPixel);
oldPixel = currentPixel;
}
//bt->stop();
//std::cout << "Time for the checkBlackWhiteTransision function: " << //bt->elapsedMicroSeconds() << " Microseconds (" << //bt->elapsedMilliSeconds() << "ms)" << std::endl;
//return pixelCounter;
return Extensions::getWeightFromPercentage(Extensions::getPercentage(pixelCounter, sourceImage.height()));
}
示例4: checkSymmetryVertical
double CheckPatterns::checkSymmetryVertical(const ImageGray &sourceImage, bool boundingBox)
{
//bt->reset();
//bt->start();
int numberOfBlackPixels = 0, symmetricBlackPixels = 0;
//double percentageSymmetric;
if (boundingBox)
{
int x1 = this->findLeftBlackPixel(sourceImage);
int x2 = this->findRightBlackPixel(sourceImage);
int y1 = this->findTopBlackPixel(sourceImage);
int y2 = this->findBottomBlackPixel(sourceImage);
for (int y = y2; y >= ((y2 - y1) / 2); y--)
{
for (int x = x2; x >= x1; x--)
{
if (*(sourceImage.data(x, y)) < thresholdValue)
{
numberOfBlackPixels++;
if (*(sourceImage.data(x, sourceImage.height() - y)) < thresholdValue)
{
symmetricBlackPixels++;
}
}
}
}
}
else
{
for (int x = 0; x < sourceImage.width(); x++)
{
auto top_ptr = sourceImage.data(x, 0);
for (int offset = sourceImage.height() - 1; offset > 0; offset -= 2)
{
bool topBlack = *top_ptr < thresholdValue;
bool bottomBlack = *(top_ptr + offset) < thresholdValue;
//numberOfBlackPixels += topBlack;
bool bothBlack = topBlack == bottomBlack;
symmetricBlackPixels += (int)bothBlack;
top_ptr += sourceImage.width();
}
}
}
//percentageSymmetric = ((double)symmetricBlackPixels / (double)numberOfBlackPixels)*100.0;
//bt->stop();
//std::cout << "Time for the checkSymmetryVertical function: " << //bt->elapsedMicroSeconds() << " Microseconds (" << //bt->elapsedMilliSeconds() << "ms)" << std::endl;
//return (int)percentageSymmetric;
return Extensions::getWeightFromPercentage(Extensions::getPercentage(symmetricBlackPixels, sourceImage.size()/2));
}
示例5: firstEdgeLocationBottom
double CheckPatterns::firstEdgeLocationBottom(const ImageGray & sourceImage, int percentage)
{
int x = Extensions::getValueFromPercentage(sourceImage.width(), percentage);
// set oldpixel to 1 because white is 1 and every ImageGray starts with white
auto end_ptr = sourceImage.data(x, 0);
bool oldpixel = 1;
int y = sourceImage.height() - 1;
for (auto pxl_ptr = sourceImage.data(x, sourceImage.height() - 1); pxl_ptr >= end_ptr; pxl_ptr -= sourceImage.width()) {
bool currentPixel = (*pxl_ptr > thresholdValue);
if (oldpixel != currentPixel) {
return Extensions::getWeightFromPercentage(Extensions::getPercentage(y, sourceImage.height()));
}
oldpixel = currentPixel;
y--;
}
return 1.0;
}
示例6: findLeftBlackPixel
int CheckPatterns::findLeftBlackPixel(const ImageGray &sourceImage)
{
int xValue = sourceImage.width();
for (int y = sourceImage.height(); y >= 0; y--)
{
for (int x = 0; x <= (sourceImage.width() / 2); x++)
{
if (*(sourceImage.data(x, y)) < thresholdValue)
{
if (x <= xValue){
xValue = x;
x = 0;
y--;
}
}
}
}
return xValue;
}
示例7: findBottomBlackPixel
int CheckPatterns::findBottomBlackPixel(const ImageGray &sourceImage)
{
int yValue = 0;
for (int x = sourceImage.width(); x >= 0; x--)
{
for (int y = sourceImage.height(); y >= (sourceImage.height() / 2); y--)
{
if (*(sourceImage.data(x, y)) < thresholdValue)
{
if (y >= yValue)
{
yValue = y;
x--;
y = 0;
}
}
}
}
return yValue;
};
示例8: saveImg
void saveImg(const ImageGray & img, const std::string filename)
{
CImg<unsigned char> cimg(img.data(), img.width(), img.height(), 1, 1);
cimg.save(filename.c_str());
}