Open khanh1808 opened 1 year ago
I can't scan small QR codes too. But I setted this config 'aspectRatio: 0.5',make the video larger
I solve this by using a barcode-detector polyfill and also increase the video constraints. Here is my working code (tested on iOS Safari):
import "barcode-detector/side-effects";
import { BarcodeDetector } from "barcode-detector/pure";
try {
// Use video without audio
const constraints: MediaStreamConstraints = {
video: {
facingMode: { exact: "environment" },
width: { min: 1024, ideal: 4096, max: 4096 },
height: { min: 540, ideal: 2160, max: 2160 },
frameRate: { ideal: 60, max: 60 },
},
audio: false,
};
// Start video stream
stream = await navigator.mediaDevices.getUserMedia(constraints);
videoElmRef.current.srcObject = stream;
const barcodeDetector = new BarcodeDetector({
formats: ["qr_code"],
});
const detectCode = async () => {
if (videoElmRef.current) {
// Start detecting codes on to the video element
const codes = await barcodeDetector.detect(videoElmRef.current);
// If no codes exit function
if (codes.length === 0) return;
setStartScanned(false);
onDone(codes[0].rawValue);
}
};
intervalId = setInterval(() => detectCode(), 100);
} catch (e: any) {
setErrorMessage(e);
}
`
I can't scan small qr code (1cm x 1cm) :((. Can you fix this problem?