jsQR icon indicating copy to clipboard operation
jsQR copied to clipboard

Equivalent feature to ZXing's TRY_HARDER?

Open david-boles opened this issue 6 years ago • 8 comments

I finally got around to actually testing some of the images I want to scan qr codes in and the success-rate with jsQR ends up being on the edge of unusably low for me. I decided to try the JS port of ZXing and it's success rate was around the same... until I turned on the TRY_HARDER hint, now it almost seems to be able to scan anything I throw at it. Any chance that's a feature that could be easily added to jsQR?

david-boles avatar Jul 21 '18 22:07 david-boles

Here's some example images that fail for jsQR and ZXing without TRY_HARDER enabled but that works when it is: img_20180721_145730 img_20180720_213104

david-boles avatar Jul 21 '18 22:07 david-boles

Hunh... Doing a little more rigorous testing and there doesn't seem to be any super clear patterns. Sometimes jsQR can see things, some times only ZXing without TRY_HARDER can.

david-boles avatar Jul 21 '18 23:07 david-boles

Another hour or so of playing around in, I've found that jsQR ends up working almost every time if I scale the image down by 3.5 if it doesn't find it the first time. Which bring me back to the original question, would it be reasonable to add a flag to make jsQR try a little harder (and maybe use some image manipulation)?

david-boles avatar Jul 22 '18 02:07 david-boles

Hey! Thanks for the investigation.

We've talked about adding the equivalent to TRY_HARDER in the past, and would fully support it. I think #78 opens up the path towards that too, as it introduces the ability to disable a feature for speed. Ideally inverting would have been opt in, not opt out, but too late to change that now.

I do think one thing we'd probably do different than ZXing is have individual flags to configure, instead of one omnibus TRY_HARDER flag. This would give people more control and insight into how they're changing the scanning.

Off the top of my head these are the things we could tweak to make jsQR more aggressive

  • Try to invert the image colors (already done :D)
  • Try to scale down the image (seems like you've hit some success with this?)
  • Increase the number of finder pattern candidates we search (right now hard coded to 4). 4 is pretty arbitrary but increasing it increases the total patterns looked at exponentially, so it has a large impact.
  • The nuclear option would be to take every possible finder pattern group we found and pass them downstream through decoder etc, instead of just the best scoring one. This would also fix https://github.com/cozmo/jsQR/issues/24.

Not sure if you have any other ideas that you think would be helpful?

cozmo avatar Jul 22 '18 18:07 cozmo

Those all some good to me. For scanning multiple QRs, would you expect the best scoring n finder pattern groups to correspond to n QR codes in the image (or would you get groups of finder patterns belonging to different QR codes)? If so, it might make sense to have an expected maximum number of QR codes option to drive both the number of finder pattern candidates and the number of finder pattern groups.

david-boles avatar Jul 22 '18 23:07 david-boles

Also, seems like down-scaling might help with #14.

david-boles avatar Jul 22 '18 23:07 david-boles

Nice ! 👍 for the nuclear option !

mobula9 avatar Jul 26 '18 16:07 mobula9

The last two options here would be really helpful.

Are there any plans to implement this?

samuelcolvin avatar Nov 13 '21 11:11 samuelcolvin