使用本教程设置您的 Java 环境
https://developer.ibm.com/recipes/tutorials/bluemix-watson-apis-quickstart-using-java-sdk/
然后看看这个其他教程,它展示了如何使用 Java 代码使用多个分类器
https://developer.ibm.com/recipes/tutorials/estimate-a-childs-age-based-on-photos-using-watson-visual-recognition/
简而言之,您的代码将如下所示
步骤 #1 - 创建分类器
VisualRecognition service = new VisualRecognition(VisualRecognition.VERSION_DATE_2015_12_02);
service.setUsernameAndPassword("*******", "********");
File p1 = new File("/home/leoks/Desktop/models/pos2010-2011.zip");
File n1 = new File("/home/leoks/Desktop/models/pos2014-2015.zip");
VisualClassifier c1 = service.createClassifier("2010", p1, n1);
File p3 = new File("/home/leoks/Desktop/models/pos2014-2015.zip");
File n3 = new File("/home/leoks/Desktop/models/pos2010-2011.zip");
VisualClassifier c3 = service.createClassifier("2014", p3, n3);
System.out.println(service.getClassifiers());
步骤 #2 - 使用它们
File image = new File("...");
VisualClassifier vc1 = new VisualClassifier("2010_633980596");
VisualClassifier vc2 = new VisualClassifier("2014_450835300");
VisualClassification result = service.classify(image, vc1,vc2);
System.out.println(result);
如果您的图像被分类器识别,它将返回分数,否则将不返回任何答案。例如
{
"images": [
{
"image": "2012.jpg",
"scores": [
{
"classifier_id": "2010_633980596",
"name": "2010",
"score": 0.992153
},
{
"classifier_id": "2014_450835300",
"name": "2014",
"score": 0.833185
}
]
}
]
}
检查教程,它们是分步说明。祝你好运。