Search in sources :

Example 86 with OutputPort

use of androidx.media.filterfw.OutputPort in project android_frameworks_base by crdroidandroid.

the class ToGrayValuesFilter method onProcess.

@Override
protected void onProcess() {
    OutputPort outPort = getConnectedOutputPort("image");
    FrameImage2D inputImage = getConnectedInputPort("image").pullFrame().asFrameImage2D();
    int[] dim = inputImage.getDimensions();
    FrameBuffer2D outputFrame;
    ByteBuffer grayBuffer;
    if (isOpenGLSupported()) {
        // crop out the portion of inputImage that will be used to generate outputFrame.
        int modular = dim[0] % 4;
        int[] outDim = new int[] { dim[0] - modular, dim[1] };
        outputFrame = outPort.fetchAvailableFrame(outDim).asFrameBuffer2D();
        grayBuffer = outputFrame.lockBytes(Frame.MODE_WRITE);
        int[] targetDims = new int[] { outDim[0] / 4, outDim[1] };
        FrameImage2D targetFrame = Frame.create(mImageInType, targetDims).asFrameImage2D();
        mShader.setSourceQuad(Quad.fromRect(0f, 0f, ((float) outDim[0]) / dim[0], 1f));
        mShader.setUniformValue("pix_stride", 1f / outDim[0]);
        mShader.process(inputImage, targetFrame);
        RenderTarget grayTarget = targetFrame.lockRenderTarget();
        grayTarget.readPixelData(grayBuffer, targetDims[0], targetDims[1]);
        targetFrame.unlock();
        targetFrame.release();
    } else {
        outputFrame = outPort.fetchAvailableFrame(dim).asFrameBuffer2D();
        grayBuffer = outputFrame.lockBytes(Frame.MODE_WRITE);
        ByteBuffer inputBuffer = inputImage.lockBytes(Frame.MODE_READ);
        if (!toGrayValues(inputBuffer, grayBuffer)) {
            throw new RuntimeException("Native implementation encountered an error during processing!");
        }
        inputImage.unlock();
    }
    outputFrame.unlock();
    outPort.pushFrame(outputFrame);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameBuffer2D(androidx.media.filterfw.FrameBuffer2D) FrameImage2D(androidx.media.filterfw.FrameImage2D) RenderTarget(androidx.media.filterfw.RenderTarget) ByteBuffer(java.nio.ByteBuffer)

Example 87 with OutputPort

use of androidx.media.filterfw.OutputPort in project android_frameworks_base by crdroidandroid.

the class Camera2Source method onProcess.

@Override
protected void onProcess() {
    Log.v(TAG, "on Process");
    if (nextFrame()) {
        OutputPort outPort = getConnectedOutputPort("video");
        // Create a 2D frame that will hold the output
        int[] dims = new int[] { mWidth, mHeight };
        FrameImage2D outputFrame = Frame.create(mOutputType, dims).asFrameImage2D();
        rgbConverter.forEach(mAllocationOut);
        mAllocationOut.copyTo(mBitmap);
        outputFrame.setBitmap(mBitmap);
        outPort.pushFrame(outputFrame);
        outputFrame.release();
        OutputPort orientationPort = getConnectedOutputPort("orientation");
        FrameValue orientationFrame = orientationPort.fetchAvailableFrame(null).asFrameValue();
        // FIXME: Hardcoded value because ORIENTATION returns null, Qualcomm
        // bug
        Integer orientation = mProperties.get(CameraCharacteristics.SENSOR_ORIENTATION);
        float temp;
        if (orientation != null) {
            temp = orientation.floatValue();
        } else {
            temp = 90.0f;
        }
        orientationFrame.setValue(temp);
        orientationPort.pushFrame(orientationFrame);
    }
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameImage2D(androidx.media.filterfw.FrameImage2D) FrameValue(androidx.media.filterfw.FrameValue)

Example 88 with OutputPort

use of androidx.media.filterfw.OutputPort in project android_frameworks_base by crdroidandroid.

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 89 with OutputPort

use of androidx.media.filterfw.OutputPort in project android_frameworks_base by crdroidandroid.

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

Example 90 with OutputPort

use of androidx.media.filterfw.OutputPort in project android_frameworks_base by crdroidandroid.

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)

Aggregations

OutputPort (androidx.media.filterfw.OutputPort)92 FrameValue (androidx.media.filterfw.FrameValue)60 FrameImage2D (androidx.media.filterfw.FrameImage2D)48 ByteBuffer (java.nio.ByteBuffer)36 FrameBuffer2D (androidx.media.filterfw.FrameBuffer2D)20 FrameValues (androidx.media.filterfw.FrameValues)12 Bitmap (android.graphics.Bitmap)8 Quad (androidx.media.filterfw.geometry.Quad)8 FloatBuffer (java.nio.FloatBuffer)8 Canvas (android.graphics.Canvas)4 Matrix (android.graphics.Matrix)4 Paint (android.graphics.Paint)4 Face (android.hardware.Camera.Face)4 RenderTarget (androidx.media.filterfw.RenderTarget)4