Created
November 26, 2018 16:59
-
-
Save RedRussianBear/ea4316f2185b8e993aa87a37b23f9ba5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private class ClarifaiTask extends AsyncTask<File, Integer, Boolean> { | |
protected Boolean doInBackground(File... images) { | |
info.setText("Processing..."); | |
// Connect to Clarifai using your API token | |
ClarifaiClient client = new ClarifaiBuilder("YOUR_API_TOKEN").buildSync(); | |
List<ClarifaiOutput<Concept>> predictionResults; | |
// For each photo we pass, send it off to Clarifai | |
for (File image : images) { | |
predictionResults = client.getDefaultModels().generalModel().predict() | |
.withInputs(ClarifaiInput.forImage(image)).executeSync().get(); | |
// Check if Clarifai thinks the photo contains the object we are looking for | |
for (ClarifaiOutput<Concept> result : predictionResults) | |
for (Concept datum : result.data()) | |
if (datum.name().contains(object.toLowerCase())) | |
return true; | |
} | |
return false; | |
} | |
protected void onPostExecute(Boolean result) { | |
// Delete photo | |
(new File(photoPath)).delete(); | |
photoPath = null; | |
// If image contained object, close the AlarmActivity | |
if (result) { | |
info.setText("Success!"); | |
finish(); | |
} else info.setText("Try again..."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment