Here's an example to start with: ImageMagick's -threshold or -adaptive-threshold (depending on the image's lighting) are what you want to look at, e.g. try something like
And if you wanna go even lower, you'll "raw" read the image pixel by pixel to normalise colour to black/white and then read that matrix for the QR pattern.
And then, cause there are some inverted colour QRs, flip and scan again.