Re: reading barcode from scanned images
Cool
Sure. As I see it, we will need to take the following steps
1. Load BMP file into binary array
2. Read the header to get the offset to the "image"
3. Get to a "good" row (ie, one that has the bars).
4. Translate bytes into a string of W and N (wide and narrow)
5. Translate W/N string into numbers and letters.
Step 3 will be a little tricky. We'll get to that point eventually,
but as a preview, we'll need to skip over possible non-barcode "rows"
(eg, at top of image in Post #28), so we'll read several rows to assure
that they are the "same". Further, if the image is slightly tilted, as it
is in Post #28, then some additional "massaging" will be in order.
Step 5 is going to be tricky, too. If we successfully get that far,
I'm afraid you'll be on your own.
So, to begin with step 1 ---
Could you please post any or all of the images from your Post #33 as
attached files (as opposed to attached images). That way I too can
download the file.
I am assuming that they are BMP format. If they aren't, could you
instead please attach one that is in a BMP format.
Spoo
2 Attachment(s)
Re: reading barcode from scanned images
Quote:
Originally Posted by
Spoo
Cool
Sure. As I see it, we will need to take the following steps
1. Load BMP file into binary array
2. Read the header to get the offset to the "image"
3. Get to a "good" row (ie, one that has the bars).
4. Translate bytes into a string of W and N (wide and narrow)
5. Translate W/N string into numbers and letters.
Step 3 will be a little tricky. We'll get to that point eventually,
but as a preview, we'll need to skip over possible non-barcode "rows"
(eg, at top of image in Post #28), so we'll read several rows to assure
that they are the "same". Further, if the image is slightly tilted, as it
is in Post #28, then some additional "massaging" will be in order.
Step 5 is going to be tricky, too. If we successfully get that far,
I'm afraid you'll be on your own.
So, to begin with step 1 ---
Could you please post any or all of the images from your Post #33 as
attached files (as opposed to attached images). That way I too can
download the file.
I am assuming that they are BMP format. If they aren't, could you
instead please attach one that is in a BMP format.
Spoo
Here is the problem
Re: reading barcode from scanned images
coolcurrent4u,
As I said in post #25, you don't have to read a bitmap.
Just load the image (bmp, jpg, etc.) in a picturebox, then use the code in the link I posted, here it is again: http://www.vbforums.com/showpost.php...5&postcount=14
It's very easy:
Code:
Dim BMP_Data() AS Byte
Dim pWidth AS Long
Dim pHeight AS Long
Picture1.ScaleMode = vbPixels
pWidth = Picture1.ScaleWidth
pHeight = Picture1.ScaleHeight
GetBitmapData Picture1.hDC, pWidth, pHeight, BMP_Data
Is that so hard ?
When you loop through the array, you will also need to know the Width in Bytes of each scan line of the image, there is a function for that also, use it like this:
Code:
Dim BPSL As Long
BPSL = BytesPerScanLine(pWidth, 24)
Then you can read and/or modify the data in the BMP_Data array
And to display the modified data, you can just do this (but I don't think you need this for your project):
Code:
SetBitmapData Picture1.hDC, pWidth, pHeight, VarPtr(BMP_Data(0))
2 Attachment(s)
Re: reading barcode from scanned images
Cool
Sorry for delayed reply.
For some reason, I could not get either of your
BMP files to work.
However, here is a BMP file that I was able to
get to "work".
-- the upper image is the BMP
-- the lower image is a snapshot of an array I created
Attachment 76540
Attachment 76541
Let me know if you are still interested.
EDIT: For some reason, I notice that there is no
"Attached Images" caption and border around my images.
I'm not sure why -- I hope I uploaded them properly.
Let me know if you don't see any images.
Spoo
Re: reading barcode from scanned images
this is cool Spoo
Please am very intrested. How did you generate this output? in the immediate window using debug.print or how?
Re: reading barcode from scanned images
Cool
It is actually a snapshot of the Locals Window (sorry, I seem
to have cropped too much at the top). It contains the contents
of the array aaChr4(), and as you can see, begins at element 82
and hence, shows essentally the bottom 1/3 of the BMP.
Elements 0 thru 81 are similar to element 82 (ie, the upper region,
just showing the bars).
As to the "how" ...
1. I read the BMP file into array aaBit (a binary array), per Post #7.
2. I then extracted the offsets to various file sections, per the link in Post #24
3. I then put the "rows" of the image into a 1-D array, aaChr1().
4. Several transformations later, ie, aaChr4(), the Locals Window image of above.
I'm being somewhat coy here (ie, I'm not directly posting code), as I think that
you'll profit from effort you put into it yourself. There are a few surprises along
the way, and I wouldn't want to deprive you of them !
But I will explain this ... by the time I get to aaChr4, I have consolidated the
3 bytes-per-pixel (ie, the RGB components) into essentially 1 character-per-pixel.
Emphasis on "essentially"
-- dark pixels are shown as "8"
-- light pixels are shown as ".."
to align things and deal with the proportional spacing of Arial font used by
Locals Window. This was an expediency to get a quick result, and is not
intended to be the final step. Natch, as the goal is to read "rows", a
truly 1 character-per-pixel approach would need be adopted.
Hope that gets you started.
Spoo
Re: reading barcode from scanned images
Good work Spoo, thanks for your effort. I appreciate it.
Could you please post the code?
Besides, how to you now convert the bars to alphanumeric characters?
Re: reading barcode from scanned images
Quote:
Originally Posted by
coolcurrent4u
Could you please post the code?
Come on good buddy, we did that dance back in Posts #22 and #23.
What have you got so far?
Spoo
Re: reading barcode from scanned images
i have done something based on what you have posted before.
I'll upload it later today or tomorow