Search in sources :

Example 66 with FrameValue

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

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

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

the class StatsFilter method onProcess.

/**
     * @see androidx.media.filterfw.Filter#onProcess()
     */
@Override
protected void onProcess() {
    FrameBuffer2D inputFrame = getConnectedInputPort("buffer").pullFrame().asFrameImage2D();
    ByteBuffer pixelBuffer = inputFrame.lockBytes(Frame.MODE_READ);
    calcMeanAndStd(pixelBuffer, inputFrame.getWidth(), inputFrame.getHeight(), mCropRect);
    inputFrame.unlock();
    OutputPort outPort = getConnectedOutputPort("mean");
    FrameValue outFrame = outPort.fetchAvailableFrame(null).asFrameValue();
    outFrame.setValue(mStats[MEAN_INDEX]);
    outPort.pushFrame(outFrame);
    OutputPort outPortStdev = getConnectedOutputPort("stdev");
    FrameValue outFrameStdev = outPortStdev.fetchAvailableFrame(null).asFrameValue();
    outFrameStdev.setValue(mStats[STDEV_INDEX]);
    outPortStdev.pushFrame(outFrameStdev);
}
Also used : OutputPort(androidx.media.filterfw.OutputPort) FrameBuffer2D(androidx.media.filterfw.FrameBuffer2D) ByteBuffer(java.nio.ByteBuffer) FrameValue(androidx.media.filterfw.FrameValue)

Example 68 with FrameValue

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

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

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

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

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

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)

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