I'm trying to leverage ZXing in an Android app to scan data matrixes. So far I'm successful with printed data matrixes such as this:
But other data matrixes, which are either printed by laser or punched into the material, have circle-looking marks —instead of square-looking ones.
These present a problem. The only app I've found capable of scanning this is QRDroid. This article says that QRDroid uses ZXing so I'm thinking if they can, there must be a way. Unfortunately QRDroid is not an open source project so I don't know how.
There's the possibility of course that QRDroid is using an algorithm to somehow transform the circled marks in to squared ones before they attempt to read the data matrix. I don't know anything about image manipulation in Java, so I can't imagine how this is done.
My question is whether there's a way to tweak ZXing to read this type of data matrix, or if there's any library I can use to manipulate the image to make it readable by ZXing.
Edit:
If I use an image editor -e.g. I used https://www.befunky.com- to and apply a blur of 10, then it looks like a normal printed data matrix and my scan works. How should I go about doing this in my Android app?
After some research I found out that this type of marking is not really considered a standard data matrix but rather referred to by the manufacturing industry as a DPM, which stands for "Direct Part Marking", although I've read other sources call it "Dot Peen Marking" or "Dot Peen Matrix"
I posted this same question on an already existing issue in the Zxing repository and this was the reply I got:
The problem is the
WhiteRectDetector
. It finds a white rectangle inside the code, similar to this issue. If you rotate the image slightly (say 10°) or you blur it as you did or you did a suitably sized pixel dilation followed by an erosion, you'll get something that should (mostly) be detectable.
Modifying the WhiteRectDetector
, to allow for dots rather than squares was not really an option for me due to deadlines, so I ended up switching from Zxing to Scandit, which is proven to be able to scan this.
Scandit is a proprietary library, but I haven't really found any other alternatives. You can get a trial license though. For those wanting to try it out to scan DPM's, the documentation is not very clear on how to enable scans for this symbology, so here's the trick.
In Android:
settings.getSymbologySettings(Barcode.SYMBOLOGY_DATA_MATRIX)
.setExtensionEnabled("direct_part_marking_mode", true);
In Objective-C:
[[settings settingsForSymbology:SBSSymbologyDatamatrix]
setExtension:@"direct_part_marking_mode" enabled:YES];