Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instability when using QReader #1

Open
henrypickler opened this issue Sep 16, 2024 · 0 comments
Open

Instability when using QReader #1

henrypickler opened this issue Sep 16, 2024 · 0 comments

Comments

@henrypickler
Copy link

Hi, thank you for this piece of software! We are using your QR detection library in one of our projects and noticed that the quadrilateral fitting algorithm is sometimes producing weird results. For example, in one of our images (that do not contain a QR code) the resulting detection gives this value:

'confidence': 0.777702271938324, 'bbox_xyxy': array([     171.08,      967.93,      427.86,        1197], dtype=float32), 'bbox_xyxyn': array([      0.104,     0.41417,      0.2601,      0.5122], dtype=float32), 'cxcy': (299.46868896484375, 1082.47021484375), 'cxcyn': (0.1820478352369871, 0.46318793959937954), 'wh': (256.78472900390625, 229.08831787109375), 'whn': (0.15610013921210106, 0.09802666575570977), 'polygon_xy': array([[     183.48,      978.62],
       [     179.82,      982.27],
       [     179.82,      1190.4],
       [     183.48,      1194.1],
       [     395.27,      1194.1],
       [     398.92,      1190.4],
       [     406.22,      1190.4],
       [     409.87,      1186.8],
       [     413.53,      1186.8],
       [     413.53,      1183.1],
       [     420.83,      1175.8],
       [     431.78,      1175.8],
       [     435.43,      1172.2],
       [     431.78,      1168.5],
       [     431.78,      1164.8],
       [     428.13,      1164.8],
       [     420.83,      1157.5],
       [     413.53,      1157.5],
       [     409.87,      1153.9],
       [     406.22,      1153.9],
       [     398.92,      1146.6],
       [     398.92,      1135.6],
       [     395.27,        1132],
       [     395.27,      1102.8],
       [     402.57,      1095.5],
       [     402.57,      1091.8],
       [     406.22,      1088.2],
       [     406.22,      1084.5],
       [     409.87,      1080.9],
       [     409.87,      1077.2],
       [     413.53,      1073.6],
       [     413.53,      1069.9],
       [     417.18,      1066.3],
       [     417.18,      1062.6],
       [     420.83,        1059],
       [     420.83,      1040.7],
       [     424.48,        1037],
       [     424.48,      1015.1],
       [     428.13,      1011.5],
       [     428.13,      1007.8],
       [     435.43,      1000.5],
       [     435.43,      982.27],
       [     428.13,      982.27],
       [     424.48,      978.62]], dtype=float32), 'polygon_xyn': array([[    0.11154,     0.41875],
       [    0.10932,     0.42031],
       [    0.10932,     0.50938],
       [    0.11154,     0.51094],
       [    0.24028,     0.51094],
       [     0.2425,     0.50938],
       [    0.24694,     0.50938],
       [    0.24916,     0.50781],
       [    0.25138,     0.50781],
       [    0.25138,     0.50625],
       [    0.25582,     0.50313],
       [    0.26248,     0.50313],
       [     0.2647,     0.50156],
       [    0.26248,         0.5],
       [    0.26248,     0.49844],
       [    0.26026,     0.49844],
       [    0.25582,     0.49531],
       [    0.25138,     0.49531],
       [    0.24916,     0.49375],
       [    0.24694,     0.49375],
       [     0.2425,     0.49063],
       [     0.2425,     0.48594],
       [    0.24028,     0.48438],
       [    0.24028,     0.47188],
       [    0.24472,     0.46875],
       [    0.24472,     0.46719],
       [    0.24694,     0.46563],
       [    0.24694,     0.46406],
       [    0.24916,      0.4625],
       [    0.24916,     0.46094],
       [    0.25138,     0.45938],
       [    0.25138,     0.45781],
       [     0.2536,     0.45625],
       [     0.2536,     0.45469],
       [    0.25582,     0.45312],
       [    0.25582,     0.44531],
       [    0.25804,     0.44375],
       [    0.25804,     0.43438],
       [    0.26026,     0.43281],
       [    0.26026,     0.43125],
       [     0.2647,     0.42813],
       [     0.2647,     0.42031],
       [    0.26026,     0.42031],
       [    0.25804,     0.41875]], dtype=float32), 'quad_xy': array([[     225.14, -1.3248e+08],
       [     418.17,      972.31],
       [     419.83,  7.1419e+06],
       [     182.42,      736.57]], dtype=float32), 'quad_xyn': array([[    0.13687,      -56687],
       [    0.25421,     0.41605],
       [    0.25522,        3056],
       [    0.11089,     0.31518]]), 'padded_quad_xy': array([[     227.84, -1.4888e+08],
       [     435.43,      982.27],
       [     435.43,      982.27],
       [     179.83,      726.67]], dtype=float32), 'padded_quad_xyn': array([[     0.1385,      -63704],
       [     0.2647,     0.42031],
       [     0.2647,     0.42031],
       [    0.10932,     0.31094]]), 'image_shape': (2337, 1645)

Notice how the quad_xy and similar rects is bigger than the image itself. In the QReader library, this quad is used for padding, which makes the program try to allocate a huge array (in our case, of 600GiB) which crashes the program due to insufficient memory.

Plugging the polygon_xy above in the QuadrilateralFitter with the arguments used in here gives the observed quad_xy. I noticed that reducing the max_simplification_epsilon to 1.0 gives a better result:

array([[     179.82,      978.57],
       [     430.56,       982.3],
       [     396.96,      1183.9],
       [     179.82,      1194.3]], dtype=float32)

I don't have much familiarity with this library and so I'm not sure I can contribute much, but hopefully this issue can help bring improvements. I'm available for discussing the issue though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant