Skip to content

🐛 Camera misinterpreting the barcode data #3544

Open
@TanyaZhecheva

Description

@TanyaZhecheva

What's happening?

I am using the library (version - 4.5.2) for barcode scanning but i have some issues. When i am scanning different products sometimes the barcode reader outputs a completely different barcode.
The problem is issued with both android and ios devices (most cases are with android). The types our camera supports are : ean-13,ean-8, code-128, as we intentionally havent applied all barcode types because the current version of the library contains a bug that results in incorrect barcodes being returned when all barcodes types are applied.
I installed the lates version of the library, but the problem still accurs.
We have also tried to store the user`s scan logs in a array and output the barcode which repeats the most, but this still doesnt solve the problem, as the output of the scanning becomes slower, which we dont want our users to experience that kind of behavior.
With the examples below you can see the problem:

The barcode 3600524127985 is read as 2123714

Image
Image
Image
Image

Reproduceable Code

const codeScanner: CodeScanner = {
        /**
            * Note: Do not add additional barcode types to this implementation. 
            * The current version of the library contains a bug that results in incorrect barcodes being returned, particularly on Android devices. 
            * This issue most frequently occurs when scanning multiple barcodes consecutively.
            * Additionally, the expo-camera library exhibits the same bug.
        */
        codeTypes: [
            'ean-13',
            'ean-8',
            'code-128'
        ],
        onCodeScanned: (codes) => {
            console.log('code', codes[0].value!);
            if (isScanning) {
                let recogniezedBarcode = codes[0].value!;

                if (codes[0].type === 'upc-a' && Platform.OS === 'android') {
                    recogniezedBarcode = 0 + recogniezedBarcode;
                }
                
                if (userContext.dailyScans >= userContext.dailyScanLimit) {
                    showPaywall();
                    return;
                }

                console.log("Scanning");
                setIsScanning(false);
                (async () => {
                    setIsLoadingProductData(true);
                    const data: any = await fetchProductData(recogniezedBarcode);
                    setIsLoadingProductData(false);
                    if (data) {
                        Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
                        // Save scanned product
                        const formatedData = formatProductData(data);
                        // console.log('formated data', formatedData);
                        const {
                            barcode,
                            name,
                            brand,
                            image,
                            grade,
                            gradeColor,
                            quantity_unit,
                            ingredients,
                            isNutriValuesEmpty,
                            isCosmetic,
                            status, // For cosmetics
                        } = formatedData;

                        if (isNutriValuesEmpty === true) {
                            setIsNutritionDataEmpty(true)
                        }

                        if (!name && !brand) {
                            setScannedProductData({
                                isSheetShown: true,
                                isCosmetic: false,
                                barcode: recogniezedBarcode,
                                barcodeType: '',
                                name: '',
                                brand: '',
                                image: '',
                                grade: '',
                                gradeColor: '',
                                quantityUnit: '',
                                ingredients: [],
                            });
                            setIngredientsData(undefined);
                            setIsProductFound(false);
                            return;
                        }

                        setIsProductFound(true);

                        if (!image) {
                            try {
                                const productImageResponse: any = await fetchData(`${baseAPI}/products/image?barcode=${codes[0]?.value}&barcodeType=${codes[0]?.type}`);
                                if (productImageResponse.image) {
                                    setScannedProductData({
                                        isSheetShown: true,
                                        isCosmetic: isCosmetic ? true : false,
                                        barcode: barcode,
                                        barcodeType: codes[0]?.type,
                                        name: name,
                                        brand: brand,
                                        image: productImageResponse.image,
                                        grade: grade,
                                        gradeColor: gradeColor,
                                        quantityUnit: quantity_unit,
                                        ingredients: ingredients
                                    });
                                }
                            } catch (error) {
                                setIsScanning(true);
                            }

                        } else {
                            setScannedProductData({
                                isSheetShown: true,
                                isCosmetic: isCosmetic ? true : false,
                                barcode: barcode,
                                barcodeType: codes[0]?.type,
                                name: name,
                                brand: brand,
                                image: image,
                                grade: grade,
                                gradeColor: gradeColor,
                                quantityUnit: quantity_unit,
                                ingredients: ingredients

                            });
                        }
                        console.log('nutri', data.nutritionAnalysis);
                        setIngredientsData(data.nutritionAnalysis);

                        mutate(formatedData);
                    } else if (!data) {
                        console.log('in else');
                        setScannedProductData({
                            isSheetShown: true,
                            isCosmetic: false,
                            barcode: recogniezedBarcode,
                            barcodeType: codes[0].type,
                            name: '',
                            brand: '',
                            image: '',
                            grade: '',
                            gradeColor: '',
                            quantityUnit: '',
                            ingredients: []
                        });
                        setIngredientsData(undefined);
                        setIsProductFound(false);
                    }
                })()
            }
        }
    }

    const device: any = useCameraDevice(cameraState);
    const [cameraDevice, setCameraDevice] = useState<CameraDevice>(device);

Relevant log output

Image

Camera Device

did not any logs

Device

All kinds of IOS and Samsung devices

VisionCamera Version

4.5.2

Can you reproduce this issue in the VisionCamera Example app?

Yes, I can reproduce the same issue in the Example app here

Additional information

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions