I have written below code in Node.js to create a classifier and then classify an image using Visual Recognition API Version 3, but the image isn't classified with the created classifier.
Same code has worked with earlier version. Please share your thoughts.
Thanks in advance!
var visual_recognition, params;
var ONE_HOUR = 3600000;
var CLASSIFIERID = [];
// Create the service wrapper
visual_recognition = watson.visual_recognition({
version: 'v3',
api_key: process.env.API_KEY || '<api-key>',
version_date: '2015-05-19'
});
Creating classfier:
params = {
name: constants.DRIVERNAME,
driverOne_positive_examples: fs.createReadStream('./public/positive.zip'),
negative_examples: fs.createReadStream('./public/negative.zip')
};
visual_recognition.createClassifier(params, function(err, classifier) {
if (err){
res.render('showError',{title:constants.TITLE1,
err:'Something went wrong!'
});
}
else{
CLASSIFIERID.push(classifier.classifier_id);
}
});
Classify image:
var parm = {
images_file: img_classify,
classifier_ids: CLASSIFIERID,
threshold: 0.0
};
visual_recognition.classify(parm, function(err, results) {
var driverName,driverScore,driverId,driver;
if (err){
console.log('Error at classification!!!');
}
else{
console.log('Image has been classified!!!');
res.json(results);
}