本文整理汇总了C++中zxing::NotFoundException方法的典型用法代码示例。如果您正苦于以下问题:C++ zxing::NotFoundException方法的具体用法?C++ zxing::NotFoundException怎么用?C++ zxing::NotFoundException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zxing
的用法示例。
在下文中一共展示了zxing::NotFoundException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: recordPattern
void OneDReader::recordPattern(Ref<BitArray> row,
int start,
vector<int>& counters) {
int numCounters = counters.size();
for (int i = 0; i < numCounters; i++) {
counters[i] = 0;
}
int end = row->getSize();
if (start >= end) {
throw NotFoundException();
}
bool isWhite = !row->get(start);
int counterPosition = 0;
int i = start;
while (i < end) {
if (row->get(i) ^ isWhite) { // that is, exactly one is true
counters[counterPosition]++;
} else {
counterPosition++;
if (counterPosition == numCounters) {
break;
} else {
counters[counterPosition] = 1;
isWhite = !isWhite;
}
}
i++;
}
// If we read fully the last section of pixels and filled up our counters -- or filled
// the last counter but ran off the side of the image, OK. Otherwise, a problem.
if (!(counterPosition == numCounters || (counterPosition == numCounters - 1 && i == end))) {
throw NotFoundException();
}
}
示例2: validatePattern
void CodaBarReader::validatePattern(int start) {
// First, sum up the total size of our four categories of stripe sizes;
vector<int> sizes (4, 0);
vector<int> counts (4, 0);
int end = decodeRowResult.length() - 1;
// We break out of this loop in the middle, in order to handle
// inter-character spaces properly.
int pos = start;
for (int i = 0; true; i++) {
int pattern = CHARACTER_ENCODINGS[(int)decodeRowResult[i]];
for (int j = 6; j >= 0; j--) {
// Even j = bars, while odd j = spaces. Categories 2 and 3 are for
// long stripes, while 0 and 1 are for short stripes.
int category = (j & 1) + (pattern & 1) * 2;
sizes[category] += counters[pos + j];
counts[category]++;
pattern >>= 1;
}
if (i >= end) {
break;
}
// We ignore the inter-character space - it could be of any size.
pos += 8;
}
// Calculate our allowable size thresholds using fixed-point math.
vector<int> maxes (4, 0);
vector<int> mins (4, 0);
// Define the threshold of acceptability to be the midpoint between the
// average small stripe and the average large stripe. No stripe lengths
// should be on the "wrong" side of that line.
for (int i = 0; i < 2; i++) {
mins[i] = 0; // Accept arbitrarily small "short" stripes.
mins[i + 2] = ((sizes[i] << INTEGER_MATH_SHIFT) / counts[i] +
(sizes[i + 2] << INTEGER_MATH_SHIFT) / counts[i + 2]) >> 1;
maxes[i] = mins[i + 2];
maxes[i + 2] = (sizes[i + 2] * MAX_ACCEPTABLE + PADDING) / counts[i + 2];
}
// Now verify that all of the stripes are within the thresholds.
pos = start;
for (int i = 0; true; i++) {
int pattern = CHARACTER_ENCODINGS[(int)decodeRowResult[i]];
for (int j = 6; j >= 0; j--) {
// Even j = bars, while odd j = spaces. Categories 2 and 3 are for
// long stripes, while 0 and 1 are for short stripes.
int category = (j & 1) + (pattern & 1) * 2;
int size = counters[pos + j] << INTEGER_MATH_SHIFT;
if (size < mins[category] || size > maxes[category]) {
throw NotFoundException();
}
pattern >>= 1;
}
if (i >= end) {
break;
}
pos += 8;
}
}
示例3: NotFoundException
Ref<Result> UPCEANReader::decodeRow(int rowNumber,
Ref<BitArray> row,
Range const& startGuardRange) {
string& result = decodeRowStringBuffer;
result.clear();
int endStart = decodeMiddle(row, startGuardRange, result);
Range endRange = decodeEnd(row, endStart);
// Make sure there is a quiet zone at least as big as the end pattern after the barcode.
// The spec might want more whitespace, but in practice this is the maximum we can count on.
int end = endRange[1];
int quietEnd = end + (end - endRange[0]);
if (quietEnd >= row->getSize() || !row->isRange(end, quietEnd, false)) {
throw NotFoundException();
}
Ref<String> resultString (new String(result));
if (!checkChecksum(resultString)) {
throw ChecksumException();
}
float left = (float) (startGuardRange[1] + startGuardRange[0]) / 2.0f;
float right = (float) (endRange[1] + endRange[0]) / 2.0f;
BarcodeFormat format = getBarcodeFormat();
ArrayRef< Ref<ResultPoint> > resultPoints(2);
resultPoints[0] = Ref<ResultPoint>(new OneDResultPoint(left, (float) rowNumber));
resultPoints[1] = Ref<ResultPoint>(new OneDResultPoint(right, (float) rowNumber));
Ref<Result> decodeResult (new Result(resultString, ArrayRef<char>(), resultPoints, format));
// Java extension and man stuff
return decodeResult;
}
示例4: NotFoundException
char Code93Reader::patternToChar(int pattern) {
for (int i = 0; i < CHARACTER_ENCODINGS_LENGTH; i++) {
if (CHARACTER_ENCODINGS[i] == pattern) {
return ALPHABET[i];
}
}
throw NotFoundException();
}
示例5: skipWhiteSpace
/**
* Skip all whitespace until we get to the first black line.
*
* @param row row of black/white values to search
* @return index of the first black line.
* @throws ReaderException Throws exception if no black lines are found in the row
*/
int ITFReader::skipWhiteSpace(Ref<BitArray> row) {
int width = row->getSize();
int endStart = row->getNextSet(0);
if (endStart == width) {
throw NotFoundException();
}
return endStart;
}
示例6: validateQuietZone
/**
* The start & end patterns must be pre/post fixed by a quiet zone. This
* zone must be at least 10 times the width of a narrow line. Scan back until
* we either get to the start of the barcode or match the necessary number of
* quiet zone pixels.
*
* Note: Its assumed the row is reversed when using this method to find
* quiet zone after the end pattern.
*
* ref: http://www.barcode-1.net/i25code.html
*
* @param row bit array representing the scanned barcode.
* @param startPattern index into row of the start or end pattern.
* @throws ReaderException if the quiet zone cannot be found, a ReaderException is thrown.
*/
void ITFReader::validateQuietZone(Ref<BitArray> row, int startPattern) {
int quietCount = this->narrowLineWidth * 10; // expect to find this many pixels of quiet zone
for (int i = startPattern - 1; quietCount > 0 && i >= 0; i--) {
if (row->get(i)) {
break;
}
quietCount--;
}
if (quietCount != 0) {
// Unable to find the necessary number of quiet zone pixels.
throw NotFoundException();
}
}
示例7: findStartPattern
int CodaBarReader::findStartPattern() {
for (int i = 1; i < counterLength; i += 2) {
int charOffset = toNarrowWidePattern(i);
if (charOffset != -1 && arrayContains(STARTEND_ENCODING, ALPHABET[charOffset])) {
// Look for whitespace before start pattern, >= 50% of width of start pattern
// We make an exception if the whitespace is the first element.
int patternSize = 0;
for (int j = i; j < i + 7; j++) {
patternSize += counters[j];
}
if (i == 1 || counters[i-1] >= patternSize / 2) {
return i;
}
}
}
throw NotFoundException();
}
示例8: findGuardPattern
UPCEANReader::Range UPCEANReader::findGuardPattern(Ref<BitArray> row,
int rowOffset,
bool whiteFirst,
vector<int> const& pattern,
vector<int>& counters) {
// cerr << "fGP " << rowOffset << " " << whiteFirst << endl;
if (false) {
for(int i=0; i < (int)pattern.size(); ++i) {
std::cerr << pattern[i];
}
std::cerr << std::endl;
}
int patternLength = (int)pattern.size();
int width = row->getSize();
bool isWhite = whiteFirst;
rowOffset = whiteFirst ? row->getNextUnset(rowOffset) : row->getNextSet(rowOffset);
int counterPosition = 0;
int patternStart = rowOffset;
for (int x = rowOffset; x < width; x++) {
// std::cerr << "rg " << x << " " << row->get(x) << std::endl;
if (row->get(x) ^ isWhite) {
counters[counterPosition]++;
} else {
if (counterPosition == patternLength - 1) {
if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) {
return Range(patternStart, x);
}
patternStart += counters[0] + counters[1];
for (int y = 2; y < patternLength; y++) {
counters[y - 2] = counters[y];
}
counters[patternLength - 2] = 0;
counters[patternLength - 1] = 0;
counterPosition--;
} else {
counterPosition++;
}
counters[counterPosition] = 1;
isWhite = !isWhite;
}
}
throw NotFoundException();
}
示例9: decodeDigit
/**
* Attempts to decode a sequence of ITF black/white lines into single
* digit.
*
* @param counters the counts of runs of observed black/white/black/... values
* @return The decoded digit
* @throws ReaderException if digit cannot be decoded
*/
int ITFReader::decodeDigit(vector<int>& counters){
int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
int bestMatch = -1;
int max = sizeof(PATTERNS)/sizeof(PATTERNS[0]);
for (int i = 0; i < max; i++) {
int const* pattern = PATTERNS[i];
int variance = patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE);
if (variance < bestVariance) {
bestVariance = variance;
bestMatch = i;
}
}
if (bestMatch >= 0) {
return bestMatch;
} else {
throw NotFoundException();
}
}
示例10: setCounters
/**
* Records the size of all runs of white and black pixels, starting with white.
* This is just like recordPattern, except it records all the counters, and
* uses our builtin "counters" member for storage.
* @param row row to count from
*/
void CodaBarReader::setCounters(Ref<BitArray> row) {
counterLength = 0;
// Start from the first white bit.
int i = row->getNextUnset(0);
int end = row->getSize();
if (i >= end) {
throw NotFoundException();
}
bool isWhite = true;
int count = 0;
for (; i < end; i++) {
if (row->get(i) ^ isWhite) { // that is, exactly one is true
count++;
} else {
counterAppend(count);
count = 1;
isWhite = !isWhite;
}
}
counterAppend(count);
}
示例11: Range
Code93Reader::Range Code93Reader::findAsteriskPattern(Ref<BitArray> row) {
int width = row->getSize();
int rowOffset = row->getNextSet(0);
{ // Arrays.fill(counters, 0);
int size = counters.size();
counters.resize(0);
counters.resize(size); }
vector<int>& theCounters (counters);
int patternStart = rowOffset;
bool isWhite = false;
int patternLength = theCounters.size();
int counterPosition = 0;
for (int i = rowOffset; i < width; i++) {
if (row->get(i) ^ isWhite) {
theCounters[counterPosition]++;
} else {
if (counterPosition == patternLength - 1) {
if (toPattern(theCounters) == ASTERISK_ENCODING) {
return Range(patternStart, i);
}
patternStart += theCounters[0] + theCounters[1];
for (int y = 2; y < patternLength; y++) {
theCounters[y - 2] = theCounters[y];
}
theCounters[patternLength - 2] = 0;
theCounters[patternLength - 1] = 0;
counterPosition--;
} else {
counterPosition++;
}
theCounters[counterPosition] = 1;
isWhite = !isWhite;
}
}
throw NotFoundException();
}
示例12: decodeDigit
int UPCEANReader::decodeDigit(Ref<BitArray> row,
vector<int> & counters,
int rowOffset,
vector<int const*> const& patterns) {
recordPattern(row, rowOffset, counters);
int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
int bestMatch = -1;
int max = (int)patterns.size();
for (int i = 0; i < max; i++) {
int const* pattern (patterns[i]);
int variance = patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE);
if (variance < bestVariance) {
bestVariance = variance;
bestMatch = i;
}
}
if (bestMatch >= 0) {
return bestMatch;
} else {
throw NotFoundException();
}
}
示例13: findGuardPattern
/**
* @param row row of black/white values to search
* @param rowOffset position to start search
* @param pattern pattern of counts of number of black and white pixels that are
* being searched for as a pattern
* @return start/end horizontal offset of guard pattern, as an array of two
* ints
* @throws ReaderException if pattern is not found
*/
ITFReader::Range ITFReader::findGuardPattern(Ref<BitArray> row, int rowOffset,
vector<int> const& pattern) {
// TODO: This is very similar to implementation in UPCEANReader. Consider if they can be
// merged to a single method.
int patternLength = pattern.size();
vector<int> counters(patternLength);
int width = row->getSize();
bool isWhite = false;
int counterPosition = 0;
int patternStart = rowOffset;
for (int x = rowOffset; x < width; x++) {
if (row->get(x) ^ isWhite) {
counters[counterPosition]++;
} else {
if (counterPosition == patternLength - 1) {
if (patternMatchVariance(counters, &pattern[0],
MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) {
return Range(patternStart, x);
}
patternStart += counters[0] + counters[1];
for (int y = 2; y < patternLength; y++) {
counters[y - 2] = counters[y];
}
counters[patternLength - 2] = 0;
counters[patternLength - 1] = 0;
counterPosition--;
} else {
counterPosition++;
}
counters[counterPosition] = 1;
isWhite = !isWhite;
}
}
throw NotFoundException();
}
示例14: NotFoundException
Ref<Result> OneDReader::doDecode(Ref<BinaryBitmap> image, DecodeHints hints) {
int width = image->getWidth();
int height = image->getHeight();
Ref<BitArray> row(new BitArray(width));
int middle = height >> 1;
bool tryHarder = hints.getTryHarder();
int rowStep = std::max(1, height >> (tryHarder ? 8 : 5));
using namespace std;
// cerr << "rS " << rowStep << " " << height << " " << tryHarder << endl;
int maxLines;
if (tryHarder) {
maxLines = height; // Look at the whole image, not just the center
} else {
maxLines = 15; // 15 rows spaced 1/32 apart is roughly the middle half of the image
}
for (int x = 0; x < maxLines; x++) {
// Scanning from the middle out. Determine which row we're looking at next:
int rowStepsAboveOrBelow = (x + 1) >> 1;
bool isAbove = (x & 0x01) == 0; // i.e. is x even?
int rowNumber = middle + rowStep * (isAbove ? rowStepsAboveOrBelow : -rowStepsAboveOrBelow);
if (false) {
std::cerr << "rN "
<< rowNumber << " "
<< height << " "
<< middle << " "
<< rowStep << " "
<< isAbove << " "
<< rowStepsAboveOrBelow
<< std::endl;
}
if (rowNumber < 0 || rowNumber >= height) {
// Oops, if we run off the top or bottom, stop
break;
}
// Estimate black point for this row and load it:
try {
row = image->getBlackRow(rowNumber, row);
} catch (NotFoundException const& ignored) {
(void)ignored;
continue;
}
// While we have the image data in a BitArray, it's fairly cheap to reverse it in place to
// handle decoding upside down barcodes.
for (int attempt = 0; attempt < 2; attempt++) {
if (attempt == 1) {
row->reverse(); // reverse the row and continue
}
// Java hints stuff missing
try {
// Look for a barcode
// std::cerr << "rn " << rowNumber << " " << typeid(*this).name() << std::endl;
Ref<Result> result = decodeRow(rowNumber, row);
// We found our barcode
if (attempt == 1) {
// But it was upside down, so note that
// result.putMetadata(ResultMetadataType.ORIENTATION, new Integer(180));
// And remember to flip the result points horizontally.
ArrayRef< Ref<ResultPoint> > points(result->getResultPoints());
if (points) {
points[0] = Ref<ResultPoint>(new OneDResultPoint(width - points[0]->getX() - 1,
points[0]->getY()));
points[1] = Ref<ResultPoint>(new OneDResultPoint(width - points[1]->getX() - 1,
points[1]->getY()));
}
}
return result;
} catch (ReaderException const& re) {
(void)re;
continue;
}
}
}
throw NotFoundException();
}
示例15: NotFoundException
Ref<Result> CodaBarReader::decodeRow(int rowNumber, Ref<BitArray> row) {
{ // Arrays.fill(counters, 0);
int size = counters.size();
counters.resize(0);
counters.resize(size); }
setCounters(row);
int startOffset = findStartPattern();
int nextStart = startOffset;
decodeRowResult.clear();
do {
int charOffset = toNarrowWidePattern(nextStart);
if (charOffset == -1) {
throw NotFoundException();
}
// Hack: We store the position in the alphabet table into a
// StringBuilder, so that we can access the decoded patterns in
// validatePattern. We'll translate to the actual characters later.
decodeRowResult.append(1, (char)charOffset);
nextStart += 8;
// Stop as soon as we see the end character.
if (decodeRowResult.length() > 1 &&
arrayContains(STARTEND_ENCODING, ALPHABET[charOffset])) {
break;
}
} while (nextStart < counterLength); // no fixed end pattern so keep on reading while data is available
// Look for whitespace after pattern:
int trailingWhitespace = counters[nextStart - 1];
int lastPatternSize = 0;
for (int i = -8; i < -1; i++) {
lastPatternSize += counters[nextStart + i];
}
// We need to see whitespace equal to 50% of the last pattern size,
// otherwise this is probably a false positive. The exception is if we are
// at the end of the row. (I.e. the barcode barely fits.)
if (nextStart < counterLength && trailingWhitespace < lastPatternSize / 2) {
throw NotFoundException();
}
validatePattern(startOffset);
// Translate character table offsets to actual characters.
for (int i = 0; i < (int)decodeRowResult.length(); i++) {
decodeRowResult[i] = ALPHABET[(int)decodeRowResult[i]];
}
// Ensure a valid start and end character
char startchar = decodeRowResult[0];
if (!arrayContains(STARTEND_ENCODING, startchar)) {
throw NotFoundException();
}
char endchar = decodeRowResult[decodeRowResult.length() - 1];
if (!arrayContains(STARTEND_ENCODING, endchar)) {
throw NotFoundException();
}
// remove stop/start characters character and check if a long enough string is contained
if ((int)decodeRowResult.length() <= MIN_CHARACTER_LENGTH) {
// Almost surely a false positive ( start + stop + at least 1 character)
throw NotFoundException();
}
decodeRowResult.erase(decodeRowResult.length() - 1, 1);
decodeRowResult.erase(0, 1);
int runningCount = 0;
for (int i = 0; i < startOffset; i++) {
runningCount += counters[i];
}
float left = (float) runningCount;
for (int i = startOffset; i < nextStart - 1; i++) {
runningCount += counters[i];
}
float right = (float) runningCount;
ArrayRef< Ref<ResultPoint> > resultPoints(2);
resultPoints[0] =
Ref<OneDResultPoint>(new OneDResultPoint(left, (float) rowNumber));
resultPoints[1] =
Ref<OneDResultPoint>(new OneDResultPoint(right, (float) rowNumber));
return Ref<Result>(new Result(Ref<String>(new String(decodeRowResult)),
ArrayRef<char>(),
resultPoints,
BarcodeFormat::CODABAR));
}