我在 Node.js 中编写了以下代码来创建分类器,然后使用Visual Recognition API Version 3对图像进行分类,但图像未使用创建的分类器进行分类。
相同的代码适用于早期版本。请分享你的想法。
提前致谢!
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'
});
创建分类器:
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);
}
});
分类图像:
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);
}