diff options
author | Linux Build Service Account <lnxbuild@localhost> | 2017-03-03 17:28:34 -0800 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2017-03-03 17:28:34 -0800 |
commit | 08fd546be5672e9d27a0c5343f581c03bdbe5db6 (patch) | |
tree | 9d614e5c41d4e8eb3c3a246173b15f55584273d2 /src | |
parent | aca636015e3d82552f7066f35429129aab976313 (diff) | |
parent | 574d7516850e08e0d2ee2c5d68cbb710d6669998 (diff) | |
download | android_packages_apps_Snap-08fd546be5672e9d27a0c5343f581c03bdbe5db6.tar.gz android_packages_apps_Snap-08fd546be5672e9d27a0c5343f581c03bdbe5db6.tar.bz2 android_packages_apps_Snap-08fd546be5672e9d27a0c5343f581c03bdbe5db6.zip |
Merge "SnapdragonCamera: Wrapper for QC API" into camera.lnx.1.0-dev.1.0
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/camera/ui/FaceView.java | 144 | ||||
-rw-r--r-- | src/org/codeaurora/snapcam/wrapper/ExtendedFaceWrapper.java | 127 |
2 files changed, 199 insertions, 72 deletions
diff --git a/src/com/android/camera/ui/FaceView.java b/src/com/android/camera/ui/FaceView.java index dfa84ec5c..9a310afdb 100644 --- a/src/com/android/camera/ui/FaceView.java +++ b/src/com/android/camera/ui/FaceView.java @@ -34,7 +34,7 @@ import android.view.View; import com.android.camera.PhotoUI; import com.android.camera.util.CameraUtil; import org.codeaurora.snapcam.R; -import org.codeaurora.camera.ExtendedFace; +import org.codeaurora.snapcam.wrapper.ExtendedFaceWrapper; public class FaceView extends View implements FocusIndicator, Rotatable, @@ -233,113 +233,113 @@ public class FaceView extends View mRect.offset(dx, dy); canvas.drawOval(mRect, mPaint); - if (mFaces[i] instanceof ExtendedFace) { - ExtendedFace face = (ExtendedFace)mFaces[i]; + if (ExtendedFaceWrapper.isExtendedFaceInstance(mFaces[i])) { + ExtendedFaceWrapper wrapper = new ExtendedFaceWrapper(mFaces[i]); float[] point = new float[4]; int delta_x = mFaces[i].rect.width() / 12; int delta_y = mFaces[i].rect.height() / 12; - Log.e(TAG, "blink: (" + face.getLeftEyeBlinkDegree()+ ", " + - face.getRightEyeBlinkDegree() + ")"); - if (face.leftEye != null) { + Log.e(TAG, "blink: (" + wrapper.getLeftEyeBlinkDegree()+ ", " + + wrapper.getRightEyeBlinkDegree() + ")"); + if (wrapper.mFace.leftEye != null) { if ((mDisplayRotation == 0) || (mDisplayRotation == 180)) { - point[0] = face.leftEye.x; - point[1] = face.leftEye.y - delta_y / 2; - point[2] = face.leftEye.x; - point[3] = face.leftEye.y + delta_y / 2; + point[0] = wrapper.mFace.leftEye.x; + point[1] = wrapper.mFace.leftEye.y - delta_y / 2; + point[2] = wrapper.mFace.leftEye.x; + point[3] = wrapper.mFace.leftEye.y + delta_y / 2; } else { - point[0] = face.leftEye.x - delta_x / 2; - point[1] = face.leftEye.y; - point[2] = face.leftEye.x + delta_x / 2; - point[3] = face.leftEye.y; + point[0] = wrapper.mFace.leftEye.x - delta_x / 2; + point[1] = wrapper.mFace.leftEye.y; + point[2] = wrapper.mFace.leftEye.x + delta_x / 2; + point[3] = wrapper.mFace.leftEye.y; } mMatrix.mapPoints (point); - if (face.getLeftEyeBlinkDegree() >= blink_threshold) { + if (wrapper.getLeftEyeBlinkDegree() >= blink_threshold) { canvas.drawLine(point[0]+ dx, point[1]+ dy, point[2]+ dx, point[3]+ dy, mPaint); } } - if (face.rightEye != null) { + if (wrapper.mFace.rightEye != null) { if ((mDisplayRotation == 0) || (mDisplayRotation == 180)) { - point[0] = face.rightEye.x; - point[1] = face.rightEye.y - delta_y / 2; - point[2] = face.rightEye.x; - point[3] = face.rightEye.y + delta_y / 2; + point[0] = wrapper.mFace.rightEye.x; + point[1] = wrapper.mFace.rightEye.y - delta_y / 2; + point[2] = wrapper.mFace.rightEye.x; + point[3] = wrapper.mFace.rightEye.y + delta_y / 2; } else { - point[0] = face.rightEye.x - delta_x / 2; - point[1] = face.rightEye.y; - point[2] = face.rightEye.x + delta_x / 2; - point[3] = face.rightEye.y; + point[0] = wrapper.mFace.rightEye.x - delta_x / 2; + point[1] = wrapper.mFace.rightEye.y; + point[2] = wrapper.mFace.rightEye.x + delta_x / 2; + point[3] = wrapper.mFace.rightEye.y; } mMatrix.mapPoints (point); - if (face.getRightEyeBlinkDegree() >= blink_threshold) { + if (wrapper.getRightEyeBlinkDegree() >= blink_threshold) { //Add offset to the points if the rect has an offset canvas.drawLine(point[0] + dx, point[1] + dy, point[2] +dx, point[3] +dy, mPaint); } } - if (face.getLeftRightGazeDegree() != 0 - || face.getTopBottomGazeDegree() != 0 ) { + if (wrapper.getLeftRightGazeDegree() != 0 + || wrapper.getTopBottomGazeDegree() != 0 ) { double length = - Math.sqrt((face.leftEye.x - face.rightEye.x) * - (face.leftEye.x - face.rightEye.x) + - (face.leftEye.y - face.rightEye.y) * - (face.leftEye.y - face.rightEye.y)) / 2.0; - double nGazeYaw = -face.getLeftRightGazeDegree(); - double nGazePitch = -face.getTopBottomGazeDegree(); + Math.sqrt((wrapper.mFace.leftEye.x - wrapper.mFace.rightEye.x) * + (wrapper.mFace.leftEye.x - wrapper.mFace.rightEye.x) + + (wrapper.mFace.leftEye.y - wrapper.mFace.rightEye.y) * + (wrapper.mFace.leftEye.y - wrapper.mFace.rightEye.y)) / 2.0; + double nGazeYaw = -wrapper.getLeftRightGazeDegree(); + double nGazePitch = -wrapper.getTopBottomGazeDegree(); float gazeRollX = (float)((-Math.sin(nGazeYaw/180.0*Math.PI) * - Math.cos(-face.getRollDirection()/ + Math.cos(-wrapper.getRollDirection()/ 180.0*Math.PI) + Math.sin(nGazePitch/180.0*Math.PI) * Math.cos(nGazeYaw/180.0*Math.PI) * - Math.sin(-face.getRollDirection()/ + Math.sin(-wrapper.getRollDirection()/ 180.0*Math.PI)) * (-length) + 0.5); float gazeRollY = (float)((Math.sin(-nGazeYaw/180.0*Math.PI) * - Math.sin(-face.getRollDirection()/ + Math.sin(-wrapper.getRollDirection()/ 180.0*Math.PI)- Math.sin(nGazePitch/180.0*Math.PI) * Math.cos(nGazeYaw/180.0*Math.PI) * - Math.cos(-face.getRollDirection()/ + Math.cos(-wrapper.getRollDirection()/ 180.0*Math.PI)) * (-length) + 0.5); - if (face.getLeftEyeBlinkDegree() < blink_threshold) { + if (wrapper.getLeftEyeBlinkDegree() < blink_threshold) { if ((mDisplayRotation == 90) || (mDisplayRotation == 270)) { - point[0] = face.leftEye.x; - point[1] = face.leftEye.y; - point[2] = face.leftEye.x + gazeRollX; - point[3] = face.leftEye.y + gazeRollY; + point[0] = wrapper.mFace.leftEye.x; + point[1] = wrapper.mFace.leftEye.y; + point[2] = wrapper.mFace.leftEye.x + gazeRollX; + point[3] = wrapper.mFace.leftEye.y + gazeRollY; } else { - point[0] = face.leftEye.x; - point[1] = face.leftEye.y; - point[2] = face.leftEye.x + gazeRollY; - point[3] = face.leftEye.y + gazeRollX; + point[0] = wrapper.mFace.leftEye.x; + point[1] = wrapper.mFace.leftEye.y; + point[2] = wrapper.mFace.leftEye.x + gazeRollY; + point[3] = wrapper.mFace.leftEye.y + gazeRollX; } mMatrix.mapPoints (point); canvas.drawLine(point[0] +dx, point[1] + dy, point[2] + dx, point[3] +dy, mPaint); } - if (face.getRightEyeBlinkDegree() < blink_threshold) { + if (wrapper.getRightEyeBlinkDegree() < blink_threshold) { if ((mDisplayRotation == 90) || (mDisplayRotation == 270)) { - point[0] = face.rightEye.x; - point[1] = face.rightEye.y; - point[2] = face.rightEye.x + gazeRollX; - point[3] = face.rightEye.y + gazeRollY; + point[0] = wrapper.mFace.rightEye.x; + point[1] = wrapper.mFace.rightEye.y; + point[2] = wrapper.mFace.rightEye.x + gazeRollX; + point[3] = wrapper.mFace.rightEye.y + gazeRollY; } else { - point[0] = face.rightEye.x; - point[1] = face.rightEye.y; - point[2] = face.rightEye.x + gazeRollY; - point[3] = face.rightEye.y + gazeRollX; + point[0] = wrapper.mFace.rightEye.x; + point[1] = wrapper.mFace.rightEye.y; + point[2] = wrapper.mFace.rightEye.x + gazeRollY; + point[3] = wrapper.mFace.rightEye.y + gazeRollX; } mMatrix.mapPoints (point); @@ -348,35 +348,35 @@ public class FaceView extends View } } - if (face.mouth != null) { - Log.e(TAG, "smile: " + face.getSmileDegree() + "," + - face.getSmileScore()); - if (face.getSmileDegree() < smile_threashold_no_smile) { - point[0] = face.mouth.x + dx - delta_x; - point[1] = face.mouth.y; - point[2] = face.mouth.x + dx + delta_x; - point[3] = face.mouth.y; + if (wrapper.mFace.mouth != null) { + Log.e(TAG, "smile: " + wrapper.getSmileDegree() + "," + + wrapper.getSmileScore()); + if (wrapper.getSmileDegree() < smile_threashold_no_smile) { + point[0] = wrapper.mFace.mouth.x + dx - delta_x; + point[1] = wrapper.mFace.mouth.y; + point[2] = wrapper.mFace.mouth.x + dx + delta_x; + point[3] = wrapper.mFace.mouth.y; Matrix faceMatrix = new Matrix(mMatrix); - faceMatrix.preRotate(face.getRollDirection(), - face.mouth.x, face.mouth.y); + faceMatrix.preRotate(wrapper.getRollDirection(), + wrapper.mFace.mouth.x, wrapper.mFace.mouth.y); faceMatrix.mapPoints(point); canvas.drawLine(point[0] + dx, point[1] + dy, point[2] + dx, point[3] + dy, mPaint); - } else if (face.getSmileDegree() < + } else if (wrapper.getSmileDegree() < smile_threashold_small_smile) { int rotation_mouth = 360 - mDisplayRotation; - mRect.set(face.mouth.x-delta_x, - face.mouth.y-delta_y, face.mouth.x+delta_x, - face.mouth.y+delta_y); + mRect.set(wrapper.mFace.mouth.x-delta_x, + wrapper.mFace.mouth.y-delta_y, wrapper.mFace.mouth.x+delta_x, + wrapper.mFace.mouth.y+delta_y); mMatrix.mapRect(mRect); mRect.offset(dx, dy); canvas.drawArc(mRect, rotation_mouth, 180, true, mPaint); } else { - mRect.set(face.mouth.x-delta_x, - face.mouth.y-delta_y, face.mouth.x+delta_x, - face.mouth.y+delta_y); + mRect.set(wrapper.mFace.mouth.x-delta_x, + wrapper.mFace.mouth.y-delta_y, wrapper.mFace.mouth.x+delta_x, + wrapper.mFace.mouth.y+delta_y); mMatrix.mapRect(mRect); mRect.offset(dx, dy); canvas.drawOval(mRect, mPaint); diff --git a/src/org/codeaurora/snapcam/wrapper/ExtendedFaceWrapper.java b/src/org/codeaurora/snapcam/wrapper/ExtendedFaceWrapper.java new file mode 100644 index 000000000..4c92e630d --- /dev/null +++ b/src/org/codeaurora/snapcam/wrapper/ExtendedFaceWrapper.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2017, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.codeaurora.snapcam.wrapper; + +import java.lang.reflect.Method; + +import android.hardware.Camera.Face; +import android.os.Bundle; + +public class ExtendedFaceWrapper{ + private final static String CLASS_NAME = "org.codeaurora.camera.ExtendedFace"; + private static Class<?> mExtendFaceClass; + public Face mFace; + public ExtendedFaceWrapper(Face face){ + mFace = face; + } + + public static boolean isExtendedFaceInstance(Object object) { + if ( mExtendFaceClass == null ){ + try { + mExtendFaceClass = Class.forName(CLASS_NAME); + }catch (Exception exception){ + exception.printStackTrace(); + return false; + } + } + return mExtendFaceClass.isInstance(object); + } + + public int getSmileDegree() { + return (int)invokeMethod("getSmileDegree"); + } + + public int getSmileScore() { + return (int)invokeMethod("getSmileScore"); + } + + public int getBlinkDetected() { + return (int)invokeMethod("getBlinkDetected"); + } + + + public int getFaceRecognized() { + return (int)invokeMethod("getFaceRecognized"); + } + + public int getGazeAngle() { + return (int)invokeMethod("getGazeAngle"); + } + + public int getUpDownDirection() { + return (int)invokeMethod("getUpDownDirection"); + } + + public int getLeftRightDirection() { + return (int)invokeMethod("getLeftRightDirection"); + } + + + public int getRollDirection() { + return (int)invokeMethod("getRollDirection"); + } + + public int getLeftEyeBlinkDegree() { + return (int)invokeMethod("getLeftEyeBlinkDegree"); + } + + + public int getRightEyeBlinkDegree() { + return (int)invokeMethod("getRightEyeBlinkDegree"); + } + + + public int getLeftRightGazeDegree() { + return (int)invokeMethod("getLeftRightGazeDegree"); + } + + + public int getTopBottomGazeDegree() { + return (int)invokeMethod("getTopBottomGazeDegree"); + } + + public Bundle getExtendedFaceInfo() { + return (Bundle)invokeMethod("getExtendedFaceInfo"); + } + + private Object invokeMethod(String name){ + Object result = null; + try { + if ( mExtendFaceClass == null ){ + mExtendFaceClass = Class.forName(CLASS_NAME); + } + Method method = mExtendFaceClass.getDeclaredMethod(name); + result = method.invoke(mFace); + }catch(Exception exception){ + exception.printStackTrace(); + } + return result; + } +} |