1
0
mirror of https://github.com/MGislv/NekoX.git synced 2024-07-02 10:33:36 +00:00

[TF][KILL] Google Vision

(cherry picked from commit 92204aada397a19354ed9212c593b8479be26679)
This commit is contained in:
thermatk 2020-01-03 10:51:34 +01:00 committed by 世界
parent ec6a123f2f
commit f79ff18925
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
6 changed files with 18 additions and 170 deletions

View File

@ -29,7 +29,6 @@ dependencies {
implementation 'com.google.firebase:firebase-messaging:20.2.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-auth:18.0.0'
implementation 'com.google.android.gms:play-services-vision:16.2.0'
implementation 'com.google.android.gms:play-services-wearable:17.0.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.googlecode.mp4parser:isoparser:1.0.6'

View File

@ -398,8 +398,6 @@
<meta-data android:name="com.google.android.gms.car.notification.SmallIcon" android:resource="@drawable/ic_player" />
<meta-data android:name="com.google.android.gms.car.application" android:resource="@xml/automotive_app_desc" />
<meta-data android:name="com.google.android.gms.vision.DEPENDENCIES" android:value="face,barcode" />
<meta-data android:name="android.max_aspect" android:value="2.5" />
<meta-data

View File

@ -11,10 +11,6 @@ import android.text.TextUtils;
import android.util.Base64;
import android.util.SparseArray;
import com.google.android.gms.vision.Frame;
import com.google.android.gms.vision.barcode.Barcode;
import com.google.android.gms.vision.barcode.BarcodeDetector;
import java.util.Calendar;
import java.util.HashMap;
@ -42,7 +38,8 @@ public class MrzRecognizer {
}
private static Result recognizeBarcode(Bitmap bitmap) {
BarcodeDetector detector = new BarcodeDetector.Builder(ApplicationLoader.applicationContext)/*.setBarcodeFormats(Barcode.PDF417)*/.build();
/*
BarcodeDetector detector = new BarcodeDetector.Builder(ApplicationLoader.applicationContext)/*.setBarcodeFormats(Barcode.PDF417).build();
if (bitmap.getWidth() > 1500 || bitmap.getHeight() > 1500) {
float scale = 1500f / Math.max(bitmap.getWidth(), bitmap.getHeight());
bitmap = Bitmap.createScaledBitmap(bitmap, Math.round(bitmap.getWidth() * scale), Math.round(bitmap.getHeight() * scale), true);
@ -127,7 +124,7 @@ public class MrzRecognizer {
}
}
}
}
}*/
return null;
}

View File

@ -33,9 +33,6 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.google.android.gms.vision.Frame;
import com.google.android.gms.vision.barcode.Barcode;
import com.google.android.gms.vision.barcode.BarcodeDetector;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.LuminanceSource;
import com.google.zxing.PlanarYUVLuminanceSource;
@ -89,7 +86,7 @@ public class CameraScanActivity extends BaseFragment implements Camera.PreviewCa
private boolean recognized;
private QRCodeReader qrReader;
private BarcodeDetector visionQrReader;
//private BarcodeDetector visionQrReader;
private boolean needGalleryButton;
@ -173,7 +170,7 @@ public class CameraScanActivity extends BaseFragment implements Camera.PreviewCa
currentType = type;
if (currentType == TYPE_QR) {
qrReader = new QRCodeReader();
visionQrReader = new BarcodeDetector.Builder(ApplicationLoader.applicationContext).setBarcodeFormats(Barcode.QR_CODE).build();
//visionQrReader = new BarcodeDetector.Builder(ApplicationLoader.applicationContext).setBarcodeFormats(Barcode.QR_CODE).build();
}
}
@ -184,9 +181,9 @@ public class CameraScanActivity extends BaseFragment implements Camera.PreviewCa
if (getParentActivity() != null) {
getParentActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}
if (visionQrReader != null) {
/*if (visionQrReader != null) {
visionQrReader.release();
}
}*/
}
@Override
@ -596,7 +593,7 @@ public class CameraScanActivity extends BaseFragment implements Camera.PreviewCa
private String tryReadQr(byte[] data, Size size, int x, int y, int side, Bitmap bitmap) {
try {
String text;
if (visionQrReader.isOperational()) {
/*if (visionQrReader.isOperational()) {
Frame frame;
if (bitmap != null) {
frame = new Frame.Builder().setBitmap(bitmap).build();
@ -609,7 +606,7 @@ public class CameraScanActivity extends BaseFragment implements Camera.PreviewCa
} else {
text = null;
}
} else {
} else {*/
LuminanceSource source;
if (bitmap != null) {
int[] intArray = new int[bitmap.getWidth() * bitmap.getHeight()];
@ -625,7 +622,7 @@ public class CameraScanActivity extends BaseFragment implements Camera.PreviewCa
return null;
}
text = result.getText();
}
//}
if (TextUtils.isEmpty(text)) {
onNoQrFound();
return null;

View File

@ -1,141 +0,0 @@
package org.telegram.ui.Components.Paint;
import android.graphics.Bitmap;
import android.graphics.PointF;
import com.google.android.gms.vision.face.Face;
import com.google.android.gms.vision.face.Landmark;
import org.telegram.ui.Components.Size;
import org.telegram.ui.Components.Point;
import java.util.List;
public class PhotoFace {
private float width;
private float angle;
private Point foreheadPoint;
private Point eyesCenterPoint;
private float eyesDistance;
private Point mouthPoint;
private Point chinPoint;
public PhotoFace(Face face, Bitmap sourceBitmap, Size targetSize, boolean sideward) {
List<Landmark> landmarks = face.getLandmarks();
Point leftEyePoint = null;
Point rightEyePoint = null;
Point leftMouthPoint = null;
Point rightMouthPoint = null;
for (Landmark landmark : landmarks) {
PointF point = landmark.getPosition();
switch (landmark.getType()) {
case Landmark.LEFT_EYE: {
leftEyePoint = transposePoint(point, sourceBitmap, targetSize, sideward);
}
break;
case Landmark.RIGHT_EYE: {
rightEyePoint = transposePoint(point, sourceBitmap, targetSize, sideward);
}
break;
case Landmark.LEFT_MOUTH: {
leftMouthPoint = transposePoint(point, sourceBitmap, targetSize, sideward);
}
break;
case Landmark.RIGHT_MOUTH: {
rightMouthPoint = transposePoint(point, sourceBitmap, targetSize, sideward);
}
break;
}
}
if (leftEyePoint != null && rightEyePoint != null) {
if (leftEyePoint.x < rightEyePoint.x) {
Point temp = leftEyePoint;
leftEyePoint = rightEyePoint;
rightEyePoint = temp;
}
eyesCenterPoint = new Point(0.5f * leftEyePoint.x + 0.5f * rightEyePoint.x,
0.5f * leftEyePoint.y + 0.5f * rightEyePoint.y);
eyesDistance = (float)Math.hypot(rightEyePoint.x - leftEyePoint.x, rightEyePoint.y - leftEyePoint.y);
angle = (float)Math.toDegrees(Math.PI + Math.atan2(rightEyePoint.y - leftEyePoint.y, rightEyePoint.x - leftEyePoint.x));
width = eyesDistance * 2.35f;
float foreheadHeight = 0.8f * eyesDistance;
float upAngle = (float)Math.toRadians(angle - 90);
foreheadPoint = new Point(eyesCenterPoint.x + foreheadHeight * (float)Math.cos(upAngle),
eyesCenterPoint.y + foreheadHeight * (float)Math.sin(upAngle));
}
if (leftMouthPoint != null && rightMouthPoint != null) {
if (leftMouthPoint.x < rightMouthPoint.x) {
Point temp = leftMouthPoint;
leftMouthPoint = rightMouthPoint;
rightMouthPoint = temp;
}
mouthPoint = new Point(0.5f * leftMouthPoint.x + 0.5f * rightMouthPoint.x,
0.5f * leftMouthPoint.y + 0.5f * rightMouthPoint.y);
float chinDepth = 0.7f * eyesDistance;
float downAngle = (float)Math.toRadians(angle + 90);
chinPoint = new Point(mouthPoint.x + chinDepth * (float)Math.cos(downAngle),
mouthPoint.y + chinDepth * (float)Math.sin(downAngle));
}
}
public boolean isSufficient() {
return eyesCenterPoint != null;
}
private Point transposePoint(PointF point, Bitmap sourceBitmap, Size targetSize, boolean sideward) {
float bitmapW = sideward ? sourceBitmap.getHeight() : sourceBitmap.getWidth();
float bitmapH = sideward ? sourceBitmap.getWidth() : sourceBitmap.getHeight();
return new Point(targetSize.width * point.x / bitmapW, targetSize.height * point.y / bitmapH);
}
public Point getPointForAnchor(int anchor) {
switch (anchor) {
case 0: {
return foreheadPoint;
}
case 1: {
return eyesCenterPoint;
}
case 2: {
return mouthPoint;
}
case 3: {
return chinPoint;
}
default: {
return null;
}
}
}
public float getWidthForAnchor(int anchor) {
if (anchor == 1) {
return eyesDistance;
}
return width;
}
public float getAngle() {
return angle;
}
}

View File

@ -24,10 +24,6 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.android.gms.vision.Frame;
import com.google.android.gms.vision.face.Face;
import com.google.android.gms.vision.face.FaceDetector;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.Bitmaps;
import org.telegram.messenger.BuildVars;
@ -44,7 +40,6 @@ import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarPopupWindow;
import org.telegram.ui.ActionBar.AlertDialog;
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.Components.Paint.PhotoFace;
import org.telegram.ui.Components.Paint.Views.EntitiesContainerView;
import org.telegram.ui.Components.Paint.Views.EntityView;
import org.telegram.ui.Components.Paint.Views.StickerView;
@ -111,7 +106,7 @@ public class PhotoPaintView extends FrameLayout implements EntityView.EntityView
private Animator colorPickerAnimator;
private DispatchQueue queue;
private ArrayList<PhotoFace> faces;
//private ArrayList<PhotoFace> faces;
private boolean ignoreLayout;
@ -420,7 +415,7 @@ public class PhotoPaintView extends FrameLayout implements EntityView.EntityView
entitiesView.setVisibility(VISIBLE);
renderView.setVisibility(View.VISIBLE);
if (facesBitmap != null) {
detectFaces();
//detectFaces();
}
}
@ -1304,6 +1299,7 @@ public class PhotoPaintView extends FrameLayout implements EntityView.EntityView
popupWindow.startAnimation();
}
/*
private int getFrameRotation() {
switch (originalBitmapRotation) {
case 90: {
@ -1371,6 +1367,7 @@ public class PhotoPaintView extends FrameLayout implements EntityView.EntityView
}
});
}
*/
private StickerPosition calculateStickerPosition(TLRPC.Document document) {
TLRPC.TL_maskCoords maskCoords = null;
@ -1384,15 +1381,16 @@ public class PhotoPaintView extends FrameLayout implements EntityView.EntityView
}
StickerPosition defaultPosition = new StickerPosition(centerPositionForEntity(), 0.75f, 0.0f);
/*
if (maskCoords == null || faces == null || faces.size() == 0) {
return defaultPosition;
} else {
int anchor = maskCoords.n;
PhotoFace face = getRandomFaceWithVacantAnchor(anchor, document.id, maskCoords);
if (face == null) {
if (face == null) {*/
return defaultPosition;
}
}/*
Point referencePoint = face.getPointForAnchor(anchor);
float referenceWidth = face.getWidthForAnchor(anchor);
@ -1463,7 +1461,7 @@ public class PhotoPaintView extends FrameLayout implements EntityView.EntityView
return false;
}
*/
private static class StickerPosition {
private Point position;
private float scale;