Created
May 21, 2019 18:24
-
-
Save frogermcs/a16d20b2ed53963b8088f6a43f4ec672 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
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