private void DecodeFrame(FastJavaByteArray fastArray) { var cameraParameters = _cameraController.Camera.GetParameters(); var width = cameraParameters.PreviewSize.Width; var height = cameraParameters.PreviewSize.Height; InitBarcodeReaderIfNeeded(); var rotate = false; var newWidth = width; var newHeight = height; // use last value for performance gain var cDegrees = _cameraController.LastCameraDisplayOrientationDegree; if (cDegrees == 90 || cDegrees == 270) { rotate = true; newWidth = height; newHeight = width; } ZXing.Result result = null; var start = PerformanceCounter.Start(); LuminanceSource luminanceSource; var fast = new FastJavaByteArrayYUVLuminanceSource(fastArray, width, height, 0, 0, width, height); // _area.Left, _area.Top, _area.Width, _area.Height); if (rotate) { fast.CopyMatrix(ref _matrix); RotateCounterClockwise(_matrix, ref _rotatedMatrix, width, height); // _area.Width, _area.Height); luminanceSource = new PlanarYUVLuminanceSource(_rotatedMatrix, height, width, 0, 0, height, width, false); // _area.Height, _area.Width, 0, 0, _area.Height, _area.Width, false); } else { luminanceSource = fast; } result = _barcodeReader.Decode(luminanceSource); fastArray.Dispose(); fastArray = null; PerformanceCounter.Stop(start, "Decode Time: {0} ms (width: " + width + ", height: " + height + ", degrees: " + cDegrees + ", rotate: " + rotate + ")"); if (result != null) { Android.Util.Log.Debug(MobileBarcodeScanner.TAG, "Barcode Found: " + result.Text); _wasScanned = true; BarcodeFound?.Invoke(this, result); return; } }
public void testCrop() { var source = new PlanarYUVLuminanceSource(YUV, COLS, ROWS, 1, 1, COLS - 2, ROWS - 2, false); for (int r = 0; r < ROWS - 2; r++) { assertEquals(Y, (r + 1)*COLS + 1, source.getRow(r, null), 0, COLS - 2); } }
public void testNoCrop() { var source = new PlanarYUVLuminanceSource(YUV, COLS, ROWS, 0, 0, COLS, ROWS, false); assertEquals(Y, 0, source.Matrix, 0, Y.Length); for (int r = 0; r < ROWS; r++) { assertEquals(Y, r*COLS, source.getRow(r, null), 0, COLS); } }
public void testCrop() { var source = new PlanarYUVLuminanceSource(YUV, COLS, ROWS, 1, 1, COLS - 2, ROWS - 2, false); for (int r = 0; r < ROWS - 2; r++) { assertEquals(Y, (r + 1) * COLS + 1, source.getRow(r, null), 0, COLS - 2); } }
public void testNoCrop() { var source = new PlanarYUVLuminanceSource(YUV, COLS, ROWS, 0, 0, COLS, ROWS, false); assertEquals(Y, 0, source.Matrix, 0, Y.Length); for (int r = 0; r < ROWS; r++) { assertEquals(Y, r * COLS, source.getRow(r, null), 0, COLS); } }
//string RgbHandle(Bitmap scanBitmap) //{ // RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap, scanBitmap.Width, scanBitmap.Height); // BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source)); // QRCodeReader reader = new QRCodeReader(); // try // { // // DecodeHintType 和EncodeHintType // var hints = new Dictionary<DecodeHintType, object>(); // hints.Add(DecodeHintType.CHARACTER_SET, "utf-8"); // 设置二维码内容的编码 // var result= reader.decode(bitmap1, hints); // return result.Text; // } // catch // { // return string.Empty; // } //} string YuvHandle(Bitmap scanBitmap) { LuminanceSource source1 = new PlanarYUVLuminanceSource(rgb2YUV(scanBitmap), scanBitmap.Width, scanBitmap.Height, 0, 0, scanBitmap.Width, scanBitmap.Height, false); BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source1)); MultiFormatReader reader1 = new MultiFormatReader(); try { var result = reader1.decode(binaryBitmap); return(result.Text); } catch { return(string.Empty); } }
public void testCrop() { var source = new PlanarYUVLuminanceSource(YUV, COLS, ROWS, 1, 1, COLS - 2, ROWS - 2, false); Assert.IsTrue(source.CropSupported); byte[] cropMatrix = source.Matrix; for (int r = 0; r < ROWS - 2; r++) { assertEquals(Y, (r + 1) * COLS + 1, cropMatrix, r * (COLS - 2), COLS - 2); } for (int r = 0; r < ROWS - 2; r++) { assertEquals(Y, (r + 1) * COLS + 1, source.getRow(r, null), 0, COLS - 2); } }
public void OnPreviewFrame(byte [] bytes, Android.Hardware.Camera camera) { Console.WriteLine("PREVIEW FRAME"); if ((DateTime.Now - lastPreviewAnalysis).TotalMilliseconds < 250) { return; } try { byte[] rotatedData = new byte[bytes.Length]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { rotatedData[x * height + height - y - 1] = bytes[x + y * width]; } } var dataRect = GetFramingRectInPreview(); var luminance = new PlanarYUVLuminanceSource(rotatedData, width, height, dataRect.Left, dataRect.Top, dataRect.Width(), dataRect.Height(), false); var binarized = new BinaryBitmap(new ZXing.Common.HybridBinarizer(luminance)); var result = reader.decodeWithState(binarized); lastPreviewAnalysis = DateTime.Now; if (result == null || string.IsNullOrEmpty(result.Text)) { return; } Android.Util.Log.Debug("ZXing.Mobile", "Barcode Found: " + result.Text); ShutdownCamera(); activity.OnScan(result); } catch (ReaderException) { Android.Util.Log.Debug("ZXing.Mobile", "No barcode Found"); // ignore this exception; it happens every time there is a failed scan } catch (Exception) { // TODO: this one is unexpected.. log or otherwise handle it throw; } }
public void testThumbnail() { var source = new PlanarYUVLuminanceSource(YUV, COLS, ROWS, 0, 0, COLS, ROWS, false); Assert.AreEqual( new int[] { (0x00FF0000 << 8) + 0x00808080, (0x00FF0000 << 8) + 0x00818181, (0x00FF0000 << 8) + 0x00838383, (0x00FF0000 << 8) + 0x00808080, (0x00FF0000 << 8) + 0x007F7F7F, (0x00FF0000 << 8) + 0x007D7D7D }, source.renderThumbnail()); }
void Update() { count++; if (count <= fps) { IsModel = false; if (MenuOpened != true && scan_again == true) { if (cameraInitialized) { try { var cameraFeed = CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.GRAYSCALE); if (cameraFeed == null) { return; } byte[] pixels = cameraFeed.Pixels; int imageWidth = cameraFeed.BufferWidth; int imageHeight = cameraFeed.BufferHeight; int dstLeft, dstTop, dstWidth, dstHeight; dstLeft = 0; dstTop = 0; dstWidth = imageWidth; dstHeight = imageHeight; PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(pixels, imageWidth, imageHeight, dstLeft, dstTop, dstWidth, dstHeight, true); BinaryBitmap bitmap = new BinaryBitmap( new HybridBinarizer(source)); var data = QRReader.decode(bitmap); if (data != null) { scan_again = false; StartCoroutine(QRSucces()); Data = data.Text; string[] DATATR = Data.Split(new Char[] { '\t', '\t', '\n' }); foreach (string ln in DATATR) { if (ln.Length > 0 && ln[0] != '#') { string l = ln.Trim().Replace(" ", " "); string[] cmps = l.Split(' '); if (cmps[0] == "mtllib") { IsModel = true; break; } } } if (IsModel == true && data.Text != Data) { OBJ2 = OBJLoader.LoadOBJFile(Data); OBJ2.layer = 4; Mesh M = OBJ2.transform.GetComponentInChildren <MeshFilter>().mesh; M.RecalculateBounds(); M.RecalculateNormals(); M.RecalculateTangents(); OBJ2.transform.SetParent(target.transform); OBJ2.transform.localPosition = new Vector3(0, 0, 0); OBJ2.transform.localRotation = Quaternion.Euler(0, 0, 0); OBJ2.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); // Debug.Log(mr.bounds.size); if (M.bounds.size.y > 20) { float z = M.bounds.size.y / 4; OBJ2.transform.localScale = new Vector3(OBJ2.transform.localScale.x / z, OBJ2.transform.localScale.y / z, OBJ2.transform.localScale.z / z); } UIController.bt_en = true; Destroy(OBJ); } if (IsModel == false) { string[] DATATR2 = Data.Split('/'); if (DATATR2[0] == "http:" || DATATR2[0] == "https:") { if (DATATR2[2] == "e98517l3.beget.tech") { //&& data.Text != Data StartCoroutine(ChekInternetConnection(Data)); // StartCoroutine(Get(Data)); } else { UIController.QRData = Data; UIController.Just_Hyperlink(); UIController.bt_en = true; } } else { UIController.QRData = Data; UIController.Just_Text(); UIController.bt_en = true; } } } else { Debug.Log("No QR code detected !"); } } catch (Exception e) { Debug.LogError(e.Message); } } } } if (count == 30) { count = 0; } }
IEnumerator Decode(WebCamTexture te) { while (true) { if (decoding && te != null) { orginalc = te.GetPixels32(); z = 0; // convert the image color data for (int y = H - 1; y >= 0; y--) { for (int x = 0; x < W; x++) { targetbyte[z++] = (byte)(((int)orginalc[y * W + x].r) << 16 | ((int)orginalc[y * W + x].g) << 8 | ((int)orginalc[y * W + x].b)); } } //RGBLuminanceSource luminancesource = new RGBLuminanceSource(targetbyte, W, H, RGBLuminanceSource.BitmapFormat.Gray8); PlanarYUVLuminanceSource planarYUV = new PlanarYUVLuminanceSource(targetbyte, W, H, 0, 0, W, H, false); var bitmap = new BinaryBitmap(new HybridBinarizer(planarYUV)); Result data; var reader = new MultiFormatReader(); data = reader.decode(bitmap); if (data != null) { { decoding = false; dataText = data.Text; Debug.Log(dataText + e_QRScanFinished.ToString()); e_QRScanFinished(dataText); } } else { yield return(new WaitForEndOfFrame()); Color[] color = te.GetPixels(); float res = 0; for (int i = 0; i < color.Length; i++) { res += (color[i].r + color[i].g + color[i].b) / 3; } res /= color.Length; for (int i = 0; i < color.Length; i++) { if ((color[i].r + color[i].g + color[i].b) / 3 < res) { color[i] = Color.black; } else { color[i] = Color.white; } } texTemp.SetPixels(color); texTemp.Apply(); data = DecodeByStaticPic(texTemp); if (data != null) { { decoding = false; dataText = data.Text; Debug.Log(dataText); e_QRScanFinished(dataText); } } } } yield return(new WaitForSeconds(0.5f)); } }