Open ssnegir opened 2 years ago
You will need to provide the image at least
The original images which cannot be recognised are: I have tried to make them smalle. in grayscale, BW...nothing works. Therefore, I have tried to modify them up to extend it was possible using Matlab:
I would appreciate for the help. Regards
additionally to above images, I have tried this one, with less defects:
By the way, the python code is:
`from pylibdmtx.pylibdmtx import decode from PIL import Image
result = decode(Image.open(path)) if len(result) == 0: decoded_data=0 else:
decoded_data=float(result[0].data)`
What kind of 2D-code is it? I was able to produce the matrix below using contours, but I can't decode it (neither using online tools).
Dear @jepperaskdk, this is the datamatrix, which contain only the number of the processed part. At first I was trying to solve the problem 1) by adjusting the intensity/contrast of the initial image using matlab. It did not work. Than 2) I have used circle detection function to find all circles and their positions on the image. With that, I was able to draw the circles position in a separate image (mimicking the real photo). This image python function did not decode...An only when I draw squares (solution 3) instead of circles using a matlab, python was able to decode the matrix. Important: What I found important, is that the "quite" zone around the datamatrix has to be clean from some defects and has to be large enough. Drawbacks of my solution: My code (find below) draw the code and save it as separate image, which has to be opened one more time to send it to python for decoding. If someone has a more elegant solution, I would be very much appreciate. The original image can be taken from my above comment!
`clear all close all dt = datetime('now', 'TimeZone', 'local') epochT=convertTo(dt,'epochtime','Epoch','1970-01-01','TicksPerSecond',1000)
Importing the images
Impath="C:\Users\sns\Documents\P-Frames\Defektenanerkenung\MatlabScripts\Tets_photos\QR-code_X2.tif" % Impath="C:\Users\sns\Documents\P-Frames\Defektenanerkenung\MatlabScripts\Tets_photos\WIN_20220919_15_03_13_Pro.jpg"
Impath="C:\Users\sns\Documents\P-Frames\Defektenanerkenung\MatlabScripts\Tets_photos\tripple3.jpg" im=imread(Impath); % imshow(im);
%improving the contrast use is optional % sigma=13; % im=imflatfield(im,13); % im= imadjust(im,[0.35 0.55],[]); % imshow(im); Finding the circles and drawing rectangles % finding the circles on the photo [centers, radii, ~] = imfindcircles(im,[10 35],'Sensitivity',0.9,'ObjectPolarity','bright'); %commented line to verify the circles on top of the image after initial %placing circles for verification: first accesment (optional) %uncomment the bottom line to verify %viscircles(centers, radii,'EdgeColor','b');
% deviation measuring
% function to remove wrong detected circels idx=radii<mean(radii)1.1 & radii>mean(radii)0.9; % removing the lines with smaller and larger wrong circles centers=centers(idx,:); radii=radii(idx); %placing one more time cisrcles for verification (optional) %uncomment the bottom line to verify %viscircles(centers, radii,'EdgeColor','r');
%top left corner of rectangles with relation to centers of the circles centers=centers+mean(radii); imSize=size(im);
%calculation the size and position of future rectangules recDiameter=2*mean(radii);
clear im radii dt
% Generating a new matrix-image f=figure(1); f.Position=[0, 0, imSize(1,1),imSize(1,2)]; set(gca,'visible','off') % applying a white background whiteImage=zeros(imSize(1,1),imSize(1,2),0);
% drawing black rectangules on the circles positions for i=1:length(centers) rectangle('Position',[centers(i,1), centers(i,2),recDiameter,recDiameter], 'FaceColor','k'); end
Saving the Matrix image in temp directory TfolNam='temp'; % creating the temporary folder [status,msg] = mkdir(TfolNam) saveas(gcf,fullfile(TfolNam, string(epochT)),'png');
Decoding the image %reading the new image with the matrix Impath=sprintf('%s.png',fullfile(TfolNam, string(epochT))) %imshow(Impath)
%opening the file using python PyPath="C:\Users\sns\Documents\P-Frames\Defektenanerkenung\MatlabScripts\testScripts\my_python_2.py" code=pyrunfile(PyPath,"decoded_data",path=Impath) % Delating the Temporary file and folder rmdir(TfolNam,'s')`
Dear @jepperaskdk, this is the datamatrix, which contain only the number of the processed part.
I'm not so interested in the matlab code - can you share the output image that it produces and which you are able to decode?
The outcome is: 000000000135299069 The image which is generated by my matlab code (see above) with further succesfully interpretation by python:
python just wraps the C library, the C library may not be robust enough to decode the circles based image, you could try to process the images using scipy in a similar way that you did in Matlab? I've never seen data matrix printed as dots, I'm not sure it's part of the standard.
My main suspicion would be on the detection of the L marker and timing, the "jaggedness" in the L may be stopping it from being detected by libdmtx.
May not be relevant anymore, but just in case somebody cares: The main problem with the code is that it is mirrored. If the cleaned image is flipped, it is decoded just fine:
The preprocessing is required, though. The original image and the binarized one without clean quiet zone does not work.
Hi @kursancew I am trying to recognise a matrix which is an arrangement of circles instead of rectangular.
The code is :
After few second of decoding i got the answer "[]"
Is there any ideas how to proceed. Thanks