本文整理汇总了C++中BitMatrix类的典型用法代码示例。如果您正苦于以下问题:C++ BitMatrix类的具体用法?C++ BitMatrix怎么用?C++ BitMatrix使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BitMatrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
BitMatrix<dim> subquotientMap
(const Subquotient<dim>& source,
const Subquotient<dim>& dest,
const BitMatrix<dim>& m)
{
assert(m.numColumns()==source.rank());
assert(m.numRows()==dest.rank());
BitMatrix<dim> result(dest.dimension(),0);
// restrict m to source.space()
for (RankFlags::iterator it=source.support().begin(); it(); ++it)
{
SmallBitVector v = m*source.space().basis(*it);
assert(v.size()==dest.rank());
/*
// go to canonical representative modulo destination subspace
dest.denominator().mod_reduce(v);
assert(v.size()==dest.rank());
// get coordinates in canonical basis
v.slice(dest.space().support()); // express |v| in basis of |d_space|
assert(v.size()==dest.space().dimension());
v.slice(dest.support());
*/
v=dest.toBasis(v);
assert(v.size()==dest.dimension()); // dimension of the subquotient
result.addColumn(v);
}
return result;
}
示例2: x
// create the map for converting index to matrix position
// 1 2 3
// 1 2 4 7 5 3 6 8 9 --> 4 5 6
// 7 8 9
void DepthEstimator::MapMatrix2ZigzagIdx(const Image8U::Size& size, DepthEstimator::MapRefArr& coords, BitMatrix& mask, int rawStride)
{
typedef DepthEstimator::MapRef MapRef;
const int w = size.width;
const int w1 = size.width-1;
coords.Empty();
coords.Reserve(size.area());
for (int dy=0, h=rawStride; dy<size.height; dy+=h) {
if (h*2 > size.height - dy)
h = size.height - dy;
int lastX = 0;
MapRef x(MapRef::ZERO);
for (int i=0, ei=w*h; i<ei; ++i) {
const MapRef pt(x.x, x.y+dy);
if (mask.empty() || mask.isSet(pt))
coords.Insert(pt);
if (x.x-- == 0 || ++x.y == h) {
if (++lastX < w) {
x.x = lastX;
x.y = 0;
} else {
x.x = w1;
x.y = lastX - w1;
}
}
}
}
}
示例3: search
// find score from alpha to beta
AlphaBetaBase::search(
const Board& board,
bool passed,
int depth,
eval_t alpha,
eval_t beta) {
BitMatrix moves = board.get_move_bit();
if (moves.size() == 0) {
if (passed) {
return board.get_score();
} else {
return search(board.make_inverse(), true, depth - 1, -beta, -alpha);
}
} else {
for (BitMoveOrderingIterator it(board, *p_evaluator_);
it.has_next(); it.go_next()) {
BitBoard next_board = it.get_next();
eval_t val = evaluate(next_board, false, -beta, -alpha);
if (alpha < val) {
alpha = val;
}
}
return alpha;
}
}
示例4: Subspace
/*!
\brief Constructs the normalised subspace generated by the columns of
a |BitMatrix|, i.e., the image of that matrix
*/
template<size_t dim> Subspace<dim>::
Subspace(const BitMatrix<dim>& M)
: d_basis(M.image())
, d_support()
, d_rank(M.numRows())
{
// change |d_basis| to a normalised form, and set |d_support|:
bitvector::Gauss_Jordan(d_support,d_basis);
}
示例5: endOfReverseBlackWhiteBlackRun
// Adapted from "sizeOfBlackWhiteBlackRun" in zxing::qrcode::Detector
Point QREdgeDetector::endOfReverseBlackWhiteBlackRun(const BitMatrix& image, Point from, Point to) {
int fromX = (int)from.x;
int fromY = (int)from.y;
int toX = (int)to.x;
int toY = (int)to.y;
bool steep = abs(toY - fromY) > abs(toX - fromX);
if (steep) {
int temp = fromX;
fromX = fromY;
fromY = temp;
temp = toX;
toX = toY;
toY = temp;
}
int dx = abs(toX - fromX);
int dy = abs(toY - fromY);
int error = -dx >> 1;
int ystep = fromY < toY ? -1 : 1;
int xstep = fromX < toX ? -1 : 1;
int state = 0; // In black pixels, looking for white, first or second time
// In case there are no points, prepopulate to from
int realX = fromX;
int realY = fromY;
for (int x = fromX, y = fromY; x != toX; x += xstep) {
realX = steep ? y : x;
realY = steep ? x : y;
if(realX < 0 || realY < 0 || realX >= (int)image.getWidth() || realY >= (int)image.getHeight())
break;
if (state == 1) { // In white pixels, looking for black
if (image.get(realX, realY)) {
state++;
}
} else {
if (!image.get(realX, realY)) {
state++;
}
}
if (state == 3) { // Found black, white, black, and stumbled back onto white; done
return Point(realX, realY);
}
error += dy;
if (error > 0) {
y += ystep;
error -= dx;
}
}
// B-W-B run not found, return the last point visited.
return Point(realX, realY);
}
示例6: ReadCodewords
ByteArray BitMatrixParser::ReadCodewords(const BitMatrix& image)
{
ByteArray result(144);
int height = image.height();
int width = image.width();
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int bit = BITNR[y][x];
if (bit >= 0 && image.get(x, y)) {
result[bit / 6] |= static_cast<uint8_t>(1 << (5 - (bit % 6)));
}
}
}
return result;
}
示例7: Decode
static ZXing::Result Decode(const BitMatrix &matrix)
{
BitArray row;
matrix.getRow(0, row);
std::unique_ptr<RowReader::DecodingState> state;
return Code128Reader(DecodeHints()).decodeRow(0, row, state);
}
示例8: FindAlignmentInRegion
/**
* <p>Attempts to locate an alignment pattern in a limited region of the image, which is
* guessed to contain it. This method uses {@link AlignmentPattern}.</p>
*
* @param overallEstModuleSize estimated module size so far
* @param estAlignmentX x coordinate of center of area probably containing alignment pattern
* @param estAlignmentY y coordinate of above
* @param allowanceFactor number of pixels in all directions to search from the center
* @return {@link AlignmentPattern} if found, or null otherwise
* @throws NotFoundException if an unexpected error occurs during detection
*/
AlignmentPattern FindAlignmentInRegion(const BitMatrix& image, float overallEstModuleSize, int estAlignmentX, int estAlignmentY, float allowanceFactor)
{
// Look for an alignment pattern (3 modules in size) around where it
// should be
int allowance = (int)(allowanceFactor * overallEstModuleSize);
int alignmentAreaLeftX = std::max(0, estAlignmentX - allowance);
int alignmentAreaRightX = std::min(image.width() - 1, estAlignmentX + allowance);
if (alignmentAreaRightX - alignmentAreaLeftX < overallEstModuleSize * 3) {
return {};
}
int alignmentAreaTopY = std::max(0, estAlignmentY - allowance);
int alignmentAreaBottomY = std::min(image.height() - 1, estAlignmentY + allowance);
if (alignmentAreaBottomY - alignmentAreaTopY < overallEstModuleSize * 3) {
return {};
}
return AlignmentPatternFinder::Find(image, alignmentAreaLeftX, alignmentAreaTopY, alignmentAreaRightX - alignmentAreaLeftX, alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize);
}
示例9: ContainsBlackPoint
/**
* Determines whether a segment contains a black point
*
* @param a min value of the scanned coordinate
* @param b max value of the scanned coordinate
* @param fixed value of fixed coordinate
* @param horizontal set to true if scan must be horizontal, false if vertical
* @return true if a black point has been found, else false.
*/
static bool ContainsBlackPoint(const BitMatrix& image, int a, int b, int fixed, bool horizontal) {
if (horizontal) {
for (int x = a; x <= b; x++) {
if (image.get(x, fixed)) {
return true;
}
}
}
else {
for (int y = a; y <= b; y++) {
if (image.get(fixed, y)) {
return true;
}
}
}
return false;
}
示例10: ThresholdBlock
/**
* Applies a single threshold to a block of pixels.
*/
static void ThresholdBlock(const uint8_t* luminances, int xoffset, int yoffset, int threshold, int stride, BitMatrix& matrix)
{
for (int y = 0, offset = yoffset * stride + xoffset; y < BLOCK_SIZE; y++, offset += stride) {
for (int x = 0; x < BLOCK_SIZE; x++) {
// Comparison needs to be <= so that black == 0 pixels are black even if the threshold is 0.
if (luminances[offset + x] <= threshold) {
matrix.set(xoffset + x, yoffset + y);
}
}
}
}
示例11:
// Applies a single threshold to an 8x8 block of pixels.
void LocalBlockBinarizer::threshold8x8Block(const unsigned char* luminances, int xoffset, int yoffset, int threshold,
int stride, BitMatrix& matrix) {
for (int y = 0; y < 8; y++) {
int offset = (yoffset + y) * stride + xoffset;
for (int x = 0; x < 8; x++) {
int pixel = luminances[offset + x];
if (pixel < threshold) {
matrix.set(xoffset + x, yoffset + y);
}
}
}
}
示例12: SizeOfBlackWhiteBlackRunBothWays
/**
* See {@link #sizeOfBlackWhiteBlackRun(int, int, int, int)}; computes the total width of
* a finder pattern by looking for a black-white-black run from the center in the direction
* of another point (another finder pattern center), and in the opposite direction too.
*/
static float SizeOfBlackWhiteBlackRunBothWays(const BitMatrix& image, int fromX, int fromY, int toX, int toY) {
float result = SizeOfBlackWhiteBlackRun(image, fromX, fromY, toX, toY);
// Now count other way -- don't run off image though of course
float scale = 1.0f;
int otherToX = fromX - (toX - fromX);
if (otherToX < 0) {
scale = (float)fromX / (float)(fromX - otherToX);
otherToX = 0;
}
else if (otherToX >= image.width()) {
scale = (float)(image.width() - 1 - fromX) / (float)(otherToX - fromX);
otherToX = image.width() - 1;
}
int otherToY = (int)(fromY - (toY - fromY) * scale);
scale = 1.0f;
if (otherToY < 0) {
scale = (float)fromY / (float)(fromY - otherToY);
otherToY = 0;
}
else if (otherToY >= image.height()) {
scale = (float)(image.height() - 1 - fromY) / (float)(otherToY - fromY);
otherToY = image.height() - 1;
}
otherToX = (int)(fromX + (otherToX - fromX) * scale);
result += SizeOfBlackWhiteBlackRun(image, fromX, fromY, otherToX, otherToY);
// Middle pixel is double-counted this way; subtract 1
return result - 1.0f;
}
示例13: SizeOfBlackWhiteBlackRun
/**
* <p>This method traces a line from a point in the image, in the direction towards another point.
* It begins in a black region, and keeps going until it finds white, then black, then white again.
* It reports the distance from the start to this point.</p>
*
* <p>This is used when figuring out how wide a finder pattern is, when the finder pattern
* may be skewed or rotated.</p>
*/
static float SizeOfBlackWhiteBlackRun(const BitMatrix& image, int fromX, int fromY, int toX, int toY) {
// Mild variant of Bresenham's algorithm;
// see http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
bool steep = std::abs(toY - fromY) > std::abs(toX - fromX);
if (steep) {
std::swap(fromX, fromY);
std::swap(toX, toY);
}
int dx = std::abs(toX - fromX);
int dy = std::abs(toY - fromY);
int error = -dx / 2;
int xstep = fromX < toX ? 1 : -1;
int ystep = fromY < toY ? 1 : -1;
// In black pixels, looking for white, first or second time.
int state = 0;
// Loop up until x == toX, but not beyond
int xLimit = toX + xstep;
for (int x = fromX, y = fromY; x != xLimit; x += xstep) {
int realX = steep ? y : x;
int realY = steep ? x : y;
// Does current pixel mean we have moved white to black or vice versa?
// Scanning black in state 0,2 and white in state 1, so if we find the wrong
// color, advance to next state or end if we are in state 2 already
if ((state == 1) == image.get(realX, realY)) {
if (state == 2) {
return ResultPoint::Distance(x, y, fromX, fromY);
}
state++;
}
error += dy;
if (error > 0) {
if (y == toY) {
break;
}
y += ystep;
error -= dx;
}
}
// Found black-white-black; give the benefit of the doubt that the next pixel outside the image
// is "white" so this last point at (toX+xStep,toY) is the right ending. This is really a
// small approximation; (toX+xStep,toY+yStep) might be really correct. Ignore this.
if (state == 2) {
return ResultPoint::Distance(toX + xstep, toY, fromX, fromY);
}
// else we didn't find even black-white-black; no estimate is really possible
return std::numeric_limits<float>::quiet_NaN();
}
示例14: GetBlackPointOnSegment
static bool GetBlackPointOnSegment(const BitMatrix& image, int aX, int aY, int bX, int bY, ResultPoint& result) {
int dist = RoundToNearest(ResultPoint::Distance(aX, aY, bX, bY));
float xStep = static_cast<float>(bX - aX) / dist;
float yStep = static_cast<float>(bY - aY) / dist;
for (int i = 0; i < dist; i++) {
int x = RoundToNearest(aX + i * xStep);
int y = RoundToNearest(aY + i * yStep);
if (image.get(x, y)) {
result.set(static_cast<float>(x), static_cast<float>(y));
return true;
}
}
return false;
}
示例15: main
int main(int argc, char **argv) {
clock_t begin = clock();
// MultiQuadTuple<N, M> f = MultiQuadTuple<N, M>::randomMultiQuadTuple();
// BitVector<N> x = BitVector<N>::randomVector();
// testLeftCompose(f, x);
// testRightCompose(f, x);
// testEvaluateMQT(f, x);
//PrivateKey<N> pk;
BitMatrix<N> randomInvertible = BitMatrix<N>::randomInvertibleMatrix();
randomInvertible.print();
// testBridgeKeyInstantiation(pk);
// testPublicKey(pk);
clock_t end = clock();
cout << "Time elapsed: " << double(end - begin) / CLOCKS_PER_SEC << " sec" << endl;
fclose(urandom);
return 0;
}