void decodeQR() { GenericMultipleBarcodeReader reader = new GenericMultipleBarcodeReader(new QRCodeReader()); while (running_) { if (_reading && bitmap_ != null) { try { ZXing.Result[] list = reader.decodeMultiple(bitmap_); if (list != null) { foreach (var result in list) { messageQueue_.Enqueue(result); } } }catch (Exception e) { Debug.LogWarning(e.Message); } } } }
public void testMulti() { // Very basic test for now var testBase = AbstractBlackBoxTestCase.buildTestBase("test/data/blackbox/multi-1"); var source = new BitmapLuminanceSource((Bitmap)Bitmap.FromFile(Path.Combine(testBase, "1.png"))); var bitmap = new BinaryBitmap(new HybridBinarizer(source)); var reader = new GenericMultipleBarcodeReader(new MultiFormatReader()); var results = reader.decodeMultiple(bitmap); Assert.IsNotNull(results); Assert.AreEqual(2, results.Length); Assert.AreEqual("031415926531", results[0].Text); Assert.AreEqual(BarcodeFormat.UPC_A, results[0].BarcodeFormat); Assert.AreEqual("www.airtable.com/jobs", results[1].Text); Assert.AreEqual(BarcodeFormat.QR_CODE, results[1].BarcodeFormat); }
void Start() { _reader = new GenericMultipleBarcodeReader(new QRCodeReader()); _hints = new Hashtable(); _hints.Add(DecodeHintType.TRY_HARDER, true); _hints.Add(DecodeHintType.POSSIBLE_FORMATS, new List <BarcodeFormat> () { BarcodeFormat.QR_CODE, BarcodeFormat.DATAMATRIX }); //var barcodeFormats = Enum.GetValues (typeof(BarcodeFormat)).Cast<BarcodeFormat> ().ToList (); //_hints.Add (DecodeHintType.POSSIBLE_FORMATS, new List<BarcodeFormat> (barcodeFormats)); VuforiaBehaviour qcarBehaviour = GetComponent <VuforiaBehaviour>(); if (qcarBehaviour) { qcarBehaviour.RegisterTrackerEventHandler(this); } isFrameFormatSet = CameraDevice.Instance.SetFrameFormat(Vuforia.Image.PIXEL_FORMAT.GRAYSCALE, true); InvokeRepeating("Autofocus", 1f, 2f); }
private Result[] decodeMulti(Uri uri, string originalInput, IDictionary <DecodeHintType, object> hints) { Bitmap image; try { image = (Bitmap)Bitmap.FromFile(uri.LocalPath); } catch (Exception) { throw new FileNotFoundException("Resource not found: " + uri); } using (image) { LuminanceSource source; if (config.Crop == null) { source = new BitmapLuminanceSource(image); } else { int[] crop = config.Crop; source = new BitmapLuminanceSource(image).crop(crop[0], crop[1], crop[2], crop[3]); } BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); if (config.DumpBlackPoint) { dumpBlackPoint(uri, image, bitmap, source); } MultiFormatReader multiFormatReader = new MultiFormatReader(); GenericMultipleBarcodeReader reader = new GenericMultipleBarcodeReader( multiFormatReader); Result[] results = reader.decodeMultiple(bitmap, hints); if (results != null && results.Length > 0) { if (config.Brief) { Console.Out.WriteLine(uri + ": Success"); } else { foreach (var result in results) { ParsedResult parsedResult = ResultParser.parseResult(result); var resultString = originalInput + " (format: " + result.BarcodeFormat + ", type: " + parsedResult.Type + "):" + Environment.NewLine; for (int i = 0; i < result.ResultPoints.Length; i++) { ResultPoint rp = result.ResultPoints[i]; Console.Out.WriteLine(" Point " + i + ": (" + rp.X + ',' + rp.Y + ')'); } resultString += "Raw result:" + Environment.NewLine + result.Text + Environment.NewLine; resultString += "Parsed result:" + Environment.NewLine + parsedResult.DisplayResult + Environment.NewLine; Console.Out.WriteLine(resultString); ResultString = resultString; } } return(results); } else { var resultString = originalInput + ": No barcode found"; Console.Out.WriteLine(resultString); ResultString = resultString; } return(null); } }
/// <summary> /// Tries to decode barcodes within an image which is given by a luminance source. /// That method gives a chance to prepare a luminance source completely before calling /// the time consuming decoding method. On the other hand there is a chance to create /// a luminance source which is independent from external resources (like Bitmap objects) /// and the decoding call can be made in a background thread. /// </summary> /// <param name="luminanceSource">The luminance source.</param> /// <returns></returns> public virtual Result[] DecodeMultiple(LuminanceSource luminanceSource) { var results = default(Result[]); var binarizer = CreateBinarizer(luminanceSource); var binaryBitmap = new BinaryBitmap(binarizer); var rotationCount = 0; var rotationMaxCount = 1; MultipleBarcodeReader multiReader = null; if (AutoRotate) { Options.Hints[DecodeHintType.TRY_HARDER_WITHOUT_ROTATION] = true; rotationMaxCount = 4; } var formats = Options.PossibleFormats; if (formats != null && formats.Count == 1 && formats.Contains(BarcodeFormat.QR_CODE)) { multiReader = new QRCodeMultiReader(); } else { multiReader = new GenericMultipleBarcodeReader(Reader); } for (; rotationCount < rotationMaxCount; rotationCount++) { results = multiReader.decodeMultiple(binaryBitmap, Options.Hints); if (results == null) { if (TryInverted && luminanceSource.InversionSupported) { binaryBitmap = new BinaryBitmap(CreateBinarizer(luminanceSource.invert())); results = multiReader.decodeMultiple(binaryBitmap, Options.Hints); } } if (results != null || !luminanceSource.RotateSupported || !AutoRotate) break; binaryBitmap = new BinaryBitmap(CreateBinarizer(luminanceSource.rotateCounterClockwise())); } if (results != null) { foreach (var result in results) { if (result.ResultMetadata == null) { result.putMetadata(ResultMetadataType.ORIENTATION, rotationCount * 90); } else if (!result.ResultMetadata.ContainsKey(ResultMetadataType.ORIENTATION)) { result.ResultMetadata[ResultMetadataType.ORIENTATION] = rotationCount * 90; } else { // perhaps the core decoder rotates the image already (can happen if TryHarder is specified) result.ResultMetadata[ResultMetadataType.ORIENTATION] = ((int)(result.ResultMetadata[ResultMetadataType.ORIENTATION]) + rotationCount * 90) % 360; } } OnResultsFound(results); } return results; }