1

Is barcode scanning with an ESP32 possible? Is there an existing project, of a library that I could use?

Any idea how to go about it?

If not feasible, would it make sense to stream video from the ESP32's camera to a server and have the server detect the barcode, then signal success to the ESP32?


[Update] just to be clear, I want to make a portable device.

Also, I would prefer to use the ESP32's camera, rather than adding barcode reading hardware, although I won't rule that out, if it is the only solution

  • 2
    I'm guessing you'll have to narrow the scope down a bit... It's almost certainly possible: you can hook a camera into it, and you can access the pictures, so all that's left is to interpret the picture. What programming language(s) are you using for your project? – anonymous2 Nov 11 '19 at 18:23
  • 2
    Also which of many different types of barcode do you mean? There are a bunch of different standards just for the parallel lines before you get into any of the 2d variants. – hardillb Nov 12 '19 at 9:23
  • 1
    do you already know the reading method? ccd, laser, camera? – Marco Tulio Souza Nov 12 '19 at 14:17
  • 1
    Note that even though 1D barcode scanning using a camera is definitely possible, the performance is often relatively bad, those barcodes are really designed to be scanned wit a laser. 2D barcodes are on the other hand designed to be read using a camera. One of the best known barcode decoding libraries can be found at github.com/zxing/zxing – jcaron Nov 13 '19 at 6:25
  • 2
    See also stackoverflow.com/questions/8116990/… for more libraries. – jcaron Nov 13 '19 at 6:27
2

If you get a CCD or laser barcode module with RS232 or TTL output, it's pretty straightforward. The decoding is handled for you and you just need to read the serial data that it outputs.

  • Those look nice, although they cost more than a LilyGos TTGO Camera. What I ought to have made clear though, is that I want to make a portable device - I will update the question – Mawg says reinstate Monica Nov 13 '19 at 6:18
  • True, though the purpose built barcode modules do the decoding for you. If you want to do that part yourself, the OpenMV project may be of some help. – John S Nov 13 '19 at 18:41
2

I don't happen to have one of these with me, but I think you could have some fun with a laser and some CV.

Laser barcode scanners work by shining a laser line on the code and reading how the light reflects back to it. If you have a laser (I would recommend green, based on some 3D scanning tests in the past) and a camera, why not trying to make it happen?

Go ahead and 3D print a case for the ESPcam and the laser, tweak some camera parameters (exposure and brightness) and see if the image gets you some results.

barcode

The image above shows a barcode on a white background with a 7pt green line with 50% opacity on top of it. Note how the colors differ. Now setup some thresholds and you should be able to see only the light on top of the white parts. Voila, you are done.

That is a hardware solution, with some very simple computer vision. Thresholds and color filtering should be good for the ESP32 to handle. If you want a software-only solution, you can always convert the barcode to the vertical lines and play with their distance, which should also not be a problem for the LX6 beast (Or, would it?).

If it shows not feasible, I'm sure that you can do this with some python a RPi and stream the image data with some simple HTTP (base 64, you know). Server response gets you the data. With the expected delays and errors.

  • If you are using the camera, then the laser is probably overkill. The laser is useful if you have a sensor that receives the light as it is reflected during the scan: you get a signal with easy to detect edges. But if you use the camera, you just scan the image received (the more “scan lines” in various positions and directions the easier it is to find the barcode, but it adds to CPU usage). There are libraries that will do the scanning of the image (see my comments on the question), the only issue is to combine this with the image capture, but it should be pretty straightforward. – jcaron Nov 19 '19 at 8:38
  • I thought about the laser in order to reduce processing load. Onde might be able to tune camera parameter to get a better yet simpler image to process. – Marco Tulio Souza Nov 22 '19 at 11:29
  • I'm not sure how that would make the image better or simpler to process. When you scan with a camera, you have the issue that the edges are not "sharp" (as can be seen in your picture, there's a grey pixel between the white and the black areas), and I don't quite see how this would be different with the laser. The only use of a laser for barcode scanning is if you read back the signal as it is scanned and get the signal back directly, without sampling, to get the rising and falling edges. Another application is just to help the user point the camera correctly at the barcode. – jcaron Nov 22 '19 at 13:22
1

I suppose that I could just purchase a portable barcode reader with BlueTooth, read from that & use the ESP's WiFi to communicate with my server, but, realistically, I don't really see the point of the ESP32 in that scenario.

As a project, it would be fun to do it myself, and I still hope for alternatives, but, as an actual answer, I think that this particular wheel has already been invented.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.