Skip to content

Instantly share code, notes, and snippets.

@frogermcs
Created May 21, 2019 18:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frogermcs/a16d20b2ed53963b8088f6a43f4ec672 to your computer and use it in GitHub Desktop.
Save frogermcs/a16d20b2ed53963b8088f6a43f4ec672 to your computer and use it in GitHub Desktop.
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