Important alert: (current site time 7/16/2013 7:33:13 AM EDT)
 

article

Read BarCodes in the Image & Get BarCode Region Information from Image

Email
Submitted on: 3/22/2013 7:45:29 AM
By: aspose_seo 
Level: Intermediate
User Rating: Unrated
Compatibility: C#, VB.NET
Views: 3445
 
     This technical tip shows how to read the image and get all the barcode regions, for all the recognized barcodes in the image. The barcode region is the part of the image that only contains the barcode itself. In a large image, it is possible that there are other texts or images along with the barcode.


 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				This technical tip shows how to read the image and get all the barcode regions, for all the recognized barcodes in the image. The barcode region is the part of the image that only contains the barcode itself. In a large image, it is possible that there are other texts or images along with the barcode. Getting the barcode region will separate the barcodes from other text/objects in the image by detecting their edges. First, we will read the BarCodes in the image using the BarCodeReader.Read() method. Then, we will get the region of the barcode using BarCodeReader.GetRegion() method, which will return an instance of type BarCodeRegion. We can then get the X and Y coordinates of the barcode using BarCodeRegion.Points property.
[C#]
 
// read code39 barcode from image
string image = "code39Extended.jpg";
BarCodeReader reader = new BarCodeReader(image, BarCodeReadType.Code39Standard);
// try to recognize all possible barcodes in the image
while (reader.Read()) {
// get the region information
BarCodeRegion region = reader.GetRegion();
if (region != null)
{
// display x and y coordinates of barcode detected
System.Drawing.Point[] point = region.Points;
Console.WriteLine("Top left coordinates: X = " + point[0].X + ", Y = " + point[0].Y);
Console.WriteLine("Bottom left coordinates: X = " + point[1].X + ", Y = " + point[1].Y);
Console.WriteLine("Bottom right coordinates: X = " + point[2].X + ", Y = " + point[2].Y);
Console.WriteLine("Top right coordinates: X = " + point[3].X + ", Y = " + point[3].Y);
}
Console.WriteLine("Codetext: " + reader.GetCodeText());
}
// close reader
reader.Close();
[VB.NET]
 ' read code39 barcode from image
Dim image As String = "code39Extended.jpg"
Dim reader As New BarCodeReader(image, BarCodeReadType.Code39Standard)
' try to recognize all possible barcodes in the image
While reader.Read()
	' get the region information
	Dim region As BarCodeRegion = reader.GetRegion()
	If region IsNot Nothing Then
		' display x and y coordinates of barcode detected
		Dim point As System.Drawing.Point() = region.Points
		Console.WriteLine("Top left coordinates: X = " & point(0).X & ", Y = " & point(0).Y)
		Console.WriteLine("Bottom left coordinates: X = " & point(1).X & ", Y = " & point(1).Y)
		Console.WriteLine("Bottom right coordinates: X = " & point(2).X & ", Y = " & point(2).Y)
		Console.WriteLine("Top right coordinates: X = " & point(3).X & ", Y = " & point(3).Y)
	End If
	Console.WriteLine("Codetext: " & reader.GetCodeText())
End While
' close reader
reader.Close()
More about Aspose.BarCode for .NET
- Homepage of Aspose.BarCode for .NET: http://www.aspose.com/.net/barcode-component.aspx
- Read more Technical Tips by Aspose.BarCode for .NET: http://www.aspose.com/docs/display/barcodenet/technical+articles 


Other 16 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.