private void Scan()
 {
     try
     {
         Camera.GetPreviewBufferY(decoder.PreviewBufferY); //get the image
         result = decoder.Decode();                        //try to decode
         cancel = true;                                    //signal success
     }
     catch                                                 //decode was not successful
     { }
 }
Exemplo n.º 2
0
        private void ScanPreviewBuffer()
        {
            if (_luminance == null)
            {
                return;
            }

            _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
            // use a dummy writeable bitmap because the luminance values are written directly to the luminance buffer
            var result = _reader.Decode(dummyBitmap);

            Dispatcher.BeginInvoke(() => DisplayResult(result));
        }
        private void ScanPreviewBuffer()
        {
            if (_photoCamera == null)
            {
                return;
            }
            if (!_initialized)
            {
                return;
            }

            // Don't scan too frequently
            // Check the minimum time between frames
            // as well as the min time between continuous scans
            var msSinceLastPreview = (DateTime.UtcNow - _lastAnalysis).TotalMilliseconds;

            if ((DateTime.UtcNow - _lastAnalysis).TotalMilliseconds < Options.DelayBetweenAnalyzingFrames ||
                (_wasScanned && msSinceLastPreview < Options.DelayBetweenContinuousScans))
            {
                return;
            }

            if (!IsAnalyzing)
            {
                return;
            }

            _wasScanned   = false;
            _lastAnalysis = DateTime.UtcNow;

            try
            {
                _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
                var binarizer = new ZXing.Common.HybridBinarizer(_luminance);

                var binBitmap = new BinaryBitmap(binarizer);

                var result = _reader.decode(binBitmap);

                if (result != null)
                {
                    _wasScanned = true;
                    OnDecodingCompleted(result);
                }
            }
            catch (Exception)
            {
                // If decoding fails it will throw a ReaderException
                // and we're not interested in doing anything with it
            }
        }
Exemplo n.º 4
0
 private void ScanPreviewBuffer()
 {
     try
     {
         _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
         var binarizer = new HybridBinarizer(_luminance);
         var binBitmap = new BinaryBitmap(binarizer);
         var result    = _reader.decode(binBitmap);
         Dispatcher.BeginInvoke(() => DisplayResult(result.Text));
     }
     catch
     {
     }
 }
Exemplo n.º 5
0
 private void ScanPreviewBuffer()
 {
     try
     {
         _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
         var result = _reader.Decode(dummyBitmap);
         if (result != null) // BV line added
         {
             Dispatcher.BeginInvoke(() => DisplayResult(result.Text));
         }
     }
     catch
     {
     }
 }
Exemplo n.º 6
0
 private void ScanPreviewBuffer()
 {
     try
     {
         _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
         var result = _reader.Decode(_luminance);
         if (result != null)
         {
             Dispatcher.BeginInvoke(() => DisplayResult(string.Format("{0} - {1}", result.BarcodeFormat, result.Text)));
         }
     }
     catch
     {
     }
 }
Exemplo n.º 7
0
 private void ScanPreviewBuffer()
 {
     try {
         photoCamera.GetPreviewBufferY(luminance.PreviewBufferY);
         var binarizer = new HybridBinarizer(luminance);
         var binBitmap = new BinaryBitmap(binarizer);
         var result    = reader.decode(binBitmap);
         if (result != null)
         {
             Dispatcher.BeginInvoke(() => Synchronize(result.Text));
         }
     }
     catch {
     }
 }
Exemplo n.º 8
0
        private void ScanPreviewBuffer()
        {
            if (luminance == null)
            {
                return;
            }

            photoCamera.GetPreviewBufferY(luminance.PreviewBufferY);
            // use a dummy writeable bitmap because the luminance values are written directly to the luminance buffer
            var result = reader.Decode(dummyBitmap);

            if (result != null)
            {
                viewModel.Scanned(result.Text);
            }
        }
Exemplo n.º 9
0
        private Result AnalyseFrame()
        {
            if (_currentCamera == null)
            {
                return(null);
            }

            var width         = Convert.ToInt32(_currentCamera.PreviewResolution.Width);
            var height        = Convert.ToInt32(_currentCamera.PreviewResolution.Height);
            var previewBuffer = new byte[width * height];

            _currentCamera.GetPreviewBufferY(previewBuffer);

            Result result = _barcodeReader.Decode(previewBuffer, width, height, RGBLuminanceSource.BitmapFormat.Gray8);

            return(result);
        }
