dmtx / libdmtx Goto Github PK
View Code? Open in Web Editor NEWlibdmtx Library
License: Other
libdmtx Library
License: Other
Hi There,
I haven't been able to find any documentation on what the properties in dmtxDecodeSetProp()
do. Could you please share what they mean? For refererence, I know that there is a roughly 35x30 px datamatrix somewhere in the image. If I could pass this information along hopefully it can substantially speed up the scan.
switch(prop) {
case DmtxPropEdgeMin:
dec->edgeMin = value;
break;
case DmtxPropEdgeMax:
dec->edgeMax = value;
break;
case DmtxPropScanGap:
dec->scanGap = value; /* XXX Should this be scaled? */
break;
case DmtxPropFnc1:
dec->fnc1 = value;
break;
case DmtxPropSquareDevn:
dec->squareDevn = cos(value * (M_PI/180.0));
break;
case DmtxPropSymbolSize:
dec->sizeIdxExpected = value;
break;
case DmtxPropEdgeThresh:
dec->edgeThresh = value;
break;
/* Min and Max values arrive unscaled */
case DmtxPropXmin:
dec->xMin = value / dec->scale;
break;
case DmtxPropXmax:
dec->xMax = value / dec->scale;
break;
case DmtxPropYmin:
dec->yMin = value / dec->scale;
break;
case DmtxPropYmax:
dec->yMax = value / dec->scale;
break;
default:
break;
}
Cheers
This library works very well with recognizing DataMatrix.
But, is there any way to extract rectangle bounding it?
I understand that dmtxRegionFindNext function return potential barcode areas.And dmtxDecodeMatrixRegion will extract the code from these candidate areas.
Below is my implemented code using libdmtx and opencv.
Thank you in advance.
` cv::Mat img = cv::imread(files[i], cv::IMREAD_GRAYSCALE);
DmtxImage *dImg = dmtxImageCreate(img.data, img.cols, img.rows, DmtxPack8bppK);
DmtxDecode *dDec = dmtxDecodeCreate(dImg, 1);
DmtxRegion *dReg = dmtxRegionFindNext(dDec, NULL);
std::string qrcode;
cv::Mat disp;
cv::cvtColor(img, disp, CV_GRAY2BGR);
if (dReg != NULL)
{
DmtxMessage *dMsg = dmtxDecodeMatrixRegion(dDec, dReg, DmtxUndefined);
qrcode = std::string((char*)dMsg->output);
cv::Point p1(dReg->topLoc.X, dReg->topLoc.Y);
cv::Point p2(dReg->rightLoc.X, dReg->rightLoc.Y);
cv::Point p3(dReg->bottomLoc.X, dReg->bottomLoc.Y);
cv::Point p4(dReg->leftLoc.X, dReg->leftLoc.Y);
//cv::line(disp, cv::Point(p1.x, p1.y), cv::Point(p2.x, p2.y), cv::Scalar(0, 0, 255), 2);
//cv::line(disp, cv::Point(p2.x, p2.y), cv::Point(p3.x, p3.y), cv::Scalar(0, 0, 255), 2);
//cv::line(disp, cv::Point(p3.x, p3.y), cv::Point(p4.x, p4.y), cv::Scalar(0, 0, 255), 2);
//cv::line(disp, cv::Point(p4.x, p4.y), cv::Point(p1.x, p1.y), cv::Scalar(0, 0, 255), 2);
cv::circle(disp, p1, 4, cv::Scalar(255, 0, 0), 2);
cv::circle(disp, p2, 4, cv::Scalar(0, 255, 0), 2);
cv::circle(disp, p3, 4, cv::Scalar(0, 0, 255), 2);
cv::circle(disp, p4, 4, cv::Scalar(255, 255, 0), 2);
}
cv::imshow("DataMatrix", disp);`
Does anyone have an idea why I cannot read this QR code using libdmtx software? I dont think the quality of the image is that bad... https://i.ibb.co/FnQkcSL/platedmtrx.png
I think dmtxEncodeDataMatrix
should free the image->pxl
buffer if the DmtxEncode
struct is re-used, e.g.:
unsigned char str[] = "30Q324343430794<OQQ";
DmtxEncode *enc;
enc = dmtxEncodeCreate();
dmtxEncodeDataMatrix(enc, strlen(str), str);
dmtxEncodeDataMatrix(enc, strlen(str), str);
dmtxEncodeDestroy(&enc);
Here the image
from the first call gets overwritten: https://github.com/dmtx/libdmtx/blob/master/dmtxencode.c#L222
The call to dmtxEncodeDestroy
only deletes the second pixel buffer in my example above, see: https://github.com/dmtx/libdmtx/blob/master/dmtxencode.c#L70
I'd suggest to call dmtxImageDestroy
and free
ing the pixel buffer in the dmtxEncodeDataMatrix
function if an image
is present from a previous call.
install ImageMagick-6.9.9-37-Q8-x64-dll.exe -> C:\Program Files
open libdmtx-0.7.2\project\visualc9\libmtx.sln using Visual studio 2012
for dmtxread, dmtxwrite project,
3.1 Attribute > C/C++ > normal: C:\Program Files\ImageMagick-6.9.9-Q8\include
3.2 Attribute > Linker > normal: C:\Program Files\ImageMagick-6.9.9-Q8\lib
3.3 Attribute > Linker > input: CORE_RL_magick_.lib, CORE_RL_Magick++.lib, CORE_RL_wand.lib
and then compile...
error LNK2019: __imp__MagickGetImagePixels ...
I need your help, advanced thank you.
How do i get notified about FNC1 (232) symbols?
This issue was originally opened on the pylibdmtx wrapper, and it was suspected that it was a MacOS issue, however a little more probing suggests that this is not a platform-dependent issue.
Commit e4c0a74 introduced changes to the datastructures used by libdmtx. This means that any downstream tools that were compiled against an old version of libdmtx will break in strange ways.
Going forward Iit might be good to use a standard versioning scheme (e.g. semantic versioning). At the very least we should be bumping the SONAME whenever backwards-incompatible changes are made.
@msva
For auto-detecting the best illumination of the barcode-image (by the "business" S/W) it would be nice to return the error-counter from the decoding, eg (and removing the non-used argument "fix"):
extern DmtxPassFail
//RsDecode(unsigned char *code, int sizeIdx, int fix)
RsDecode(unsigned char *code, int sizeIdx, int* errorCount )
...
repairable = RsFindErrorLocatorPoly(&elp, &syn, blockErrorWords, blockMaxCorrectable, errorCount );
-> where:
static DmtxBoolean
RsFindErrorLocatorPoly(DmtxByteList *elpOut, const DmtxByteList *syn, int errorWordCount, int maxCorrectable, int* errors )
...
// The number of error codewords aded as an output parameter
*errors = lambda;
return (lambda <= maxCorrectable) ? DmtxTrue : DmtxFalse;
}
I am using the python wrapper of libdmtx: pylibdmtx. And I have been struggling to read some of my data matrices which looked pretty decent in terms of quality. I did quite few enhancement like cv2.fastNlMeansDenoisingColored, cv2.threshold and so on. With these improvements I have had some success, but still missing quite few readings. It was funny that I could read some of my blurred, partly damaged data matrices, but missing good ones. It was rather a random behavior to be honest.
Until I learned that decode function takes quite a few number of parameters:
decode(
image,
timeout=None,
gap_size=None,
shrink=1,
shape=None,
deviation=None,
threshold=None,
min_edge=None,
max_edge=None,
corrections=None,
max_count=None,
)
BUT there are not documentations what these arguments are. Some surely can be guessed, but others I could not guess what values to put in. A better documentation would be really appreciated. The reason I emphasize having one that, in my case, I came across this post in stackoverflow, and shrink was one recommended to play with. I started seeing magic. I basically, out of blue, screened some values shrink = np.arange(1,10)
and I could read the data matrices that I was struggling with. The problem is that now it is not fixed shrink value, sometimes higher value, sometimes lower! I have to scan for each reading this range!
This bring to the significance of knowing more about arguments of this function!
I have noticed that when attempting to decode a particular image (which does not contain a Datamatrix) libdmtx
will kill the current process with exit code 40.
The error is seen when using the pylibdmtx wrapper. Even though the presence of this bug could indicate bad usage of libdmtx
by the wrapper, I am opening the issue here as well, as I believe this to be a bug in libdmtx itself.
OS: Debian GNU/Linux testing (buster) x86_64
libdmtx version: 0.7.4
(reported by apt info
as 0.7.4-2+b1
Python version: 3.6.0
pylibdmtx version: 0.1.7
PIL version: 5.0.0
Run the following in a Python interpreter:
from PIL import Image
from pylibdmtx import pylibdmtx
pylibdmtx.decode(Image.open('bad_image.png'))
with the following image saved as bad_image.png
in the current working directory;
An error should be raised at the Python level
Python process exits with code 40
It seems that DecodeSchemeBase256 calls exit()
when it detects a problem.
I note that removing calls to exit
and assert
is on the roadmap for the 0.8.0 release. I would imagine that removing at least this call to exit
would require deciding how DecodeSchemeBase256
should handle error conditions (e.g. returning a null pointer) and plumbing this choice through all the call sites. If given a bit of guidance I would be willing to implement this.
Tested with last source code, when trying to dmtxread the attached image, libdtmx tries to decode a datamatrix which doesn't exist, find an invalid sequence and an assert is triggered :
#0 0x00007ffff6b4e1d7 in raise () from /lib64/libc.so.6
#1 0x00007ffff6b4f8c8 in abort () from /lib64/libc.so.6
#2 0x00007ffff6b47146 in __assert_fail_base () from /lib64/libc.so.6
#3 0x00007ffff6b471f2 in __assert_fail () from /lib64/libc.so.6
#4 0x0000000000409e90 in PushOutputWord (msg=0x6372e0, value=-1)
at dmtxdecodescheme.c:128
#5 0x000000000040a1b5 in DecodeSchemeAscii (msg=0x6372e0,
ptr=0x6371f2 "\372$\255\071;\340", dataEnd=0x6371f3 "$\255\071;\340")
at dmtxdecodescheme.c:226
#6 0x0000000000409d5f in DecodeDataStream (msg=0x6372e0, sizeIdx=0,
outputStart=0x0) at dmtxdecodescheme.c:60
#7 0x0000000000408f91 in dmtxDecodePopulatedArray (sizeIdx=0, msg=0x6372e0,
fix=-1) at dmtxdecode.c:402
#8 0x0000000000408f10 in dmtxDecodeMatrixRegion (dec=0x634af0, reg=0x63afd0,
fix=-1) at dmtxdecode.c:359
#9 0x0000000000401ad9 in main (argc=3, argv=0x7fffffffdde8) at dmtxread.c:162
In DecodeSchemeAscii at dmtxdecodescheme.c:226 a codeword=0 is found which can't happen in a valid datamatrix :
225 else if(codeword <= 128) {
226 PushOutputWord(msg, codeword - 1);
227 }
In PushOutputWord at dmtxdecodescheme.c:128 assertion fails due to the invalid value=-1
125 static void
126 PushOutputWord(DmtxMessage *msg, int value)
127 {
128 assert(value >= 0 && value < 256);
129
130 msg->output[msg->outputIdx++] = (unsigned char)value;
131 }
The following minimal image triggers this fatal abort (tested with dmtxread -n test1.png).
Could we have a new release of libdmtx so that the issue shared in #21 is resolved. The patch has already been integrated into the master.
How do you prepend the GS1 FNC1 data codepoint (232) to a datamatrix?
Doesn't seem to be any char value that translates to the FNC1 as a start data codepoint.
Hi my friend, I've used this wonderful library in my paper for an algorithm,
Since I've used this library, I wanna know how to cite this work.
I've noticed that many papers have already cited your work but the reference is different,
So can you provide my the correct citation style (in bibtex is the best)?
Thanks so much if you could help.
After building libdmtx 0.7.5 (using "./autogen.sh && ./configure && make") the test-binaries fails to build, eg:
$ make check
...
gcc -DHAVE_CONFIG_H -I. -I../.. -Wshadow -Wall -pedantic -ansi -g -O2 -MT simple_test.o -MD -MP -MF .deps/simple_test.Tpo -c -o simple_test.o simple_test.c
simple_test.c: In function ‘main’:
simple_test.c:41:4: error: C++ style comments are not allowed in ISO C90
//dmtxEncodeSetProp( enc, DmtxPropPixelPacking, DmtxPack16bppRGB );
^
simple_test.c:41:4: error: (this will be reported only once per input file)
simple_test.c:61:32: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
fprintf(stdout, "width: \"%d\"\n", width);
^
simple_test.c:62:32: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
fprintf(stdout, "height: \"%d\"\n", height);
^
simple_test.c:63:32: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
fprintf(stdout, "bpp: \"%d\"\n", bytesPerPixel);
^
simple_test.c:65:4: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
for (int i=0; i<width*height; i++){
^~~
simple_test.c:65:4: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
simple_test.c:84:45: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
fprintf(stdout, "msg->arraySize : \"%d\"\n", msg->arraySize );
^
simple_test.c:85:45: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
fprintf(stdout, "msg->codeSize : \"%d\"\n", msg->codeSize );
^
simple_test.c:86:45: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
fprintf(stdout, "msg->outputSize: \"%d\"\n", msg->outputSize);
^
simple_test.c:87:18: warning: implicit declaration of function ‘sqrt’ [-Wimplicit-function-declaration]
int oned = sqrt(msg->arraySize);
^~~~
simple_test.c:87:18: warning: incompatible implicit declaration of built-in function ‘sqrt’
simple_test.c:87:18: note: include ‘<math.h>’ or provide a declaration of ‘sqrt’
simple_test.c:87:7: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
int oned = sqrt(msg->arraySize);
^~~
simple_test.c:88:16: warning: declaration of ‘i’ shadows a previous local [-Wshadow]
for (int i=0; i<msg->arraySize; i++){
^
simple_test.c:65:13: note: shadowed declaration is here
for (int i=0; i<width*height; i++){
^
simple_test.c:88:7: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
for (int i=0; i<msg->arraySize; i++){
^~~
simple_test.c:95:7: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
for (int j=0; j<msg->codeSize; j++){
^~~
simple_test.c:99:7: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
for (int k=0; k<msg->outputSize; k++){
^~~
Makefile:353: recipe for target 'simple_test.o' failed
make[3]: *** [simple_test.o] Error 1
Using gcc 6 (on a debian 9):
$ gcc --version
gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516
Hello, great library! I found myself wondering how hard it would be to implement the Data Matrix Rectangular Extension, which adds some more rectangular symbol dimensions. Adding the support to ZXing was apparently quickly done. I'm not sure what other changes than adding the new symbol dimensions here are needed, though.
Hello,
I'm following the readme for mingw and I'm trying to install this library on windows.
The first instruction in the readme is to run ./configure, but there is no file in the source code folder named configure. So I ran ./configure.ac and then I get the error ./configure.ac: line 1: syntax error near unexpected token [libdmtx]
Please advice, how do you install this?
Hi,
I'm having trouble getting the library to decode the attached image - or indeed any image.
My code is quite simple:
// Load the image
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
HBITMAP mBkgImg = mLoadImage(L"i:\\RedTitan\\Test002.png");
BITMAP bm2 = { 0 };
GetObject(mBkgImg, sizeof(bm2), &bm2);
LONG cx2 = bm2.bmWidth;
LONG cy2 = bm2.bmHeight;
GdiplusShutdown(gdiplusToken);
DmtxImage* img = dmtxImageCreate((unsigned char *)bm2.bmBits, bm2.bmWidth, bm2.bmHeight, DmtxPack32bppBGRX);
DmtxDecode* dec = dmtxDecodeCreate(img, 1);
dmtxDecodeSetProp(dec, DmtxPropImageFlip, DmtxFlipNone);
DmtxRegion* reg = dmtxRegionFindNext(dec, NULL);
if (reg != NULL) {
DmtxMessage* msg = dmtxDecodeMatrixRegion(dec, reg, DmtxUndefined);
All seem to be going well, all the objects are returned as expected but msg is always returned as NULL.
I wonder if I am missing an important step but looking at the samples that I have found all seems fine!
Any suggestions would be much appreciated.
Martin
Hi,
We saw that sometimes the error correction does not run as we expected:
We had these codewords as input : {140, 142, 229, 130, 229, 130, 182, 130, 72, 156, 53, 144, 110, 15, 22, 55, 12, 171}, that is seen as {174, 142, 229, 130, 229, 130, 182, 131, 72, 156, 61, 144, 110, 47, 50, 63, 12, 155}, so we have some errors (starting from the end 0 2 3 4 7 17 index, 0 index being the last code), but while detection/correction, we get "5 errors / 5 correctables" out of RsFindErrorLocatorPoly, which seems to be a normal behaviour because it seems to maximise the look for loop at the maximum number of correctable errors.
Then we run RsFindErrorLocations and this function seems to fail when there are toomuch errors (it finds less error locations tat the number of correction to get and the function outs an error.
But in our case, 5 locations are found (but we had 7 errors), and locations are loc[0] = 2 loc[1] = 4 loc[2] = 15 loc[3] = 16 loc[4] = 15 : we find 5 errors but two at the same index and get a successful output, but with a wrong codeword array:
we expected: 10 12 99 00 99 00 52 00
but we extract : 44 12 99 00 99 00 52 01
Thanks for your help!
When I used pylibdmtx to do data matrix decode I got below error message.Is there anyone can help me on this issue. Thanks.
---> How can I create "dmtx shared library"?
from pylibdmtx.pylibdmtx import decode
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pylibdmtx/pylibdmtx.py", line 10, in
from .wrapper import (
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pylibdmtx/wrapper.py", line 70, in
_dmtxVersion = libdmtx_function('dmtxVersion', c_char_p)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pylibdmtx/wrapper.py", line 58, in libdmtx_function
return prototype((fname, load_libdmtx()))
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pylibdmtx/wrapper.py", line 39, in load_libdmtx
LIBDMTX = dmtx_library.load()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pylibdmtx/dmtx_library.py", line 47, in load
raise ImportError('Unable to find dmtx shared library')
ImportError: Unable to find dmtx shared library
I use the libdmt with pylibdmtx into my python program, and this program will process dm code every day. Recently I find it cannot read datamatrix after running for several days. But if I test the same image or restart the program, it works well again. Anyone meet the similar problem?
PrintPattern seemingly tries to set RGB components no matter what the image format is.
If the user includes the '31' (unlatch to ASCCII) character in the input, EDIFACT barcode is corrupted. It should unlatch to ASCII first and then encode character in a different scheme, or at least throw an error.
$ echo -en 'OH\037CRAP' | dmtxwrite -o test.png -e e ; dmtxread test.png
OHG��
$ echo -en 'OH\037CRAP' | dmtxwrite -o test.png -e e ; dmtxread test.png -c
d:240
d:060
d:135
d:195
d:072
d:020
d:031
d:129
...
I have successfully been able to decode dmtx codes in 8 bit RGB images using DmtxPacked24bppRGB, however I haven't been able to process 16 bit grayscale images. I tried using DmtxPackCustom and setting the bytesPerPixel value in the dmtx image to 16, but I still get no codes found.
In the README there is a link to www.libdmtx.org, which now points to a web page about German powertools. There are also links to an old wiki, a repository on sourceforge, and some company's website that does not even load, in my browser.
I also notice that the Debian packages pull from the (AFAICT defunct) sourceforge repository, however the Brew packages do use this Github repo.
@msva what is the status of this GitHub fork; are you in contact with the original authors?
If this is now the official libdmtx repo, maybe we could clean up the README a bit to reflect this.
Hi, actually its a pretty cool library. when i'm trying to decode the datamatrix code it works perfectly. I face an issue while detecting and drawing a rectangle aroung the datamatrix code, actually the rectangle was not perfectly bounding aroung the code it detects a different portin of the image and decodes the code perfectly. Is there any suugestions for perfect bounding rectangle aroung the code.
I see a note from a 2006 release "Add in de-skew transformation" and I see a deskew struct, but I'm having trouble finding any notes about how it works or how to use it.
I would like to figure out how to use contiguous lines or block markers (like QR codes) to find edges or angles and deskew an image.
I am trying to use the Java version of this library, however any use attempts have failed with Java not finding the appropriate symbols: java: symbol lookup error: /home/angelin/git/dmtx-wrappers/java/native/libdmtx.so: undefined symbol: dmtxImageCreate
. This is when trying to run either the GUIExample or the CLIExample.
I am creating the issue here since the repository seems more active. The wrappers repo hasn't been updated since 2014.
I want to note that Python's wrappers, obtained with pip, are working perfectly fine.
I'd also like to note that this will be used in an embedded system later, so compilation is a must, no ready-to-go binaries.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.