Search in sources :

Example 1 with FrameValue

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

the class AverageFilter method onProcess.

@Override
protected void onProcess() {
    FrameValue inFrameValue = getConnectedInputPort("sharpness").pullFrame().asFrameValue();
    if (counter < NUM_FRAMES && counter >= 0) {
        temp[counter] = ((Float) inFrameValue.getValue()).floatValue();
    }
    counter = (counter + 1) % NUM_FRAMES;
    float output = (temp[0] + temp[1] + temp[2] + temp[3] + temp[4]) / NUM_FRAMES;
    if (mLogVerbose)
        Log.v(TAG, "Avg= " + output + "temp1= " + temp[0] + "temp2= " + temp[1] + "temp3= " + temp[2] + "temp4=" + temp[3] + "temp5=" + temp[4]);
    OutputPort outPort = getConnectedOutputPort("avg");
    FrameValue outFrame = outPort.fetchAvailableFrame(null).asFrameValue();
    outFrame.setValue(output);
    outPort.pushFrame(outFrame);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameValue(androidx.media.filterfw.FrameValue)

Example 2 with FrameValue

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

the class CSVWriterFilter method onProcess.

@Override
protected void onProcess() {
    Log.v(TAG, "in csv writer on process");
    FrameValue sharpnessValue = getConnectedInputPort("sharpness").pullFrame().asFrameValue();
    float sharpness = ((Float) sharpnessValue.getValue()).floatValue();
    FrameValue overExposureValue = getConnectedInputPort("overExposure").pullFrame().asFrameValue();
    float overExposure = ((Float) overExposureValue.getValue()).floatValue();
    FrameValue underExposureValue = getConnectedInputPort("underExposure").pullFrame().asFrameValue();
    float underExposure = ((Float) underExposureValue.getValue()).floatValue();
    FrameValue colorfulnessValue = getConnectedInputPort("colorfulness").pullFrame().asFrameValue();
    float colorfulness = ((Float) colorfulnessValue.getValue()).floatValue();
    FrameValue contrastValue = getConnectedInputPort("contrastRating").pullFrame().asFrameValue();
    float contrast = ((Float) contrastValue.getValue()).floatValue();
    FrameValue brightnessValue = getConnectedInputPort("brightness").pullFrame().asFrameValue();
    float brightness = ((Float) brightnessValue.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));
    FrameValue imageFileNameFrameValue = getConnectedInputPort("imageFileName").pullFrame().asFrameValue();
    String imageFileName = ((String) imageFileNameFrameValue.getValue());
    FrameValue csvFilePathFrameValue = getConnectedInputPort("csvFilePath").pullFrame().asFrameValue();
    String csvFilePath = ((String) csvFilePathFrameValue.getValue());
    if (mFirstTime) {
        try {
            FileWriter fileWriter = new FileWriter(csvFilePath + "/CSVFile.csv");
            BufferedWriter csvWriter = new BufferedWriter(fileWriter);
            csvWriter.write("FileName,Sharpness,OverExposure,UnderExposure,Colorfulness," + "ContrastRating,Brightness,Motion");
            csvWriter.newLine();
            csvWriter.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        mFirstTime = false;
    }
    try {
        Log.v(TAG, "about to write to file");
        FileWriter fileWriter = new FileWriter(csvFilePath + mFileName, true);
        BufferedWriter csvWriter = new BufferedWriter(fileWriter);
        csvWriter.write(imageFileName + "," + sharpness + "," + overExposure + "," + underExposure + "," + colorfulness + "," + contrast + "," + brightness + "," + vectorAccel);
        Log.v(TAG, "" + imageFileName + "," + sharpness + "," + overExposure + "," + underExposure + "," + colorfulness + "," + contrast + "," + brightness + "," + vectorAccel);
        csvWriter.newLine();
        csvWriter.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) FrameValue(androidx.media.filterfw.FrameValue) BufferedWriter(java.io.BufferedWriter)

Example 3 with FrameValue

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

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 4 with FrameValue

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

the class IfElseFilterTest method testIfElseFilterFalse.

public void testIfElseFilterFalse() throws Exception {
    FrameImage2D image = createFrame(FrameType.image2D(FrameType.ELEMENT_RGBA8888, FrameType.READ_CPU), new int[] { BIG_INPUT_WIDTH, BIG_INPUT_HEIGHT }).asFrameImage2D();
    FrameImage2D video = createFrame(FrameType.image2D(FrameType.ELEMENT_RGBA8888, FrameType.READ_CPU), new int[] { SMALL_INPUT_WIDTH, SMALL_INPUT_HEIGHT }).asFrameImage2D();
    // Image of legs
    Bitmap videoBitmap = BitmapFactory.decodeStream(assetMgr.open("0002_000390.jpg"));
    // Image of a face
    Bitmap imageBitmap = BitmapFactory.decodeStream(assetMgr.open("XZZ019.jpg"));
    image.setBitmap(imageBitmap);
    injectInputFrame("falseResult", image);
    video.setBitmap(videoBitmap);
    injectInputFrame("trueResult", video);
    FrameValue conditionFrame = createFrame(FrameType.single(boolean.class), new int[] { 1 }).asFrameValue();
    conditionFrame.setValue(false);
    injectInputFrame("condition", conditionFrame);
    process();
    // Ensure that for true, we use the video input
    FrameImage2D outputImage = getOutputFrame("output").asFrameImage2D();
    assertEquals(outputImage, image);
}
Also used : Bitmap(android.graphics.Bitmap) FrameImage2D(androidx.media.filterfw.FrameImage2D) FrameValue(androidx.media.filterfw.FrameValue)

Example 5 with FrameValue

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

the class IfElseFilterTest method testIfElseFilterTrue.

public void testIfElseFilterTrue() throws Exception {
    FrameImage2D image = createFrame(FrameType.image2D(FrameType.ELEMENT_RGBA8888, FrameType.READ_CPU), new int[] { BIG_INPUT_WIDTH, BIG_INPUT_HEIGHT }).asFrameImage2D();
    FrameImage2D video = createFrame(FrameType.image2D(FrameType.ELEMENT_RGBA8888, FrameType.READ_CPU), new int[] { SMALL_INPUT_WIDTH, SMALL_INPUT_HEIGHT }).asFrameImage2D();
    // Image of legs
    Bitmap videoBitmap = BitmapFactory.decodeStream(assetMgr.open("0002_000390.jpg"));
    // Image of a face
    Bitmap imageBitmap = BitmapFactory.decodeStream(assetMgr.open("XZZ019.jpg"));
    image.setBitmap(imageBitmap);
    injectInputFrame("falseResult", image);
    video.setBitmap(videoBitmap);
    injectInputFrame("trueResult", video);
    FrameValue conditionFrame = createFrame(FrameType.single(boolean.class), new int[] { 1 }).asFrameValue();
    conditionFrame.setValue(true);
    injectInputFrame("condition", conditionFrame);
    process();
    // Ensure that for true, we use the video input
    FrameImage2D outputImage = getOutputFrame("output").asFrameImage2D();
    assertEquals(outputImage, video);
}
Also used : Bitmap(android.graphics.Bitmap) FrameImage2D(androidx.media.filterfw.FrameImage2D) 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