c# scanner scan barcode - c#

I'm now trying to create an web application or software, whatever, by c# to achieve a process -- when I scan a piece of paper(contains barcode) using my office scanner, the software or web application will automatically get the the barcode content.
I'm now a bit confusing of how to achieve this. Anyone has idea about this? Do I need to call the Scanner's API or something? My scanner brand is EPSON.
Thanks in advance.

This will give you a general idea on creating your desired application
At first you have to capture the image from the scanner using TWAIN or using Windows image Acquistion
Then you have to read the bar code from the image.You can use some third party libraries to read the barcode.
Some of the articles that will help you..
http://www.codeproject.com/Articles/1376/NET-TWAIN-image-scanner
Using a scanner without dialogs in C#
http://www.codeproject.com/Articles/10734/Reading-Barcodes-from-an-Image-II

Barcode scanners automatically decode the Bars and return a string! Try using in Ms-Word or Notepad. The string is followed by return in some barcode readers.

Actually we do not normally do it coz it will dramatically reduce application performance. Let's say for example, if you scan two files at the same time, the time gap is too short, scanner won't have the mechanism to separate two files.
Thus my suggestion of this would be create a web app, manually upload the document and process.

With Asprise C# VB.NET Scanning & Imaging SDK, you can acquires images from TWAIN WIA scanners and extract barcodes at the same time - even if your scanner doesn't support reading barcode natively.
The code snippet below saves the scanned images into a multi-page PDF file at the current working directory and prints the barcodes recognized:
Result result = new AspriseImaging().Scan(new Request()
.SetTwainCap(TwainConstants.ICAP_PIXELTYPE, TwainConstants.TWPT_RGB) // color mode
.SetTwainCap(TwainConstants.ICAP_SUPPORTEDSIZES, TwainConstants.TWSS_USLETTER) // paper size
.SetRecognizeBarcodes(true)
.AddOutputItem(new RequestOutputItem(AspriseImaging.OUTPUT_SAVE, AspriseImaging.FORMAT_PDF).SetSavePath(".\\${TMS}${EXT}")),
"select", true, true);
List<string> barcodes = result == null ? null : result.GetBarcodes();
Console.WriteLine("Barcodes: " + string.Join(";\n", barcodes == null ? new string[0] : barcodes.ToArray()));
// Alternatively, request can be specified using the following JSON:
{
"twain_cap_setting" :
{
"ICAP_PIXEXELTYPE" : "TWPT_RGB",
"ICAP_SUPPORPORTEDSIZES" : "TWSS_USLESLETTER"
},
"recognize_barcodes" : true,
"output_settings" : [ {
"type" : "save",
"format" : "pdf",
"save_path" : ".\\${TMS}${EXT}" } ]
}
Download and run the reading barcodes while scanning from TWAIN scanners demos here.
Refer to the developer's guide to C# VB.NET scanning and imaging API for more details.

Related

Ways to Count a Printer With a Built in Scanner as a Scanner for WIA

