node.jsfirebasevue.jsibm-watsonvisual-recognition

What is the best way to create a link from an image uploaded by the user?


I am trying to create an app that uses IBM Watson Visual Recognition for sortering waste. Watson runs in the backend (node js) and I wanted to develop the application in Vue.

Watson needs a link to an image, and I was thinking of using firebase in order to create the link when an user uploads an image.

My question is: "Is there a better way to do it, considering that the image and its results should be unique to the user an do not have to persist?"

I do not know much about Visual Recognition and just a little of firebase. So, if there is a way to handle things better, please say. Thanks!


Solution

  • As per the API documentation, you can submit the image to be classified either as a url or as a readstream. https://cloud.ibm.com/apidocs/visual-recognition/visual-recognition-v3?code=node#classify

    The sample provided in the API docs makes use of a readstream :

    
    const fs = require('fs');
    const VisualRecognitionV3 = require('ibm-watson/visual-recognition/v3');
    const { IamAuthenticator } = require('ibm-watson/auth');
    
    const visualRecognition = new VisualRecognitionV3({
      version: '2018-03-19',
      authenticator: new IamAuthenticator({
        apikey: '{apikey}',
      }),
      serviceUrl: '{url}',
    });
    
    const classifyParams = {
      imagesFile: fs.createReadStream('./fruitbowl.jpg'),
      owners: ['me'],
      threshold: 0.6,
    };
    
    visualRecognition.classify(classifyParams)
      .then(response => {
        const classifiedImages = response.result;
        console.log(JSON.stringify(classifiedImages, null, 2));
      })
      .catch(err => {
        console.log('error:', err);
      });