2 * Copyright 2009 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.multi.qrcode.detector;
19 import com.google.zxing.FormatException;
20 import com.google.zxing.NotFoundException;
21 import com.google.zxing.common.BitMatrix;
22 import com.google.zxing.common.DetectorResult;
23 import com.google.zxing.qrcode.detector.Detector;
24 import com.google.zxing.qrcode.detector.FinderPatternInfo;
26 import java.util.Hashtable;
27 import java.util.Vector;
30 * <p>Encapsulates logic that can detect one or more QR Codes in an image, even if the QR Code
31 * is rotated or skewed, or partially obscured.</p>
34 * @author Hannes Erven
36 public final class MultiDetector extends Detector {
38 private static final DetectorResult[] EMPTY_DETECTOR_RESULTS = new DetectorResult[0];
40 public MultiDetector(BitMatrix image) {
44 public DetectorResult[] detectMulti(Hashtable hints) throws NotFoundException {
45 BitMatrix image = getImage();
46 MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image);
47 FinderPatternInfo[] info = finder.findMulti(hints);
49 if (info == null || info.length == 0) {
50 throw NotFoundException.getNotFoundInstance();
53 Vector result = new Vector();
54 for (int i = 0; i < info.length; i++) {
56 result.addElement(processFinderPatternInfo(info[i]));
57 } catch (FormatException e) {
61 if (result.isEmpty()) {
62 return EMPTY_DETECTOR_RESULTS;
64 DetectorResult[] resultArray = new DetectorResult[result.size()];
65 for (int i = 0; i < result.size(); i++) {
66 resultArray[i] = (DetectorResult) result.elementAt(i);