use of androidx.media.filterfw.FrameImage2D in project android_frameworks_base by DirtyUnicorns.
the class IfElseFilter method onProcess.
@Override
protected void onProcess() {
OutputPort outPort = getConnectedOutputPort("output");
FrameImage2D trueFrame = getConnectedInputPort("trueResult").pullFrame().asFrameImage2D();
FrameImage2D falseFrame = getConnectedInputPort("falseResult").pullFrame().asFrameImage2D();
FrameValue boolFrameValue = getConnectedInputPort("condition").pullFrame().asFrameValue();
boolean condition = (Boolean) boolFrameValue.getValue();
FrameBuffer2D outputFrame;
// If the condition is true, then we want to use the camera, else use the gallery
if (condition) {
outputFrame = trueFrame;
} else {
outputFrame = falseFrame;
}
outPort.pushFrame(outputFrame);
}
use of androidx.media.filterfw.FrameImage2D in project android_frameworks_base by DirtyUnicorns.
the class ImageGoodnessFilter method onProcess.
/**
* @see androidx.media.filterfw.Filter#onProcess()
*/
@Override
protected void onProcess() {
FrameValue sharpnessFrameValue = getConnectedInputPort("sharpness").pullFrame().asFrameValue();
float sharpness = ((Float) sharpnessFrameValue.getValue()).floatValue();
FrameValue overExposureFrameValue = getConnectedInputPort("overExposure").pullFrame().asFrameValue();
float overExposure = ((Float) overExposureFrameValue.getValue()).floatValue();
FrameValue underExposureFrameValue = getConnectedInputPort("underExposure").pullFrame().asFrameValue();
float underExposure = ((Float) underExposureFrameValue.getValue()).floatValue();
FrameValue colorfulnessFrameValue = getConnectedInputPort("colorfulness").pullFrame().asFrameValue();
float colorfulness = ((Float) colorfulnessFrameValue.getValue()).floatValue();
FrameValue contrastRatingFrameValue = getConnectedInputPort("contrastRating").pullFrame().asFrameValue();
float contrastRating = ((Float) contrastRatingFrameValue.getValue()).floatValue();
FrameValue brightnessFrameValue = getConnectedInputPort("brightness").pullFrame().asFrameValue();
float brightness = ((Float) brightnessFrameValue.getValue()).floatValue();
FrameValue motionValuesFrameValue = getConnectedInputPort("motionValues").pullFrame().asFrameValue();
float[] motionValues = (float[]) motionValuesFrameValue.getValue();
float vectorAccel = (float) Math.sqrt(Math.pow(motionValues[0], 2) + Math.pow(motionValues[1], 2) + Math.pow(motionValues[2], 2));
String outStr;
FrameValue capturingFrameValue = getConnectedInputPort("capturing").pullFrame().asFrameValue();
boolean capturing = (Boolean) capturingFrameValue.getValue();
FrameImage2D inputImage = getConnectedInputPort("image").pullFrame().asFrameImage2D();
// TODO: get rid of magic numbers
float score = 0.0f;
score = computePictureScore(vectorAccel, sharpness, underExposure, overExposure, contrastRating, colorfulness, brightness);
if (scoreMean == 0)
scoreMean = score;
else
scoreMean = scoreMean * (1 - DECAY) + score * DECAY;
if (motionMean == 0)
motionMean = vectorAccel;
else
motionMean = motionMean * (1 - DECAY) + vectorAccel * DECAY;
float classifierScore = classifierComputeScore(vectorAccel, sharpness, underExposure, colorfulness, contrastRating, score);
// Log.v(TAG, "ClassifierScore:: " + classifierScore);
final float GREAT_SCORE = 3.5f;
final float GOOD_SCORE = 2.5f;
final float OK_SCORE = 1.5f;
final float BAD_SCORE = 0.5f;
if (score >= GREAT_SCORE) {
outStr = GREAT;
} else if (score >= GOOD_SCORE) {
outStr = GOOD;
} else if (score >= OK_SCORE) {
outStr = OK;
} else if (score >= BAD_SCORE) {
outStr = BAD;
} else {
outStr = AWFUL;
}
if (capturing) {
if (outStr.equals(GREAT)) {
// take a picture
Bitmap bitmap = inputImage.toBitmap();
new AsyncOperation().execute(bitmap);
final float RESET_FEATURES = 0.01f;
sharpnessMean = RESET_FEATURES;
underExposureMean = RESET_FEATURES;
overExposureMean = RESET_FEATURES;
contrastMean = RESET_FEATURES;
colorfulnessMean = RESET_FEATURES;
brightnessMean = RESET_FEATURES;
}
}
OutputPort outPort = getConnectedOutputPort("goodOrBadPic");
FrameValue stringFrame = outPort.fetchAvailableFrame(null).asFrameValue();
stringFrame.setValue(outStr);
outPort.pushFrame(stringFrame);
OutputPort scoreOutPort = getConnectedOutputPort("score");
FrameValue scoreFrame = scoreOutPort.fetchAvailableFrame(null).asFrameValue();
scoreFrame.setValue(score);
scoreOutPort.pushFrame(scoreFrame);
}
use of androidx.media.filterfw.FrameImage2D in project android_frameworks_base by DirtyUnicorns.
the class AvgBrightnessFilterTest method testBrightnessFilter.
public void testBrightnessFilter() throws Exception {
final int INPUT_WIDTH = 480;
final int INPUT_HEIGHT = 640;
FrameImage2D image = createFrame(FrameType.image2D(FrameType.ELEMENT_RGBA8888, FrameType.READ_CPU), new int[] { INPUT_WIDTH, INPUT_HEIGHT }).asFrameImage2D();
Bitmap bitmap = BitmapFactory.decodeStream(assetMgr.open("0002_000390.jpg"));
image.setBitmap(bitmap);
injectInputFrame("image", image);
process();
final float EXPECTED_RESULT = 0.35f;
assertEquals(EXPECTED_RESULT, ((Float) getOutputFrame("brightnessRating").asFrameValue().getValue()).floatValue(), 0.01f);
}
use of androidx.media.filterfw.FrameImage2D in project android_frameworks_base by DirtyUnicorns.
the class ContrastRatioFilterTest method testContrastFilter.
public void testContrastFilter() throws Exception {
final int INPUT_WIDTH = 480;
final int INPUT_HEIGHT = 640;
FrameImage2D image = createFrame(FrameType.image2D(FrameType.ELEMENT_RGBA8888, FrameType.READ_CPU), new int[] { INPUT_WIDTH, INPUT_HEIGHT }).asFrameImage2D();
Bitmap bitmap = BitmapFactory.decodeStream(assetMgr.open("0002_000390.jpg"));
image.setBitmap(bitmap);
injectInputFrame("image", image);
process();
final float EXPECTED_RESULT = 0.29901487f;
assertEquals(EXPECTED_RESULT, ((Float) getOutputFrame("contrastRating").asFrameValue().getValue()).floatValue(), 0.001f);
}
use of androidx.media.filterfw.FrameImage2D in project android_frameworks_base by DirtyUnicorns.
the class ExposureFilterTest method testExposureFilter.
public void testExposureFilter() throws Exception {
final int INPUT_WIDTH = 480;
final int INPUT_HEIGHT = 640;
FrameImage2D image = createFrame(FrameType.image2D(FrameType.ELEMENT_RGBA8888, FrameType.READ_CPU), new int[] { INPUT_WIDTH, INPUT_HEIGHT }).asFrameImage2D();
Bitmap bitmap = BitmapFactory.decodeStream(assetMgr.open("0002_000390.jpg"));
image.setBitmap(bitmap);
injectInputFrame("image", image);
process();
final float EXPECTED_OVEREXPOSURE = 0.00757f;
assertEquals(EXPECTED_OVEREXPOSURE, ((Float) getOutputFrame("overExposureRating").asFrameValue().getValue()).floatValue(), 0.001f);
final float EXPECTED_UNDEREXPOSURE = 0.2077f;
assertEquals(EXPECTED_UNDEREXPOSURE, ((Float) getOutputFrame("underExposureRating").asFrameValue().getValue()).floatValue(), 0.001f);
}
Aggregations