I am currently working with some OMR software that will take and scan sheets from a scanner, and then write their information to a text file. For getting available local scanners, I am using WIA; to get these scanners, I would use some bit of code like
public List<ScannerInfo> GetWiaDevices()
{
WIA.DeviceManager mgr = new WIA.DeviceManager();
List<ScannerInfo> retVal = new List<ScannerInfo>();
foreach (WIA.DeviceInfo info in mgr.DeviceInfos)
{
if (info.Type == WIA.WiaDeviceType.ScannerDeviceType)
{
foreach (WIA.Property p in info.Properties)
{
if (p.Name == "Name")
retVal.Add(new ScannerInfo(((WIA.IProperty)p).get_Value().ToString(), info.DeviceID));
}
}
}
return retVal;
}
Now, I am working with something that is technically a printer (and that Windows reads as a printer) -- the Konica Minolta Bizhub 282, I believe. Unfortunately, if (info.Type == WIA.WiaDeviceType.ScannerDeviceType) doesn't recognize printers with built in scanners as scanners, so when I run this code checking for local scanners, the printer doesn't show up.
Is there a way to make printers with built-in scanners show up on the list, and furthermore, to make them usable as scanners in C#? Thanks for your time!
It doesn't look like this printer has a scanner that will show up as a twain or WIA source.
There certainly are no drivers on the Minolta site for it (only PCLx and PostScript Print Drivers).
The way this scanner works is to use a SMB network share setup by your IT admin. The printer will dump scanned documents there after it is configured properly.
You can read about it here .
If I somehow missed something.. (I don't think I did), ALL of the manuals for that printer are here

How to read text from 'simple' screenshot fast and effectively?

I'm working on a small personal application that should read some text (2 sentences at most) from a really simple Android screenshot. The text is always the same size, same font, and in approx. the same location. The background is very plain, usually a few shades of 1 color (think like bright orange fading into a little darker orange). I'm trying to figure out what would be the best way (and most importantly, the fastest way) to do this.
My first attempt involved the IronOcr C# library, and to be fair, it worked quite well! But I've noticed a few issues with it:
It's not 100% accurate
Despite having a community/trial version, it sometimes throws exceptions telling you to get a license
It takes ~400ms to read a ~600x300 pixel image, which in the case of my simple image, I consider to be rather long
As strange as it sounds, I have a feeling that libraries like IronOcr and Tesseract may just be too advanced for my needs. To improve speeds I have even written a piece of code to "treshold" my image first, making it completely black and white.
My current IronOcr settings look like this:
ImageReader = new AdvancedOcr()
{
CleanBackgroundNoise = false,
EnhanceContrast = false,
EnhanceResolution = false,
Strategy = AdvancedOcr.OcrStrategy.Fast,
ColorSpace = AdvancedOcr.OcrColorSpace.GrayScale,
DetectWhiteTextOnDarkBackgrounds = true,
InputImageType = AdvancedOcr.InputTypes.Snippet,
RotateAndStraighten = false,
ReadBarCodes = false,
ColorDepth = 1
};
And I could totally live with the results I've been getting using IronOcr, but the licensing exceptions ruin it. I also don't have $399 USD to spend on a private hobby project that won't even leave my own PC :(
But my main goal with this question is to find a better, faster or more efficient way to do this. It doesn't necessarily have to be an existing library, I'd be more than willing to make my own kind of letter-detection code that would work (only?) for screenshots like mine if someone can point me in the right direction.
I have researched about this topic and the best solution which I could find is Azure cognitive services. You can use Computer vision API to read text from an image. Here is the complete document.
How fast does it have to be?
If you are using C# I recommend the Google Cloud Vision API. You pay per request but the first 1000 per month are free (check pricing here). However, it does require a web request but I find it to be very quick
using Google.Cloud.Vision.V1;
using System;
namespace GoogleCloudSamples
{
public class QuickStart
{
public static void Main(string[] args)
{
// Instantiates a client
var client = ImageAnnotatorClient.Create();
// Load the image file into memory
var image = Image.FromFile("wakeupcat.jpg");
// Performs label detection on the image file
var response = client.DetectText(image);
foreach (var annotation in response)
{
if (annotation.Description != null)
Console.WriteLine(annotation.Description);
}
}
}
}
I find it works well for pictures and scanned documents so it should work perfectly for your situation. The SDK is also available in other languages too like Java, Python, and Node

BarcodeScanner found but not possible to connect with Windows.Devices.PointOfService

I have created a watcher to connect to BarcodeScanner using Windows.Devices.PointOfService
var watcher = DeviceInformation.CreateWatcher(BarcodeScanner.GetDeviceSelector());
var id = "";
watcher.Added += async (sender, information) =>
{
id = information.Id;
var barcodeScanner = await BarcodeScanner.FromIdAsync(id);
...
}
information parameter contains all data releted to my barcodeScanner, but when i try to get it with FromIdAsync is always null.
Those are data contained into information
- information {Windows.Devices.Enumeration.DeviceInformation} Windows.Devices.Enumeration.DeviceInformation
EnclosureLocation null Windows.Devices.Enumeration.EnclosureLocation
Id "\\\\?\\HID#VID_0536&PID_02E1&MI_01#c&d907bf5&0&0000#{c243ffbd-3afc-45e9-b3d3-2ba18bc7ebc5}\\POSBarcodeScanner" string
IsDefault false bool
IsEnabled true bool
Kind DeviceInterface Windows.Devices.Enumeration.DeviceInformationKind
Name "3800G" string
+ Pairing {Windows.Devices.Enumeration.DeviceInformationPairing} Windows.Devices.Enumeration.DeviceInformationPairing
+ Properties {System.__ComObject} System.Collections.Generic.IReadOnlyDictionary<string, object> {System.__ComObject}
+ Native View 0x1d148140 <Information not available, no symbols loaded for Windows.Devices.Enumeration.dll> IUnknown *
This device is listed as enabled to be accessed with POS.
Where I'm wrong? I have tried also to create the watcher behind a button click, but nothigs change.
If the model name of the scanner you are using is "3800G" as in the question code, it may not be supported by Windows.Devices.PointOfService.
A list of supported models is below.
Supported Point of Service Peripherals
If you want to use it with Windows.Devices.PointOfService, please change it to the model described in this.
In Addition:
Unified POS standard and Windows® Embedded for Point of Service are OPOS/POS for.NET/JavaPOS API. It is not Windows.Devices.PointOfService API.
That model is not listed on Honeywell's site.
And, sales agencies in Japan may be displayed as sales ended. Probably it is an old model. It is better to switch to a new model.
For example, the USB HID Bar code scanner mode setting is described on page 21 of the detailed manual of 1900 series.
If this mode setting description is not in the 3800G manual, you can not use Windows.Devices.PointOfService API on 3800G.
If you can set it, you will be able to use it if you install a device driver corresponding to this mode.
#Luigi Saggese,
You must first put this scanner into USB HID Barcode Scanner Mode. Please see Page 1-3 of the Honeywell 3800g Users Guide for the programming code to put the scanner into this mode.
Once the scanner is in this mode, you should see a POS Barcode Scanner node in Windows Device Manager. The specific scanner will show up in Device Manager as POS HID Barcode Scanner since it is using an in-box class driver which supports the USB HID POS Scanner protocol. At this point it should work with your Watcher.
Terry Warwick, Microsoft

How to Develop a Desktop Application using C# which can Utilize USB Barcode Scanner. How to start

I have gone through Microsoft Developer website. There is development using pointOfService. but I am getting error in:
scanner = await BarcodeScanner.GetDefaultAsync();
SAYING: IAsyncOperation does not contain definition for GetAwaiter
May be I am missing any Reference but not sure which one.
If there is any other way to do please share it. And one Important thing I am developing Windows Desktop Application.
Complete Code is:
private async Task<bool> CreateDefaultScannerObject()
{
if (scanner == null)
{
UpdateOutput("Creating Barcode Scanner object.");
scanner = await BarcodeScanner.GetDefaultAsync();
if (scanner != null)
{
UpdateOutput("Default Barcode Scanner created.");
UpdateOutput("Device Id is:" + scanner.DeviceId);
}
else
{
UpdateOutput("Barcode Scanner not found. Please connect a Barcode Scanner.");
return false;
}
}
return true;
}
You cannot use the BarcodeScanner class in a Desktop application. This class is part of the new "Universal Windows Platform" that only works in Universal Apps for Windows 8 and Windows 10.
The easiest way to use barcode scanners is by having them emulate the keyboard. You can configure the scanners to send prefix and suffix characters before and after the actual code.
Usually, you will configure "Return" as the suffix and some special code that the user usually never enters as the prefix.
If you process all keypress events in your application you can react to receiving the configured prefix by clearing and setting focus to a textbox that is meant to receive the barcode. The barcode is then (via the keyboard emulation) inserted into the textbox and return is pressed.
The textbox can then process this the same way as if a user had entered the code into the textbox and pressed Return.
For some more details and code samples see http://www.codeproject.com/Articles/296533/Using-a-bar-code-scanner-in-NET

How to read QR code in windows phone 8.1 app development?

I want to scan QR code in windows phone app 8.1.I am tried lot of examples but no one is work for me.
Below code I tried but no use
xmlns:jwqr="clr-namespace:JeffWilcox.Controls;assembly=JeffWilcox.Controls.QR"
in xaml
<jwqr:QRCodeScanner
ScanComplete="QRCodeScanner_ScanComplete"
Error="QRCodeScanner_Error"
Width="400"
Height="400"/>
It showing error like:
The name "QRCodeScanner" does not exist in the namespace
"clr-namespace:JeffWilcox.Controls;assembly=JeffWilcox.Controls.QR"
And tried the link this one also not working for me. But in this camera not scan the code. Please anyone help me. If you have any other links. I am trying this last 3 days but till now I am not getting any answer correctly. Plase help me.......
I'm not recommending but i've used Zxing Library for Barcode/QR code scanning and that worked for me.
here's a sample how to use this library:
// create a barcode reader instance
IBarcodeReader reader = new BarcodeReader();
// load a bitmap
var barcodeBitmap = (Bitmap)Bitmap.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;
}
Documentation and other demoClient is available here
Ask if you require more code. Hope that helps..!

Categories