|
I downloaded this project and copied the code into a Windows Mobile Project. The only things that wouldn't build were the flip and rotate parts, which I removed. But the app now produces run time errors.
|
|
|
|
|
The error is on this line:
BitmapData bmData = bmp.LockBits(new Rectangle(0, startheight, bmp.Width, endheight - startheight), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
Debug shows that the values of the items are (0, 0, 640, 48 - 0) and it says "Value does not fall within the expected range" (System.ArgumentException in System.Drawing.dll)
|
|
|
|
|
That is due to a "by design" difference in behavior of LockBits (read: Microsoft botched up the mobile implementation of LockBits and refuse to fix it). See this msdn forum thread:
Bitmap.LockBits Does Not Behave as Expected
To make it work in Windows Mobile, what you could do is to move the bmp.LockBits to VScanPageCode39 and lock the full image before calling ReadCode39 for each band. You would need new overloads for functions ReadCode39 and verticalHistogram that accept a BitmapData instead of Bitmap parameter.
P.S. It might amuse you to read what Steve Ballmer recently had to say about the Windows Mobile programming team: http://wmpoweruser.com/?p=8170
|
|
|
|
|
Hi friends I am trying to read values from barcode images can any help me how to achieve this one i am c#.net
|
|
|
|
|
Hello,
If I make a print screen from the image the example provides and paste it to Paint and then save it as a tiff image, for instance, I will still be able to read the barcode.
However, if I open Word and crete a barcode usinf a 30f9 font and than make a printscreen and paste it to Paint and, finally, save it to a tiff (or other image type) file, despite your program will find a barcode while performing a scan page, it get get the right data...
So, my question is, how are you generating the codebar images?
Is it necessary to include any sp+ecial character on the value of the codebar?
Thank you
|
|
|
|
|
To what i read in the sourcecode. The application only works for one ratio of the 3of9 barcode.
3of9 barcodes can have a barcoderatio. This is the ratio between the thinnest and the thickest barcode line.
So when you generate the barcode in word see if you can change the barcoderatio.
|
|
|
|
|
I had the same problem and looked into the cause. Please consider this enlargement from the leading edge of a barcode, that I generated using a Code39 TrueType font in MS Word. I used the MS Document Image Writer printer to create a tiff image directly from Word, then enlarged and measured it in Photoshop:
Click to view image in new window
The first dark bar encountered has a width of 4 pixels, being a "narrow" bar. The software assumes that the first bar encountered will always be a dark "narrow" bar and uses that to determine if other bars are "narrow" or "wide". A barcode is seen as a pattern of bars of alternating width in light and dark color.
Here is one example of the code that does that determination:
if ((i-nBarStart) > (nNarrowBarWidth))
{
As you can see, the comparison will go wrong because the "narrow" bars following the first one are not 4 pixels, but 5, 6 or even 7 pixels wide. All bars > 5 pixels will be regarded as "wide" bars by the software, and the barcode is thus not correctly recognized. Word consistently makes the white gaps wider than the black bars in a barcode font, hence the problem is so prominent when Word is used to create barcode bitmaps.
To solve the problem, I have applied a small change:
private const float WIDEFACTOR = 2.0f;
...
int nBarWidth = i - nBarStart;
if (nBarWidth > nNarrowBarWidth * WIDEFACTOR)
{
Now with this version of the code, a bar will not be considered to be "wide" unless it is at least twice as wide as the measured narrow bar width. In the example, only bars >= 9 pixels will be considered to be wide. With this change the barcode created by Word is correctly recognized. I have re-run the software against all my test images and I believe that the change does not negatively affect the detection rate.
|
|
|
|
|
Anyone care to give me some pointers on how to upgrade this project to read code 128 barcodes?
thanks in advance
|
|
|
|
|
First,Thanks for your code.
I have some question for you.
How to dectect a barcode if its image is too bad or it's a blur image?
How to indentify barcode region in a large image?
Rich + Handsome = Amorous
|
|
|
|
|
> How to dectect a barcode if its image is too bad or it's a blur image?
I don't think you can. Some image sharpening MIGHT help, but I don't know how to implement that. Blurred barcodes are like blurred pictures. If the information isn't there in the first place, nothing you can do will get it.
> How to indentify barcode region in a large image?
As said in postings earlier:
In my experience, most barcodes begin and end with *
However, I have also seen a model with a fixed number of characters, which is more difficult to parse out.
Also remember that there may be text on the same scan line as your barcode, so your result in the arraylist may be something like:
kjh4#u*SURPRISE*fvj
Still, it's pretty easy to parse out useful text from this.
The more scans you do, the more likely you are to pick up a barcode, but the longer it will take to scan.
|
|
|
|
|
I myseft use this code to recognize: Code 93, Code 128, EAN, UPC...
You know:
They're not belong to wide/narrow bar.
Most of these barcodes don't start with "*" character.
I have to archive accurate distance between bars. Maybe, that's why It's right in some cases.
Would you like to give me some comment?
Anyway, thanks for your reply.
|
|
|
|
|
I've had this code in production for quite sometime now, what I have noticed is that if you scan just the portion of the image that the barcode should be in it increases your chances of reading the barcode. I have noticed some other barcode commerical barcode reading libraries that have an algorithmn to find the "region" in to which the barcode is located. I'm not sure how one would go about coding this but it would defiantly increase the percentage of successful barcode reads.
|
|
|
|
|
Hi,
Do you have C# code for generating barcode based on the format that will read it by your program?
If you have any idea, please pass it on to me..
Thanks in advance.
Regards
M.Kumar
|
|
|
|
|
I don't. However, codeproject seems to. check out
http://www.codeproject.com/cs/media/GenCode128.asp
|
|
|
|
|
Hi Kumar
Do generate Bar code, At very first we need to add reference..."barcodelib"
And rest of the code goes like this (To generate and print)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.PointOfService;
using System.IO;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Image = null;
BarcodeLib.Barcode b = new BarcodeLib.Barcode(textBox1.Text);
b.EncodedType = BarcodeLib.TYPE.CODE39;
Image barcode = b.Encode();
pictureBox1.Image = barcode;
label1.Text = b.RawData;
barcode.Save("C:\\Barcode.jpg");
//System.Drawing.Imaging.EncoderParameters encodeParams= new System.Drawing.Imaging.EncoderParameters();
//encodeParams.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.ScanMethod, textBox1.Text);
//printDialog1.ShowDialog();
// printDialog1.PrinterSettings.PrinterName="HP LaserJet P2015 Series PCL 5e";
// printDialog1.AllowSomePages = true;
// System.Drawing.Printing.PrintDocument doctoPrint = new System.Drawing.Printing.PrintDocument();
//printDialog1.Document = doctoPrint;
//doctoPrint.Print();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
System.Drawing.Font printFont = new System.Drawing.Font
("Arial", 35, System.Drawing.FontStyle.Regular);
// Draw the content.
e.Graphics.DrawString("Hi", printFont, System.Drawing.Brushes.Black, 10, 10);
}
}
}
If u have idea about how to interface digital camera to our windows application...plz revert back
Regards
Kiran
|
|
|
|
|
I justed wanted to let you know that I have successfully implemented this library and I have found that increasing the num of scans of the image greatly increases the success rate of finding a valid barcode. I also added a checksum function that makes certain that the code is valid.
Thanks,
Curtis
|
|
|
|
|
Could you post your improved source and demo here so everyone will benefit?
Thanks
We can't stop asking "WHY!!"
|
|
|
|
|
I increased the number of scans that it did while doing a full path scan and I also added my own function in VB.net to check for the check sum digit. I have control of the barcode printing so I know that my barcodes use a check digit for accuracy.
Code:
ImgBar.FullScanPageCode39(AryCodes, bmpPage, 200)
#Region "CheckSum Code"
Public Function CheckSum(ByVal Code As String) As Boolean
Dim I As Integer
Dim sum As Integer
Dim SingleChar As String
Dim ChkVal As Integer
Dim ModChk As Integer
Dim CodeEnd As Integer
CodeEnd = Code.Length - 2
If CodeEnd > 0 Then
For I = 0 To Code.Length - 2
SingleChar = Nothing
ChkVal = 0
SingleChar = Code.Chars(I).ToString
'Get the value of the character
ChkVal = CheckValAry(SingleChar)
sum += ChkVal
Next
'Get the last character
Dim CheckChar As String
Dim TrailingChkVal As Integer
'Get the last character of the barcode text
CheckChar = Code.Chars(Code.Length - 1)
TrailingChkVal = CheckValAry(CheckChar)
'The mod of the sum should equal the value of the check sum character
ModChk = sum Mod 43
If ModChk = TrailingChkVal Then
Return True
Else
Return False
End If
Else
Return False
End If
End Function
Public Function CheckValAry(ByVal pChar As Char) As Integer
pChar = UCase(pChar)
Dim AryChar() As Char = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "-", ".", " ", "$", "/", "+", "%"}
Return AryChar.IndexOf(AryChar, pChar)
End Function
#End Region
|
|
|
|
|
How tolerant is the scanner of angled rotations?
|
|
|
|
|
It appears that it is not very tolerant the barcodes being at an angle, does anyone have any suggestions as to how to improve this library to correct that?
Thanks,
Curtis
|
|
|
|
|
I'm trying to read the barcode using my barcodereader, but nothing happens. My reader makes an bib, so I guess it manage to read the code, but I would really like that to make the messagebox popup showing my barcode converted to alphanumeric...
Anyone know how to do that?
Thanks, Ole
|
|
|
|
|
Yes, use the FullScanPageCode39 method and it will pass you back an array list of values that it found. You can look through that arrylist and display it back to the user in a messagebox if you like.
Curtis
|
|
|
|
|
This code isn't realy intended for use with a barcode reader, and I'm really not sure if they are in any way compatable, as I don't have a reader to play with.
This topic was intended for finding barcodes in images, such as scanned pages.
Sorry that I can't be more helpful.
|
|
|
|
|
Yeah, this code is pretty much completely intolerant of angles, as it's meant for scanned documents... and if someone's scanning documents diagonally, they should be beaten severely.
I think that an angled reader would be a great deal more difficult to build, however if the number of scans were increased dramaticly (well above 50) then at least one of the scans should read a barcode as long as the angle isn't severe enough that no scan gets across the whole barcode.
Barcode scanners in Supermarkets have dozens of scan lines at differant angles to accomplish this.
|
|
|
|
|
I just want to know in barcode is usually start by * and end by * ... so can we aim in ArrayList if found string start with * and * is a content ?
|
|
|
|
|