0

I have a question that I can't figure out,I do not know where to begin.I use the following technologies: React Native (mobile application) and the backend application is built with Node Js.

What I'm trying to do is, the user takes a picture of a product, with the help of this mobile application the caption is saved in a directory on the server, let's say [image_phone],I managed to do this part,on the server I also have a directory [app_images] where I have images of products with a specific name.

What I want to do is create a function that will return from the folder [app_images] all the images similar to the one uploaded by the user in the folder [image_phone].

What did I try to do about it:

  1. Following a tutorial on the Internet, I tried to solve this problem using the following modules.[jimp, pixelmatch, pngjs]

Code:

const Jimp = require('jimp');
const PNG = require('pngjs').PNG;
const pixelmatch = require('pixelmatch');

exports.compareImage = catchAsync(async(req,res,next)=>{




    const originalFile = imageRoot+'/imagine3.png';
    const compareFile = compareRoot+'/Screenshot_72.png';


    const createBufferImage = async (url) => {
        return new Promise(async (resolve, reject) => {
            await Jimp.read(url, async (err, image) => {
                if (err) {
                    console.log(`eroare la citirea imagini Jimp: ${err}`);
                    reject(err);
                }
                image.resize(400, 400);
                return image.getBuffer(jimp.MIME_PNG, (err, buffer) => {
                    if (err) {
                        console.log(`eroare convertire url in buffer: ${err}`);
                        reject(err);
                    }
                    resolve(buffer);
                });
            });
        });
    };


    const compareImageApp = async (
        capture,
        app_image
    ) => {
        try {
            console.log('> Start compare');
            const img1Buffer = await createBufferImage(capture);
            const img2Buffer = await createBufferImage(app_image);
            const img1 = PNG.sync.read(img1Buffer);
            const img2 = PNG.sync.read(img2Buffer);
            const { width, height } = img1;
            const diff = new PNG({ width, height });
    
            const difference = pixelmatch(
                img1.data,
                img2.data,
                diff.data,
                width,
                height,
                {
                    threshold: 0,
                }
            );
    
            const compatibility = 100 - (difference * 100) / (width * height);
            console.log(`${difference} diferenta pixel`);
            console.log(`Compatibilitate: ${compatibility}%`);
            console.log('< Misiune completa');
            return compatibility;
        } catch (error) {
            console.log(`Eroare la compararea imaginilor: ${error}`);
            throw error;
        }
    };

    compareImageApp(originalFile,
        compareFile
)


res.status(200).json({
    status:'succes'
})
 })

Result:

enter image description here

But the accuracy does not really exist, there are images that do not resemble each other at all, but it gives me an accuracy of over 50%.

2)I tried to solve this problem using another module https://www.npmjs.com/package/rembrandt but the same accuracy problem does not exist.

Now I'm trying to solve this problem using tensorFlow js, to make a kind of image recognition app, something like facial recognition.

Do you have any ideas on how to solve this problem, if you have faced it before.

0 Answers0