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