当前位置: 首页>>代码示例>>Java>>正文


Java RecognitionRequest类代码示例

本文整理汇总了Java中com.clarifai.api.RecognitionRequest的典型用法代码示例。如果您正苦于以下问题:Java RecognitionRequest类的具体用法?Java RecognitionRequest怎么用?Java RecognitionRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RecognitionRequest类属于com.clarifai.api包,在下文中一共展示了RecognitionRequest类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addTagsFromImage

import com.clarifai.api.RecognitionRequest; //导入依赖的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

import com.clarifai.api.RecognitionRequest; //导入依赖的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

import com.clarifai.api.RecognitionRequest; //导入依赖的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

import com.clarifai.api.RecognitionRequest; //导入依赖的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

import com.clarifai.api.RecognitionRequest; //导入依赖的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

import com.clarifai.api.RecognitionRequest; //导入依赖的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: fetchTag

import com.clarifai.api.RecognitionRequest; //导入依赖的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


注:本文中的com.clarifai.api.RecognitionRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。