-
Notifications
You must be signed in to change notification settings - Fork 220
Highlight scan barcodes for better UX #38
Comments
@qboisson I've changed it a little and it looks very close to reality const WINDOW_HEIGHT = Dimensions.get('window').height; ...
const frameProcessor = useFrameProcessor(frame => {
'worklet';
const detectedBarcodes = scanBarcodes(frame, [BarcodeFormat.ALL_FORMATS]);
const barcode = detectedBarcodes[0];
if (barcode) {
const cornerPoints = barcode.cornerPoints;
const xRatio = frame.width / WINDOW_WIDTH;
const yRatio = frame.height / WINDOW_HEIGHT;
if (Platform.OS === 'ios') {
const xArray = cornerPoints.map(corner => parseFloat(corner.x));
const yArray = cornerPoints.map(corner => parseFloat(corner.y));
const resultPoints = {
left: Math.min(...xArray) / xRatio,
right: Math.max(...xArray) / xRatio,
bottom: Math.max(...yArray) / yRatio,
top: Math.min(...yArray) / yRatio,
};
runOnJS(setPointsOfInterest)(resultPoints);
} else {
// Other similar logic for Android
}
runOnJS(setBarcodes)(detectedBarcodes);
} else {
runOnJS(setPointsOfInterest)(null);
}
}, []);
... |
It works realy great, thanks a lot @kirill3333 ! |
@saajuck this is because your screen size is different from the size of the image you are sending to process. I am pretty sure the frame processor shouldn't know about screen size. |
Hello, Is it possible to get an example. I was trying to use your code but it doesn't work on my side. |
Works on ios, but on android there's some offset from actual qrcode, why? |
Unfortunately it's more complex than the current given solutions as it actually depends on the camera view size (that can be equal to the window when in fullscreen), and there is also some cropping after the resize that you have to take into account to setup proper offsets. Currently working on a solution that covers all cases, @rodgomesc would you be interested in a PR adding this highlight feature? |
Would be great! @mgcrea |
@mgcrea Any news on this? Also, wouldn't it make sense to use animated components from Reanimated for the bounding boxes? |
For android and ios
|
While scanning barcodes, it is possible to retrieve a barcode object with either boundingBox for Android or cornerPoints for iOS.
With these properties, it seems possible to get the right positioning of the barcode in order to highlight it for better user experience.
For instance, while scanning multiple barcodes, it can be useful to add an emoji or show the borders of the barcodes already scanned.
The issue is that I am not able to display correctly the borders of scanned barcodes.
I am trying to adapt boundingBox and cornerPoints to use these values in a more classic way to display absolute elements with left and top properties but it does not fit perfectly with the real barcode borders.
Is there a way to use boundingBox or cornerPoints correctly ?
See below an example to reproduce this issue and an example of cornerPoints value.
Example of cornerPoints while scanning a QR code with an iPad Air 2 (window dimensions = 677:335) :
"cornerPoints": [{"x": 209.60528564453125, "y": 647.1997680664062}, {"x": 331.0139465332031, "y": 655.4308471679688}, {"x": 330.98651123046875, "y": 780.6898193359375}, {"x": 209.5778350830078, "y": 772.458740234375}]
The text was updated successfully, but these errors were encountered: