Search in sources :

Example 86 with FrameValue

use of androidx.media.filterfw.FrameValue in project android_frameworks_base by ResurrectionRemix.

the class ColorfulnessFilter method onProcess.

@Override
protected void onProcess() {
    FrameBuffer2D histogramFrame = getConnectedInputPort("histogram").pullFrame().asFrameBuffer2D();
    ByteBuffer byteBuffer = histogramFrame.lockBytes(Frame.MODE_READ);
    byteBuffer.order(ByteOrder.nativeOrder());
    FloatBuffer histogramBuffer = byteBuffer.asFloatBuffer();
    histogramBuffer.rewind();
    // Create a hue histogram from hue-saturation histogram
    int hueBins = histogramFrame.getWidth();
    int saturationBins = histogramFrame.getHeight() - 1;
    float[] hueHistogram = new float[hueBins];
    float total = 0;
    for (int r = 0; r < saturationBins; ++r) {
        float weight = (float) Math.pow(2, r);
        for (int c = 0; c < hueBins; c++) {
            float value = histogramBuffer.get() * weight;
            hueHistogram[c] += value;
            total += value;
        }
    }
    float colorful = 0f;
    for (int c = 0; c < hueBins; ++c) {
        float value = hueHistogram[c] / total;
        if (value > 0f) {
            colorful -= value * ((float) Math.log(value));
        }
    }
    colorful /= Math.log(2);
    histogramFrame.unlock();
    OutputPort outPort = getConnectedOutputPort("score");
    FrameValue frameValue = outPort.fetchAvailableFrame(null).asFrameValue();
    frameValue.setValue(colorful);
    outPort.pushFrame(frameValue);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameBuffer2D(androidx.media.filterfw.FrameBuffer2D) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) FrameValue(androidx.media.filterfw.FrameValue)

Example 87 with FrameValue

use of androidx.media.filterfw.FrameValue in project android_frameworks_base by ResurrectionRemix.

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

use of androidx.media.filterfw.FrameValue in project android_frameworks_base by ResurrectionRemix.

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)

Example 89 with FrameValue

use of androidx.media.filterfw.FrameValue in project android_frameworks_base by ResurrectionRemix.

the class ToStringFilter method onProcess.

@Override
protected void onProcess() {
    FrameValue objectFrame = getConnectedInputPort("object").pullFrame().asFrameValue();
    String outStr = objectFrame.getValue().toString();
    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 90 with FrameValue

use of androidx.media.filterfw.FrameValue in project android_frameworks_base by ResurrectionRemix.

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)

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