本文整理汇总了Java中com.clarifai.api.RecognitionResult类的典型用法代码示例。如果您正苦于以下问题:Java RecognitionResult类的具体用法?Java RecognitionResult怎么用?Java RecognitionResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RecognitionResult类属于com.clarifai.api包,在下文中一共展示了RecognitionResult类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: addTagsFromImage
点赞 3
import com.clarifai.api.RecognitionResult; //导入依赖的package包/类
/**
* Save tags to a game based on uploaded image
* adds these tags to the current game
*
* @param filename
*/
public void addTagsFromImage (String filename) {
// set tags from current game
loadCurrentGameTags();
try {
if(filename.endsWith(".gif")) return;
if (!ResourceDecipherer.isImage(filename)) return;
}
catch (VoogaException e) {
}
// Retrieve recognition results
List<RecognitionResult> results =
clarifai.recognize(new RecognitionRequest(new File(filename)));
// add all of the Tags to a list
myTags.addAll(results.get(0).getTags());
// save Tags
saveCurrentGameTags();
}
开发者ID:sjain28,
项目名称:Game-Engine-Vooga,
代码行数:28,
代码来源:GameTagManager.java
示例2: getTags
点赞 3
import com.clarifai.api.RecognitionResult; //导入依赖的package包/类
private static Collection<IPTCDataSet> getTags(File image) {
// create collection to store all keywords found in an image
Set<IPTCDataSet> keywords = new HashSet<>();
// get results from clarifai api !Requires internet
List<RecognitionResult> clarifaiTags =
clarifai.recognize(new RecognitionRequest(image));
// insert all tags returned as keyword, filter away the less likely tags
clarifaiTags.get(0).getTags().stream().filter(tag -> tag.getProbability() > 0.95).forEach(tag -> {
IPTCDataSet keyword = new IPTCDataSet(25, tag.getName());
keywords.add(keyword);
});
return keywords;
}
开发者ID:SamiAlabed,
项目名称:Tagifai,
代码行数:17,
代码来源:Tagfai.java
示例3: sortIntoDirectoryByTag
点赞 3
import com.clarifai.api.RecognitionResult; //导入依赖的package包/类
private static void sortIntoDirectoryByTag(File image) throws IOException {
List<RecognitionResult> results =
clarifai.recognize(new RecognitionRequest(image));
// get the most probable tag
Tag tag = results.get(0).getTags().get(0);
String targetDir = "./output/" + tag.getName() + "/";
// create directory for tag
if (new File(targetDir).mkdirs())
System.out.println("New directory created: " + tag.getName());
// move file to newly created directory
Path moveFrom = FileSystems.getDefault().getPath(image.getAbsolutePath());
Path target = FileSystems.getDefault().getPath(targetDir + image.getName());
Files.move(moveFrom, target, StandardCopyOption.REPLACE_EXISTING);
}
开发者ID:SamiAlabed,
项目名称:Directifai,
代码行数:19,
代码来源:Directifai.java
示例4: recognizeBitmap
点赞 3
import com.clarifai.api.RecognitionResult; //导入依赖的package包/类
/**
* Sends the given bitmap to Clarifai for recognition and returns the result.
*/
private RecognitionResult recognizeBitmap(Bitmap bitmap, String model) {
try {
// Scale down the image. This step is optional. However, sending large images over the
// network is slow and does not significantly improve recognition performance.
Bitmap scaled = Bitmap.createScaledBitmap(bitmap, 320,
320 * bitmap.getHeight() / bitmap.getWidth(), true);
// Compress the image as a JPEG.
ByteArrayOutputStream out = new ByteArrayOutputStream();
scaled.compress(Bitmap.CompressFormat.JPEG, 90, out);
byte[] jpeg = out.toByteArray();
// Send the JPEG to Clarifai and return the result.
return client.recognize(new RecognitionRequest(jpeg).setModel(model)).get(0);
} catch (ClarifaiException e) {
Log.e(TAG, "Clarifai error", e);
return null;
}
}
开发者ID:husseinfahmy,
项目名称:Bad-Boyfriend,
代码行数:23,
代码来源:RecognitionActivity.java
示例5: recognizeNSWFBitmap
点赞 3
import com.clarifai.api.RecognitionResult; //导入依赖的package包/类
/**
* Sends the given bitmap to Clarifai for recognition and returns the result.
*/
private RecognitionResult recognizeNSWFBitmap(Bitmap bitmap, String model) {
try {
// Scale down the image. This step is optional. However, sending large images over the
// network is slow and does not significantly improve recognition performance.
Bitmap scaled = Bitmap.createScaledBitmap(bitmap, 320,
320 * bitmap.getHeight() / bitmap.getWidth(), true);
// Compress the image as a JPEG.
ByteArrayOutputStream out = new ByteArrayOutputStream();
scaled.compress(Bitmap.CompressFormat.JPEG, 90, out);
byte[] jpeg = out.toByteArray();
// Send the JPEG to Clarifai and return the result.
return client.recognize(new RecognitionRequest(jpeg).setModel(model)).get(0);
} catch (ClarifaiException e) {
Log.e(TAG, "Clarifai error", e);
return null;
} //catch (NetworkOnMainThreadException e) {
// System.out.println("Caught here again!");
//return null;
//}
}
开发者ID:husseinfahmy,
项目名称:Bad-Boyfriend,
代码行数:27,
代码来源:RecognitionActivity.java
示例6: guessImage
点赞 2
import com.clarifai.api.RecognitionResult; //导入依赖的package包/类
public void guessImage(Chat chat, BufferedImage bufferedImage) {
Core.send(chat, "Okay, let my try to guess what this is....");
File picFile = new File(folder, "Pic-" + new Random().nextInt(999999));
picFile.deleteOnExit();
try {
ImageIO.write(bufferedImage, "jpg", picFile);
} catch (Exception e) {
try {
ImageIO.write(bufferedImage, "png", picFile);
} catch (IOException e1) {
Core.send(chat, "Something went wrong while processing your picture. Please make sure its a JPG or PNG!");
picFile.delete();
return;
}
}
List<RecognitionResult> recognitions = clarifai.recognize(new RecognitionRequest(picFile));
List<Tag> tags = recognitions.get(0).getTags();
int id = new Random().nextInt(2);
switch (id) {
case 0:
Core.send(chat, "It could have something to do with " + tags.get(0).getName() + " or what about " + tags.get(1).getName() + "? Or maybe " + tags.get(2).getName() + "...");
break;
case 1:
Core.send(chat, "Im pretty sure it has something to do with " + tags.get(0).getName() + ". If not then what about " + tags.get(1).getName() + "? Or maybe " + tags.get(2).getName() + "...?");
break;
case 2:
Core.send(chat, "Okay, Im sure it must have something to do with " + tags.get(0).getName() + ", right ? If not then maybe " + tags.get(1).getName() + "? Or " + tags.get(2).getName() + "...?");
break;
default:
break;
}
picFile.delete();
}
开发者ID:Kitt3120,
项目名称:ViperBot,
代码行数:34,
代码来源:ImageRecognition.java
示例7: onActivityResult
点赞 2
import com.clarifai.api.RecognitionResult; //导入依赖的package包/类
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == CODE_PICK && resultCode == RESULT_OK) {
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == CODE_PICK && resultCode == RESULT_OK) {
Bitmap bitmap = loadBitmapFromUri(intent.getData());
/*
ArrayList<String> imagePaths = getImagesPath(this);
for (int i = 1; i < imagePaths.size(); i++) {
File imgFile = new File(imagePaths.get(i));
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath(), bmOptions);
myBitmap = Bitmap.createScaledBitmap(myBitmap, 320,
320 * myBitmap.getHeight() / myBitmap.getWidth(), true);
// Compress the image as a JPEG.
ByteArrayOutputStream out = new ByteArrayOutputStream();
myBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
byte[] jpeg = out.toByteArray();
*/
new AsyncTask<Bitmap, Void, RecognitionResult>() {
@Override protected RecognitionResult doInBackground(Bitmap... bitmaps) {
return recognizeBitmap(bitmaps[0], "nsfw-v0.1");
}
@Override protected void onPostExecute(RecognitionResult result) {
updateUIForResult(result);
}}.execute(bitmap);
}
}
}
开发者ID:husseinfahmy,
项目名称:Bad-Boyfriend,
代码行数:37,
代码来源:RecognitionActivity.java
示例8: updateUIForResult
点赞 2
import com.clarifai.api.RecognitionResult; //导入依赖的package包/类
/**
* Updates the UI by displaying tags for the given result.
*/
private void updateUIForResult(RecognitionResult result) {
//String bestHashTag = "#";
if (result != null) {
if (result.getStatusCode() == RecognitionResult.StatusCode.OK) {
// Display the list of tags in the UI.
StringBuilder b = new StringBuilder();
for (Tag tag : result.getTags()) {
Double SFWProb = tag.getProbability();
b.append(b.length() > 0 ? "" : "").append(tag.getName() + SFWProb);
b.append(nsfwProbability(SFWProb));
Double NSFWProb = tag.getProbability();
b.append(b.length() > 0 ? "" : "").append(tag.getName() + NSFWProb);
if (nsfwProbability(NSFWProb)) {
tagsRequest(currentBitmap);
}
b.append(nsfwProbability(NSFWProb));
}
} else {
Log.e(TAG, "Clarifai: " + result.getStatusMessage());
//textView.setText("Sorry, there was an error recognizing your image.");
}
} else {
//textView.setText("Sorry, there was an error recognizing your image.");
}
}
开发者ID:husseinfahmy,
项目名称:Bad-Boyfriend,
代码行数:35,
代码来源:RecognitionActivity.java
示例9: tagsRequest
点赞 2
import com.clarifai.api.RecognitionResult; //导入依赖的package包/类
private void tagsRequest(Bitmap bitmap) {
// Run recognition on a background thread since it makes a network call.
new AsyncTask<Bitmap, Void, RecognitionResult>() {
@Override
protected RecognitionResult doInBackground(Bitmap... bitmaps) {
return recognizeNSWFBitmap(bitmaps[0], "");
}
}.execute(bitmap);
}
开发者ID:husseinfahmy,
项目名称:Bad-Boyfriend,
代码行数:13,
代码来源:RecognitionActivity.java
示例10: fetchTag
点赞 2
import com.clarifai.api.RecognitionResult; //导入依赖的package包/类
public void fetchTag(View view) {
ClarifaiClient clarifai = new ClarifaiClient();
List<RecognitionResult> results =
clarifai.recognize(new RecognitionRequest("http://www.clarifai.com/static/img_ours/metro-north.jpg"));
/**Tag mostRelevantTag = null;
for (Tag tag : results.get(0).getTags()) {
if (mostRelevantTag == null || mostRelevantTag.getProbability() < tag.getProbability())
mostRelevantTag = tag;
}
TinyDB tinyDB = new TinyDB(this);
ArrayList<String> photoTags = tinyDB.getList(getString(R.string.photoTags));
photoTags.add(mostRelevantTag.getName());
tinyDB.putList(getString(R.string.photoTags), photoTags);*/
}
开发者ID:alexdao,
项目名称:Lollipop,
代码行数:16,
代码来源:MainActivity.java