Search in sources :

Example 11 with FrameValue

use of androidx.media.filterfw.FrameValue in project platform_frameworks_base by android.

the class FloatArrayToSizeFilter method onProcess.

/**
     * @see androidx.media.filterfw.Filter#onProcess()
     */
@Override
protected void onProcess() {
    FrameValue arrayFrame = getConnectedInputPort("array").pullFrame().asFrameValues();
    Object array = arrayFrame.getValue();
    int size = Array.getLength(array);
    OutputPort outPort = getConnectedOutputPort("size");
    FrameValue sizeFrame = outPort.fetchAvailableFrame(null).asFrameValue();
    sizeFrame.setValue(size);
    outPort.pushFrame(sizeFrame);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameValue(androidx.media.filterfw.FrameValue)

Example 12 with FrameValue

use of androidx.media.filterfw.FrameValue in project platform_frameworks_base by android.

the class FloatArrayToStrFilter method onProcess.

/**
     * @see androidx.media.filterfw.Filter#onProcess()
     */
@Override
protected void onProcess() {
    FrameValue arrayFrame = getConnectedInputPort("array").pullFrame().asFrameValues();
    float[] array = (float[]) arrayFrame.getValue();
    String outstr = Arrays.toString(array);
    OutputPort outPort = getConnectedOutputPort("string");
    FrameValue stringFrame = outPort.fetchAvailableFrame(null).asFrameValue();
    stringFrame.setValue(outstr);
    outPort.pushFrame(stringFrame);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameValue(androidx.media.filterfw.FrameValue)

Example 13 with FrameValue

use of androidx.media.filterfw.FrameValue in project platform_frameworks_base by android.

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);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) Bitmap(android.graphics.Bitmap) FrameImage2D(androidx.media.filterfw.FrameImage2D) FrameValue(androidx.media.filterfw.FrameValue)

Example 14 with FrameValue

use of androidx.media.filterfw.FrameValue in project platform_frameworks_base by android.

the class NormFilter method onProcess.

@Override
protected void onProcess() {
    FrameValue xFrameValue = getConnectedInputPort("x").pullFrame().asFrameValue();
    float xValue = ((Float) xFrameValue.getValue()).floatValue();
    FrameValue yFrameValue = getConnectedInputPort("y").pullFrame().asFrameValue();
    float yValue = ((Float) yFrameValue.getValue()).floatValue();
    float norm = (float) Math.hypot(xValue, yValue);
    if (mLogVerbose)
        Log.v(TAG, "Norm = " + norm);
    OutputPort outPort = getConnectedOutputPort("norm");
    FrameValue outFrame = outPort.fetchAvailableFrame(null).asFrameValue();
    outFrame.setValue(norm);
    outPort.pushFrame(outFrame);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameValue(androidx.media.filterfw.FrameValue)

Example 15 with FrameValue

use of androidx.media.filterfw.FrameValue in project platform_frameworks_base by android.

the class TextViewTarget method onProcess.

@Override
protected void onProcess() {
    FrameValue textFrame = getConnectedInputPort("text").pullFrame().asFrameValue();
    final String text = (String) textFrame.getValue();
    if (mTextView != null) {
        mTextView.post(new Runnable() {

            @Override
            public void run() {
                mTextView.setText(text);
            }
        });
    }
}
Also used : FrameValue(androidx.media.filterfw.FrameValue)

Aggregations

FrameValue (androidx.media.filterfw.FrameValue)112 OutputPort (androidx.media.filterfw.OutputPort)60 FrameImage2D (androidx.media.filterfw.FrameImage2D)32 ByteBuffer (java.nio.ByteBuffer)20 Bitmap (android.graphics.Bitmap)12 FrameBuffer2D (androidx.media.filterfw.FrameBuffer2D)12 FrameValues (androidx.media.filterfw.FrameValues)4 BufferedWriter (java.io.BufferedWriter)4 FileWriter (java.io.FileWriter)4 IOException (java.io.IOException)4 FloatBuffer (java.nio.FloatBuffer)4