-2

Please, how can I scan barcode using webcam of my PC? I used ZXing Nugget and could only generate (write) QR Code but not read. These are my C# code

XAML

    <Page
        x:Class="Bembem_Samples.FrontScan"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:Bembem_Samples"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">

        <Grid Background ="CadetBlue">
            <StackPanel
                HorizontalAlignment="Center"
                VerticalAlignment="Center">
                <Button x:Name="testZxing" Click="testZxing_Click"/>
                <TextBlock
                    FontSize="18"
                    x:Name="txtStatus"/>
                <TextBlock
                    FontSize="18"
                    x:Name="txtResult"
                    Margin="0,4,0,0" />
            </StackPanel>
        </Grid>
    </Page>

C# Code

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Runtime.InteropServices.WindowsRuntime;
    using Windows.Foundation;
    using Windows.Foundation.Collections;
    using Windows.Media;
    using Windows.Media.Capture;
    using Windows.Storage;
    using Windows.Storage.Streams;
    using Windows.UI.Popups;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Controls.Primitives;
    using Windows.UI.Xaml.Data;
    using Windows.UI.Xaml.Input;
    using Windows.UI.Xaml.Media;
    using Windows.UI.Xaml.Media.Imaging;
    using Windows.UI.Xaml.Navigation;
    using ZXing;

    // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

    namespace tinoTestField
    {
        /// <summary>
        /// An empty page that can be used on its own or navigated to within a Frame.
        /// </summary>
        public sealed partial class CamElement : Page
        {
            public FrontScan()
            {
                this.InitializeComponent();

            }
            private void testZxing_Click(){
                IBarcodeReader reader = new BarcodeReader();
                // load a bitmap - *Bitmap* is not recognised by the library
                var barcodeBitmap = (Bitmap)Image.LoadFrom("C:\\sample-barcode-image.png");
                // detect and decode the barcode inside the bitmap
                var result = reader.Decode(barcodeBitmap);
                // do something with the result
                if (result != null)
                {
                  txtDecoderType.Text = result.BarcodeFormat.ToString();
                  txtDecoderContent.Text = result.Text;
                }
          }
       }
    }

Please, how can I scan barcode using webcam of my PC? I used ZXing Nugget and could only generate (write) QR Code but not read.

Also if anyone knows how I can resolve this or suggestion on how to open webcam using captureElement.

Thanks in advance.

Bembem
  • 249
  • 4
  • 12
  • 1
    Do you really expect us to write the program for you? Do it yourself – musefan Jun 12 '18 at 14:42
  • Hi @musefan, am only asking for directions. Doing it myself will certainly make me learn better. Do you know any resources? – Bembem Jun 12 '18 at 14:47

1 Answers1

0

So basically what you have here is single image reader, if you want to read from webcam you have to write a lil code for that.

Steps to follow

  1. Get Library which can stream webcam data (like Aforge) Aforge Example
  2. grab an image from that stream.
  3. process that image to find the barcode
  4. Repeat

Note: This just an overview that how can you do that there is a lot of things you have to consider while building barcode reader.

Update:-

While researching on this I found Github Repo this is not complete solution but will give a good leap in what you want to achieve

Mihir Dave
  • 3,954
  • 1
  • 12
  • 28
  • Okay, @Mihir Dave. I will read the article and revert my findings. Thank you. – Bembem Jun 12 '18 at 14:56
  • Hi @Mihir Dave. Takes for your effort. I really appreciate. My basic issue is to view an image on UWP (desktop) without launching the camera. I have read and still very confused. I used https://learn.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.Controls.CaptureElement and it's did not work and so did many other I read. Creating Barcode works. – Bembem Jun 12 '18 at 17:10
  • so you are facing issue in accessing webcam? and what do you mean by "without launching the camera" ? – Mihir Dave Jun 12 '18 at 17:48
  • Normally, I launch Camera on my PC, Capture image as a bitmap and save (as base64 string). I want to see the image on the app before clicking a button to capture. – Bembem Jun 12 '18 at 18:01
  • so basically you need to see live webcam stream in your app right? – Mihir Dave Jun 12 '18 at 19:31
  • @Tino Not to clear what you are doing to use the webcam and it should be another issue. Please clarify the issue on a new thead with more details about it so that we can help you in the right direction. Thanks. – Breeze Liu - MSFT Jun 14 '18 at 02:16
  • so Tino as BreezeLiu-MSFT Liu mentioned you can open a new thread where you can put your new question and waht you tried so far. regarding live stream webcam access Aforge is the answer. i have personally used it and it's awesome so post a new question if you're facing some issue with that – Mihir Dave Jun 14 '18 at 17:32
  • Mihir Dave and @BreezeLiu-MSFT Liu. Thank you very much. I can use CaptureElement now. I did enable it on package.appmanifest. Remain to decode Qr-Codes. Thank you again. – Bembem Jun 20 '18 at 11:59
  • Great... @Tino. – Mihir Dave Jun 20 '18 at 12:21