Exemplo n.º 10
0
 private void ScanPreviewBuffer()
 {
     try {
         _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
         var binarizer = new HybridBinarizer(_luminance);
         var binBitmap = new BinaryBitmap(binarizer);
         var result    = _reader.decode(binBitmap);
         if (result != null)
         {
             Dispatcher.BeginInvoke(() => DisplayResult(result.Text));
             var client = new WebClient();
             var sqrl   = new SqrlUrl(result.Text);
             var nonce  = SqrlUtils.CreateClientNonce();
             client.DownloadStringAsync(new Uri(sqrl.GetClientResponse(nonce)));
         }
     } catch {
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Scans the camera's preview buffer for a QR code.
        /// </summary>
        private void ScanPreviewBuffer()
        {
            int width  = (int)_camera.PreviewResolution.Width;
            int height = (int)_camera.PreviewResolution.Height;

            byte[] pixelData = new byte[width * height];

            _camera.GetPreviewBufferY(pixelData);

            var luminance = new RGBLuminanceSource(pixelData, width, height, RGBLuminanceSource.BitmapFormat.Gray8);
            var binarizer = new HybridBinarizer(luminance);
            var bitmap    = new BinaryBitmap(binarizer);
            var result    = new QRCodeReader().decode(bitmap);

            if (result != null)
            {
                Dispatcher.BeginInvoke(() => ProcessResult(result));
            }
        }
Exemplo n.º 12
0
        private void ScanPreviewBuffer()
        {
            try
            {
                _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
#if USE_ORIGINAL_IMPLEMENTATION
                var binarizer = new HybridBinarizer(_luminance);
                var binBitmap = new BinaryBitmap(binarizer);
                var result    = _reader.decode(binBitmap);
#else
                var result = _reader.Decode(_dummy);
#endif
                if (result != null)
                {
                    Dispatcher.BeginInvoke(() => DisplayResult(result.Text));
                }
            }
            catch
            {
            }
        }
Exemplo n.º 13
0
        private void ScanPreviewBuffer()
        {
            try
            {
                lblQR.Text = "No se detecta ningún código QR";
                _photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
                var binarizer = new HybridBinarizer(_luminance);
                var binBitmap = new BinaryBitmap(binarizer);
                var result    = _reader.decode(binBitmap);

                var scan = result.Text;
                lblQR.Text = "Escanea un código de Museos App";
                //System.Media.SystemSounds.Beep.Play();
                //System.Media.SystemSounds.Asterisk.Play();
                //SystemSounds.Beep.Play();

                /*Stream stream = TitleContainer.OpenStream("/Assets/cartel.mp3");
                 * SoundEffect effect = SoundEffect.FromStream(stream);
                 * FrameworkDispatcher.Update();
                 * effect.Play();*/
                //mediaElement.Play();

                var textId = scan.Remove(0, 42);
                System.Diagnostics.Debug.WriteLine("ID DEL TEXTO: " + textId);
                var textQR = scan.Remove(42, 1);
                System.Diagnostics.Debug.WriteLine("TEXTO DEL QR: " + textQR);

                if (textQR.Equals("http://museosapp.azurewebsites.net/Piezas/"))
                {
                    lblQR.Text = "Código QR correcto";
                    NavigationService.Navigate(new Uri("/InfoQR.xaml?id=" + textId, UriKind.Relative));
                    _timer.Stop();
                }

                Dispatcher.BeginInvoke(() => DisplayResult(result.Text));
            }
            catch
            {
            }
        }
Exemplo n.º 14
0
 /// <summary>
 /// Copies the luminance data for the current viewfinder frame into a buffer for further manipulation.
 /// </summary>
 /// <param name="pixelData">The YCrCb pixel data.</param>
 /// <remarks>
 /// This method is already protected and only called when the service is currently running.
 /// </remarks>
 protected override void GetPreviewBufferYFromCamera(byte[] pixelData)
 {
     _photoCamera.GetPreviewBufferY(pixelData);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Copies the luminance data for the current viewfinder frame into a buffer for further manipulation.
 /// </summary>
 /// <param name="pixelData">The YUV pixel data.</param>
 public void GetPreviewBufferY(byte[] pixelData)
 {
     _photoCamera.GetPreviewBufferY(pixelData);
 }
Exemplo n.º 16
0
        private void Detect()
        {
            if (isDetecting || !isInitialized)
            {
                return;
            }

            isDetecting = true;
            var stopwatch = Stopwatch.StartNew();

            try
            {
                // Update buffer size
                var pixelWidth  = (int)photoCamera.PreviewResolution.Width;
                var pixelHeight = (int)photoCamera.PreviewResolution.Height;
                if (buffer == null || buffer.Length != pixelWidth * pixelHeight)
                {
                    buffer = new byte[pixelWidth * pixelHeight];

                    // Create constant transformations instances
                    // Center at origin of the 256x256 controls
                    centerAtOrigin = Matrix3DFactory.CreateTranslation(-128, -128, 0);
                    // Swap the y-axis and scale down by half
                    scale = Matrix3DFactory.CreateScale(0.5, -0.5, 0.5);
                    // Viewport transformation
                    viewport           = Matrix3DFactory.CreateViewportTransformation(pixelWidth, pixelHeight);
                    matrix3DProjection = new Matrix3DProjection();
                    Txt.Projection     = matrix3DProjection;
                    Img.Projection     = matrix3DProjection;
                }

                // Grab snapshot
                photoCamera.GetPreviewBufferY(buffer);

                // Detect
                var dr = arDetector.DetectAllMarkers(buffer, pixelWidth, pixelHeight);

                // Draw the detected squares
                //bitmap.Clear();
                //ViewportOverlay.Source = bitmap;

                // Calculate the projection matrix
                if (dr.HasResults)
                {
                    // Calculate the complete transformation matrix based on the first detection result
                    var world = centerAtOrigin * scale * dr[0].Transformation;

                    // Calculate the final transformation matrix by using the camera projection matrix
                    var m = Matrix3DFactory.CreateViewportProjection(world, Matrix3D.Identity, arDetector.Projection, viewport);

                    // Apply the final transformation matrix to the TextBox
                    matrix3DProjection.ProjectionMatrix = m;

                    //// Draw the detected squares
                    //foreach (var r in dr)
                    //{
                    //   bitmap.DrawQuad((int)r.Square.P1.X, (int)r.Square.P1.Y, (int)r.Square.P2.X, (int)r.Square.P2.Y, (int)r.Square.P3.X, (int)r.Square.P3.Y, (int)r.Square.P4.X, (int)r.Square.P4.Y, Colors.Red);
                    //}
                }
            }
            finally
            {
                isDetecting = false;
                stopwatch.Stop();
                TxtDiag.Text = string.Format("{0} ms", stopwatch.ElapsedMilliseconds);
            }
        }
Exemplo n.º 17
0
        //オートフォーカスが完了したら呼び出される
        void camera_AutoFocusCompleted(object sender, CameraOperationCompletedEventArgs e)
        {
            //アマゾンからデータを取得するインスタンスにイベントハンドラを追加
            //AmazonWebService aws = new AmazonWebService();
            //aws.Comp += new AmazonWebService.GetItemInfoFromAmazonCompletedEventHandler(this.aws_GetItemInfoFromAmazonCompleted);

            //ItemData itemData = new ItemData();

            //cameraインスタンスがnullの場合は即return。そうしないと下の「プレビューフレームの取得」でnullreferenceexceptionが出てしまう。readTimerとのタイミングの問題か?
            if (camera == null)
            {
                return;
            }

            // コントロールへのアクセスを行うのでUIスレッドにて非同期で実行。UIへのアクセスは別のスレッドからはできないため。
            Dispatcher.BeginInvoke(() =>
            {
                // プレビューフレームの取得
                var luminanceSource = new PreviewFrameLuminanceSource((int)camera.PreviewResolution.Width, (int)camera.PreviewResolution.Height);

                camera.GetPreviewBufferY(luminanceSource.Buffer);

                // リーダーインスタンス生成
                var reader = new EAN13Reader();

                // バーコード解析用のBitmapを作成
                var binarizer = new HybridBinarizer(luminanceSource);
                var binBitmap = new BinaryBitmap(binarizer);


                Result result = null;
                try
                {
                    // バーコードの解析(デコード)を行う。
                    //resultにEANが入る。

                    result = reader.decode(binBitmap);
                }
                catch (ReaderException)
                {
                    // プレビューフレーム内にバーコードが見つからなかった場合
                    // 読み取り例外のReaderExceptionが発行されてしまう
                    TextBlock_Result.Text = "Can not read barcode.";
                    return;
                }
                catch (Exception ex)
                {
                    throw ex;
                }


                //読み取ったEANがデータベースに登録済みかチェック
                if (BookView.Exist(result.Text) != null)
                {
                    //登録済みの場合
                    TextBlock_Result.Text = result.Text + " is exists";
                }
                else
                {
                    //未登録の場合。Amazonへリクエスト
                    TargetEAN = result.Text;

                    aws = new AmazonWebService(result.Text);
                    //アマゾンからデータを取得するインスタンスにイベントハンドラを追加
                    aws.GetItemInfoFromAmazonCompleted += new AmazonWebService.GetItemInfoFromAmazonCompletedEventHandler(this.aws_GetItemInfoFromAmazonCompleted);
                    aws.GetItemInfo();
                }
            });

            //イベントを削除
            camera.AutoFocusCompleted -= camera_AutoFocusCompleted;
        }
Exemplo n.º 18
0
        public void GetImageTexture(int[] returnImage, byte[] imagePtr)
        {
            if (cameraInitialized && cameraReady)
            {
                if (returnImage != null)
                {
                    if (UseLuminance)
                    {
                        camera.GetPreviewBufferY(luminance);

                        for (int i = 0; i < returnImage.Length; ++i)
                        {
                            returnImage[i] = (int)(luminance[i] << 16 | luminance[i] << 8 | luminance[i]);
                        }
                    }
                    else
                    {
                        camera.GetPreviewBufferArgb32(returnImage);

                        byte r, g, b;
                        for (int i = 0; i < returnImage.Length; ++i)
                        {
                            r = (byte)(returnImage[i]);
                            g = (byte)(returnImage[i] >> 8);
                            b = (byte)(returnImage[i] >> 16);
                            returnImage[i] = (int)(r << 16 | g << 8 | b);
                        }
                    }
                }

                if (imagePtr != null)
                {
                    switch (format)
                    {
                    case ImageFormat.B8G8R8A8_32:
                        if (returnImage != null)
                        {
                            Buffer.BlockCopy(returnImage, 0, imagePtr, 0, imagePtr.Length);
                        }
                        else
                        {
                            try
                            {
                                if (UseLuminance)
                                {
                                    camera.GetPreviewBufferY(luminance);

                                    // Here, we assume the resizer is HalfResizer and instead of using
                                    // the HalfResizer to resize the pixel data, it's much faster to
                                    // do it here directly
                                    if (resizer != null)
                                    {
                                        int srcIndex  = 0;
                                        int destIndex = 0;

                                        for (int j = 0; j < cameraHeight; j += 2)
                                        {
                                            for (int i = 0; i < cameraWidth; i += 2, destIndex += 4)
                                            {
                                                imagePtr[destIndex]         = imagePtr[destIndex + 1] =
                                                    imagePtr[destIndex + 2] = luminance[srcIndex];
                                                srcIndex += 2;
                                            }

                                            srcIndex += cameraWidth;
                                        }
                                    }
                                    else
                                    {
                                        for (int i = 0, j = 0; i < imagePtr.Length; i += 4, ++j)
                                        {
                                            imagePtr[i] = imagePtr[i + 1] = imagePtr[i + 2] = luminance[j];
                                        }
                                    }
                                }
                                else
                                {
                                    if (color == null)
                                    {
                                        color = new int[imagePtr.Length / 4];
                                    }

                                    camera.GetPreviewBufferArgb32(color);

                                    for (int i = 0; i < imagePtr.Length; i += 4)
                                    {
                                        imagePtr[i]     = (byte)(color[i]);
                                        imagePtr[i + 1] = (byte)(color[i] >> 8);
                                        imagePtr[i + 2] = (byte)(color[i] >> 16);
                                    }
                                }
                            }
                            catch (Exception exp) { }
                        }
                        break;

                    default:
                        throw new GoblinException("Currently " + format + " is not supported");
                    }
                }
            }
        }