本文整理汇总了Java中com.google.zxing.ResultPoint.orderBestPatterns方法的典型用法代码示例。如果您正苦于以下问题:Java ResultPoint.orderBestPatterns方法的具体用法?Java ResultPoint.orderBestPatterns怎么用?Java ResultPoint.orderBestPatterns使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.zxing.ResultPoint
的用法示例。
在下文中一共展示了ResultPoint.orderBestPatterns方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findMulti
import com.google.zxing.ResultPoint; //导入方法依赖的package包/类
public FinderPatternInfo[] findMulti(Map<DecodeHintType,?> hints) throws NotFoundException {
boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
boolean pureBarcode = hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE);
BitMatrix image = getImage();
int maxI = image.getHeight();
int maxJ = image.getWidth();
// We are looking for black/white/black/white/black modules in
// 1:1:3:1:1 ratio; this tracks the number of such modules seen so far
// Let's assume that the maximum version QR Code we support takes up 1/4 the height of the
// image, and then account for the center being 3 modules in size. This gives the smallest
// number of pixels the center could be, so skip this often. When trying harder, look for all
// QR versions regardless of how dense they are.
int iSkip = (int) (maxI / (MAX_MODULES * 4.0f) * 3);
if (iSkip < MIN_SKIP || tryHarder) {
iSkip = MIN_SKIP;
}
int[] stateCount = new int[5];
for (int i = iSkip - 1; i < maxI; i += iSkip) {
// Get a row of black/white values
stateCount[0] = 0;
stateCount[1] = 0;
stateCount[2] = 0;
stateCount[3] = 0;
stateCount[4] = 0;
int currentState = 0;
for (int j = 0; j < maxJ; j++) {
if (image.get(j, i)) {
// Black pixel
if ((currentState & 1) == 1) { // Counting white pixels
currentState++;
}
stateCount[currentState]++;
} else { // White pixel
if ((currentState & 1) == 0) { // Counting black pixels
if (currentState == 4) { // A winner?
if (foundPatternCross(stateCount) && handlePossibleCenter(stateCount, i, j, pureBarcode)) { // Yes
// Clear state to start looking again
currentState = 0;
stateCount[0] = 0;
stateCount[1] = 0;
stateCount[2] = 0;
stateCount[3] = 0;
stateCount[4] = 0;
} else { // No, shift counts back by two
stateCount[0] = stateCount[2];
stateCount[1] = stateCount[3];
stateCount[2] = stateCount[4];
stateCount[3] = 1;
stateCount[4] = 0;
currentState = 3;
}
} else {
stateCount[++currentState]++;
}
} else { // Counting white pixels
stateCount[currentState]++;
}
}
} // for j=...
if (foundPatternCross(stateCount)) {
handlePossibleCenter(stateCount, i, maxJ, pureBarcode);
} // end if foundPatternCross
} // for i=iSkip-1 ...
FinderPattern[][] patternInfo = selectMutipleBestPatterns();
List<FinderPatternInfo> result = new ArrayList<>();
for (FinderPattern[] pattern : patternInfo) {
ResultPoint.orderBestPatterns(pattern);
result.add(new FinderPatternInfo(pattern));
}
if (result.isEmpty()) {
return EMPTY_RESULT_ARRAY;
} else {
return result.toArray(new FinderPatternInfo[result.size()]);
}
}
示例2: selectMutipleBestPatterns
import com.google.zxing.ResultPoint; //导入方法依赖的package包/类
private FinderPattern[][] selectMutipleBestPatterns() throws NotFoundException {
List<FinderPattern> possibleCenters = getPossibleCenters();
int size = possibleCenters.size();
if (size < 3) {
throw NotFoundException.getNotFoundInstance();
} else if (size == 3) {
FinderPattern[][] finderPatternArr = new FinderPattern[1][];
finderPatternArr[0] = new FinderPattern[]{(FinderPattern) possibleCenters.get(0),
(FinderPattern) possibleCenters.get(1), (FinderPattern) possibleCenters.get(2)};
return finderPatternArr;
} else {
Collections.sort(possibleCenters, new ModuleSizeComparator());
List<FinderPattern[]> results = new ArrayList();
for (int i1 = 0; i1 < size - 2; i1++) {
FinderPattern p1 = (FinderPattern) possibleCenters.get(i1);
if (p1 != null) {
for (int i2 = i1 + 1; i2 < size - 1; i2++) {
FinderPattern p2 = (FinderPattern) possibleCenters.get(i2);
if (p2 != null) {
float vModSize12 = (p1.getEstimatedModuleSize() - p2
.getEstimatedModuleSize()) / Math.min(p1
.getEstimatedModuleSize(), p2.getEstimatedModuleSize());
if (Math.abs(p1.getEstimatedModuleSize() - p2.getEstimatedModuleSize
()) > DIFF_MODSIZE_CUTOFF && vModSize12 >=
DIFF_MODSIZE_CUTOFF_PERCENT) {
break;
}
for (int i3 = i2 + 1; i3 < size; i3++) {
FinderPattern p3 = (FinderPattern) possibleCenters.get(i3);
if (p3 != null) {
float vModSize23 = (p2.getEstimatedModuleSize() - p3
.getEstimatedModuleSize()) / Math.min(p2
.getEstimatedModuleSize(), p3.getEstimatedModuleSize());
if (Math.abs(p2.getEstimatedModuleSize() - p3
.getEstimatedModuleSize()) > DIFF_MODSIZE_CUTOFF &&
vModSize23 >= DIFF_MODSIZE_CUTOFF_PERCENT) {
break;
}
Object test = new FinderPattern[]{p1, p2, p3};
ResultPoint.orderBestPatterns(test);
FinderPatternInfo info = new FinderPatternInfo(test);
float dA = ResultPoint.distance(info.getTopLeft(), info
.getBottomLeft());
float dC = ResultPoint.distance(info.getTopRight(), info
.getBottomLeft());
float dB = ResultPoint.distance(info.getTopLeft(), info
.getTopRight());
float estimatedModuleCount = (dA + dB) / (p1
.getEstimatedModuleSize() * 2.0f);
if (estimatedModuleCount <= MAX_MODULE_COUNT_PER_EDGE &&
estimatedModuleCount >= MIN_MODULE_COUNT_PER_EDGE &&
Math.abs((dA - dB) / Math.min(dA, dB)) < 0.1f) {
float dCpy = (float) Math.sqrt((double) ((dA * dA) + (dB
* dB)));
if (Math.abs((dC - dCpy) / Math.min(dC, dCpy)) < 0.1f) {
results.add(test);
}
}
}
}
}
}
}
}
if (!results.isEmpty()) {
return (FinderPattern[][]) results.toArray(new FinderPattern[results.size()][]);
}
throw NotFoundException.getNotFoundInstance();
}
}