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);
}
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);
}
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);
}
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);
}
}
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);
}
}
Aggregations