Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class ModelTestActivity extends AppCompatActivity {
private ImageView ivPreview;
private TextView tvClassification;
private ModelClassificator modelClassificator;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(com.frogermcs.imageclassificationtester.test.R.layout.activity_model_test);
ivPreview = findViewById(com.frogermcs.imageclassificationtester.test.R.id.ivPreview);
tvClassification = findViewById(com.frogermcs.imageclassificationtester.test.R.id.tvClassification);
initClassification();
}
private void initClassification() {
try {
ModelConfig modelConfig = new FlowersConfig();
modelClassificator = new ModelClassificator(this, modelConfig);
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, "Frame Processor initialization failed", Toast.LENGTH_SHORT).show();
}
}
public void classifyImage(Bitmap bitmap) {
setImagePreview(bitmap);
performClassification(bitmap);
}
public void setImagePreview(Bitmap bitmap) {
Bitmap squareBitmap = ThumbnailUtils.extractThumbnail(bitmap, 100, 100);
runOnUiThread(() -> setImage(squareBitmap));
}
private void performClassification(Bitmap bitmap) {
List<ClassificationResult> classificationResults = modelClassificator.process(bitmap);
showClassificationResults(classificationResults);
}
public void showClassificationResults(List<ClassificationResult> classificationResults) {
runOnUiThread(() -> tvClassification.setText(ResultsUtils.resultsToStr(classificationResults)));
}
public void setImage(Bitmap bmp) {
ivPreview.setImageBitmap(bmp);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.