Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class ClassificationFrameProcessor implements FrameProcessor {
private final Interpreter interpreter;
private final List<String> labels;
private final ClassificationListener classificationListener;
private final ModelConfig modelConfig;
/* ... */
@Override
public void process(@NonNull Frame frame) {
Bitmap bitmap = ImageUtils.frameToBitmap(frame);
Bitmap toClassify = ThumbnailUtils.extractThumbnail(
bitmap, modelConfig.getInputWidth(), modelConfig.getInputHeight()
);
bitmap.recycle();
ByteBuffer byteBufferToClassify = bitmapToModelsMatchingByteBuffer(toClassify);
float[][] result = new float[1][labels.size()];
interpreter.run(byteBufferToClassify, result);
classificationListener.onClassifiedFrame(getSortedResult(result));
}
/* ... */
public interface ClassificationListener {
void onClassifiedFrame(List<ClassificationResult> classificationResults);
}
}
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.