|
Dear naorem,
I did not write code for that. However, Code 39 Extended is implemented on top of Code 39, so you can use any Code 39 reader to read Code 39 Extended as well, my reader would be suitable for that.
This wikipedia article explains how it works:
http://en.wikipedia.org/wiki/Code_39[^]
Near the end of the article, you find a table specifying how the characters of "Full ASCII Code 39" translate back to the underlying basic Code 39 characters. For instance, to encode the * in Full ASCII Code 39 the characters /J in Code 39 are used.
Usually, the Code 39 checksum is also used with Full ASCII Code 39. The wikipedia article also explains how to calculate that checksum.
Best regards,
Berend
|
|
|
|
|
i have modified the code by using smart device framework ,it can solve the problem you pointed out that lockbits function in .net compact framework doesn't provide the ablity to lock parts of the image and run successful on windows mobile.
but i found another problem that the programe run quite slow on pocket pc SDK while it can run quickly on windows,
i think the problem may lies in the algorithm itself ,when the Variable "NumScans" is large it needs large amount of computation to determine the barcode region.
because in my program i only need to recognize one barcode once ,the situation is not so complex.so i am wondering whether i can improve the efficiency by determine the barcode region using my algorithm ,save it as the image to recognize, it is smaller than the original iamge and only with the barcode region. then i can call your algorithm to get the result by using a lower value of NumScans (for example numscans=30),in this way ,i think the running speed may be faster.
do you think this approach will works ,i want to ask u for some advice.
thanks!
|
|
|
|
|
Dear lulu831110,
I am afraid I do not own a Windows mobile device, so I can't really help you in optimizing the code specifically for that.
However, we did look into reducing CPU load in general. In our internal version of the c# code, we introduced a property QuickScan. If that is set and NumScans is set to a low value, the code will only examine a band of 8 pixels wide for each scan instead of examining all pixels in the image. If you know that the barcode is large compared to the image size, it will still be detected and examining less pixels takes proportionally less processing time. That version of the code can be downloaded here:
http://support.decos.nl/berend/clsBarcodeImaging-20100119.zip
Hope this helps,
Berend
|
|
|
|
|
Hi.
Just wanted to say that I find your gesture (of working so much and good and posting the source here) amazing.
Thank you very much.
Radu
|
|
|
|
|
Excellent work. 5 from me. Gave me a good product idea too - will update you if idea materializes.
Best Regards,
Parag Mehta
|
|
|
|
|
Should this algorith work for Code 39 Extended Borcode?
|
|
|
|
|
It doesn't. The code as published only recognizes the original Code 39 barcodes (digits, capital letters and some special characters) without check digit, as shown in this wikipedia article:
http://en.wikipedia.org/wiki/Code_39[^]
Best regards,
Berend
|
|
|
|
|
Hi !!!
The sample work perfect, congratulations !!!
But is Possible running in WM or Pocket PC ???
Thank
Regards
|
|
|
|
|
Hello Zorrani,
The code will not run unmodified on Windows Mobile. The problem is in this part:
private static histogramResult verticalHistogram(Bitmap bmp, int start, int end, ScanDirection direction)
{
PixelFormat pf = CheckSupportedPixelFormat(bmp.PixelFormat);
BitmapData bmData;
...
bmData = bmp.LockBits(new Rectangle(start, 0, end - start, bmp.Height), ImageLockMode.ReadOnly, pf);
...
}
In Windows Mobile, LockBits will not allow to lock a part of the image, but only the full image. To rewrite for Windows Mobile, you should lock the image in the caller of verticalHistogram and pass the locked BitmapData instead of the Bitmap object.
Hope this helps,
Best regards,
Berend
|
|
|
|
|
Thanks for you answer...
Try and coments you..
Zorrani
|
|
|
|
|
i have modified you code by using smart device framework ,it can solve the problem you pointed out that lockbits function in .net compact framework doesn't provide the ablity to lock parts of the image and run successful on windows mobile.
but i found another problem that the programe run quite slow on pocket pc SDK while it can run quickly on windows.
i think the problem may lies in the algorithm itself ,when the Variable "NumScans" is large it needs large amount of computation to determine the barcode region which costs lots of time.
because in my program i only need to recognize one barcode once ,the situation is not so complex.so i am wondering whether i can improve the efficiency by determine the barcode region using my algorithm ,save it as the image to recognize, it is smaller than the original iamge and only with the barcode region. then i can call your algorithm to get the result by using a lower value of NumScans (for example numscans=30),in this way ,i think the running speed may be faster.
do you think this approach will works ,i want to ask u for some advice.
thanks!
|
|
|
|
|
Could you give me your app let me debug?? my email is 237650651@qq.com
thanks you.
|
|
|
|
|
I've just tested your app, and that's very cool, Berend! Very well deserved prize!
Got my 5!
|
|
|
|
|
Could you give me the app to make the program run on Windows Mobile?(my email is 237650651@qq.com)
thank you
|
|
|
|
|
This is excellent work. I plan on trying this in a production project. The company processes periodicals in large amounts. They perfor to scan all the covers and then extract the barcode from it. Can you recommend an image scanner?
|
|
|
|
|
Basically for this software to work succesfully, any scanner that can scan at medium resolution (300 - 600 dpi) would be OK. Because the software needs the barcodes to be horizontally or vertically aligned, I would recommend some kind of automated paper transport for large volumes. However, most scanners with sheet feeders won't be able to handle a magazine unless you first separate it out in pages or sheets (by cutting it up or removing the staples). Is that what you plan to do? If not, perhaps a multifunctional copier that allows you to put the magazine cover on a glass plate might be more suitable.
For medium volume, we usually recommend the Canon DR series with sheet feeder, because they have an image reader element that can scan both sides at once, that simplifies paper handling for double sided scanning. Canon scanners are mostly sold for office environments, volume typically up to 3000 pages per day. For really high volume scanners, you might look at the high-end offerings of Fujitsu Siemens, Kodak or Agfa (note however that high volume scanners come at a hefty price). For multifunctionals, Ricoh is a popular choice among our customers.
|
|
|
|
|
I think what you have done is great, and I will give a 4 for doing so, but you are miles behind when it comes to barcode recognition software.
I have no affiliation to this product other than I found it to be the best barcode reader I could find for the money we had available.
http://www.dtksoft.com/barreader.php
There is a free trial and if you or someone else could surpass its functionality please let me know and I will happily switch to that solution.
TonyMac
|
|
|
|
|
I looked at the link you provided and it looked interesting. However the point of CodeProject (to me) is to learn how to code some things that I have never done before. Since I have never written any software to scan images for Bar Codes, but may have to at some point, I was very excited to see this article. It gives me a base to build on and enhance with my own development experience for a price that fits within my budget (free ). I really don't expect to find the equivalent of specialized commercial software on CodeProject. With 22 years of development experience - I can use this as a "fast-start" to shorten the learning curve and then do the rest myself. Kudos to the author for putting an interesting and helpful topic out there.
|
|
|
|
|
Agreed and sorry. I am in a commercial environment and need a solution yesterday so I look for code snippets that I can adapt into my programs. Hope the author keeps up his good work and also accepts my apologies
TonyMac
|
|
|
|
|
No hard feelings . Before, I decided to ignore your rant because it seemed like an blatant advertisement for a commercial product. When you post criticism, you could think a bit more about balancing and qualifying your statements. You say my code is "miles behind", that is a subjective opinion, without giving any indication where you find it lacking. In a good quality post, you would have pointed out clear deficiencies and provided evidence material to demonstrate them. Others have done just that, and it did help me to find bugs and improve the code.
What I wanted to say, even if my product is "miles behind", in my (not-so-humble ) opinion it is still the best you can get for free in this field. The reason I wrote this, is because all other open source image barcode readers I found were not good enough for my company's purpose. We now use it commercially to replace a closed source commercial product that was not 64 bit Windows compatible, and it works well enough for our purpose. I do eat my own dog food!
Finally, please note that I am a professional programmer with well over 20 years experience in coding and I donated several mandays of my time for free to the Code Project community in this and similar open source projects. That is not something to be dismissed so casually.
|
|
|
|
|
ok - you dont need to labour the point. I have already apologised, I was a dick sorry again.
Just wish I had several mandays I could easily contribute to this forum.
TonyMac
|
|
|
|
|
Dear Berend,
i am a newbie regarding the "barcode world".
I have read you code and i think that is is a great job: ASAP i start to rewrite it in C#.
I have a question: what kind of barcode reader I can buy to test the software and understand something more?
Could you recommend to me any barcode reader to use with your application?
I hope that you can help me
Begs
|
|
|
|
|
Dear Begs,
Please note that the barcode detection library is written in c#, so you shouldn't need much time to translate it to c#
The purpose of my code project is to read a barcode that is part of an image, there is no barcode reader required. The idea is that you have a printed page that has a barcode and some text on it, and that is input to the software using an image scanner (e.g., a flatbed scanner or a multifunctional scanner/copier). Document Management software (like the software that my employer sells) often uses barcodes to automatically route scanned documents.
POS Barcode Reader SoftwareFor handheld barcode readers, you would need a different kind of software. I have done a quick search of CodeProject and found these projects:
VBScan barcode software[^]
Controlling a Barcode Reader with POS for .NET[^]
Both of these projects use input from handheld barcode readers, also known as POS (Point Of Sales) barcode readers. This type of reader is usually connected to a serial port of your PC.
Barcode readers with keyboard emulationWhat you could also do is buy a barcode reader that emulates an USB keyboard. Then your software could be very simple: just write a program that has a single input text box, position the cursor in the input box and use the barcode reader. The output of the reader will appear in the textbox, just like normal keyboard output.
In my company, we use the Symbol LS 2208 barcode scanner for this kind of application. It is robust has good detection and reasonably cheap. Also, it is fully programmable. We programmed it to output ESC before the barcode digits and CR LF (Enter key) afterward, so that we can distinguish the barcode input from normal keyboard input and capture it without relying on a text box. For the .Net version of this "keyboard hook" interface, we based on this code project by George Mamaladze:
Processing Global Mouse and Keyboard Hooks in C#[^]
|
|
|
|
|
If barcodes will be surrounded by quiet zones, such that one can identify the beginning and end of any suspected barcode before one has to worry about trying to decode it, one can easily narrow down the possibilities for barcode type and compute bar/space widths without fancy histogram techniques.
For example, if there are 5n+4 bars between quiet zones (for some value n), the code might be an I2of5 barcode containing 2n+1 wide bars and 3n+3 narrow ones, along with 2n wide spaces and 3n+3 narrow ones. If one expects a 2:1 wide/narrow ratio, one can figure that the narrow bar width should be the total width of the black areas, divided by (7n+5). Likewise the narrow space width should be the total space of the white areas (not counting quiet zones) divided by (7n+3). If the number of bars isn't 5n+4, the code isn't I2of5, so there's no need to parse any further.
For Code39, the number of bars must be a multiple of five, and the bars should be processed in groups of five. There are two types of Code39 barcode (two wide and three narrow bars, plus one wide and three narrow spaces, or else five narrow bars, and three wide and one narrow spaces). If less than half the area within a symbol is white, it's the former style; if more than half, the latter. Once the style is determined, the wide/narrow widths for bars and spaces may be ascertained.
This approach is nicely amenable to things like Code128 which have multiple bar/space widths. Because the 'ink density' of Code 128 isn't constant, it's necessary to compute the module width based upon total symbol width, without using total white width and total black width separately. This makes it harder to factor out the effects of printers that cause black areas to come out wider or narrower than they should, but is much easier than using histograms.
|
|
|
|
|
Dear supercat9,
For any computing problem there are any number of solutions and you are of course welcome to publish your own. If you can improve on mine, you are welcome too - that is what I did with qlipoth's work and he with Liedblad's original version before me.
However, I have the feeling that you are trying to solve a problem that is already sufficiently solved (the published code already detects Code39, Code128 and EAN, also in bad quality scans), while not progressing in the problem that is still open: my code is not able to detect rotated barcodes very well, if at all. I tried a basic Hough transform and it works well only if the rectangle where the barcode is located is already known, so that the transform can be applied on an area without other image elements. My application however needs to detect multiple barcodes on pages that also have text and other graphics. Just applying a Hough transform over the full page often badly malfunctions.
If you look at this image, you may also notice a problem with the bar counting that you propose: actually in a rotated barcode, the scan line will not cover the full barcode and thus not return a complete bar count. What I plan to do is find partial barcodes (with the same approach that I use now) and if I find one, use that information to identify the rotated rectangle containing the barcode fragment that was found.
One more problem that you should be aware of: you cannot expect a 2:1 wide/narrow bar ratio. I have seen both 1.7 : 1 and 4:1 in Code 39. Also, in a bad scan the white bars are drawn too wide and the black bars too narrow (or the other way around), because the lighting is off. This causes a wide white bar to have a very different size from a wide black bar. This is the reason why the current version of the code does measurements for white and black bars separately. I had to later relax the constraints that I set on the ratio between white and black, to be able to pass more of our test material.
Finally, the reason why the code averages several rows of scan lines vertically is to compensate for noise. The image usually has white pixels in the middle of a black bar and black pixels in the background, and that will screw bar width calculations and bar counts if you consider just one scan line at the time. Unfortunately, the averaging technique is also a prime reason why the code is so sensitive for rotation: if you average two rotated bars vertically, the gap between them will be grayed out in the average scan line. I have tried to disable the averaging in good quality skewed scans and in that case detection actually improves. However, our customers manage to produce much more bad than good quality imaging, so the overall detection rate over our test set went down
Here is a sample of what I am up against: fail1a.tif. The current version of the code can just detect this barcode (with a bit of luck). Please zoom in on the image and notice in how bad shape the bars are ...
Best regards,
Berend
|
|
|
|
|