Get barcode region coordinates in image
You can define one or more rectangle region(s) in an image, and the barcode scanner library will scan barcodes from these defined regions only. It will really improve the
barcode scanning and reading speed and accuracy.
Defined region coordinates
To define a rectangle region inside an image, you need provide two points' coordinates of the rectangle inside the image.
- Point One (x1, y1), the top left corner of the rectangle.
- Point Two (x2, y2), the bottom right corner of the rectangle
The coordinate values are expressed as the percentage of the image width and height.
The origin (0,0) of the coordinate system is the upper left point of the image. The point (100, 100) is the bottom right point of the image.
The C# code below we have defined one rectangle region. It's top left corner (Point One) is the same position as the image upper left point. The rectangle width is the same as the image width, and the rectangle height is 20% of the image height.
The origin (0,0) of the coordinate system is the upper left point of the image. The point (100, 100) is the bottom right point of the image.
The C# code below we have defined one rectangle region. It's top left corner (Point One) is the same position as the image upper left point. The rectangle width is the same as the image width, and the rectangle height is 20% of the image height.
float x1 = 0; float y1 = 0; float x2 = 100; float y2 = 20; new SRegion(x1, y1, x2, y2);
The following C# sample code explains how to scan QR Codes from the top 20% of the image using C#.
ScanOptions opts = new ScanOptions(BarcodeType.QRCode); float x1 = 0; float y1 = 0; float x2 = 100; float y2 = 20; List<SRegion> regions = new List<SRegion>(); regions.Add(new SRegion(x1, y1, x2, y2)); opts.SetScanRegions(regions); BarcodeDetail[] datas = BarcodeScanner.Scan("qrcode-barcodes.png", opts);
Scan, read barcodes from an image specified region using C#?
To improve the reading speed, you can scan and recognize barcodes from specified region in an image using C# barcode generator.
- The below C# code will scan barcodes a rectangle region inside the barcode image.
List<SRegion> region = new List<SRegion>(); region.Add(new SRegion(0, 0, 50, 60)); string[] barcodes = BarcodeScanner.ScanRegions( "qrcode-barcodes.png", BarcodeType.QRCode, region);
You can further improve the reading speed by quickly reading a single barcode from the target area inside the image file.
- Use the method BarcodeScanner.ScanSingleBarcodeRegions() to quickly get a barcode from the target area in the image
List<SRegion> region = new List<SRegion>(); region.Add(new SRegion(0, 0, 50, 60)); string[] barcodes = BarcodeScanner.ScanSingleBarcodeRegions( "qrcode-barcodes.png", BarcodeType.QRCode, region);
How to read barcodes from image multiple target regions using C#?
Sometimes the barcodes are always printed on the certain areas inside a scanned document image. You can scan and read barcodes from those target areas quickly using C# barcode reader library.
- Here we will read barcodes from multiple specified regions in the image
List<SRegion> regions = new List<SRegion>(); regions.Add(new SRegion(0, 0, 50, 60)); regions.Add(new SRegion(100, 100, 50, 60)); string[] barcodes = BarcodeScanner.ScanRegions( "qrcode-barcodes.png", BarcodeType.QRCode, regions);
Common Asked Questions
How to scan specified regions inside the barcode image in C#?
You can define a rectangle inside an image by creating a
SRegion object with two points coordinates (x, y) values passed.
The two positions specify the positions of opposite vertices of the rectangle.
Then pass all defined SRegion objects to scan options by calling method SetScanRegions().
How to accurately define the region position information for barcode reading in C#?
The coordinate values are expressed as the percentage of the image width and height.
The origin (0,0) of the coordinate system is the upper left point of the image. The point (100, 100) is the bottom right point of the image.
You can use Windows installed picture application, such as Microsoft Paint to find the rectangle region coordinates.
Can I specify the barcode scanning directon on crop regions using C#?
Yes. You can specify the barcode scanning direction on the crop regions using C# Barcode Reader library.
You can specifiy the scanning directions through property
ScanDirection, call method SetScanRegions() to
define the crop regions inside the barcode image in C# project.
Will barcode scanning on partail image improve the barcode reading performance?
Yes. The barcode reading on partial image can improve the barcode reading performance by occupying less memory resources, and reducing image scanning time.
It will significantly improve the barcode reading speed on high resolution images.
Can I combine barcode crop region with other scanner options in C#?
Yes. You can customize and apply other scanning options (such as scan step interval, image filters, multithreading) with barcode crop regions scanning to
improve the reading performance in C# ASP.NET, MVC, WinForms and WPF applications.
When should I define crop regions for barcode reading?
Partial image barcode scanning is valuable when processing high resolution images, multiple pages document, low quality barcode images with noises, multiple barcodes
with different formats. Barcode scanning on specified crop regions will greatly improve the barcode reading performance using C# Barcode Reader component.