Navigation Menu

Skip to content

Commit

Permalink
[TF][KILL] Google Vision
Browse files Browse the repository at this point in the history
  • Loading branch information
thermatk committed Aug 2, 2020
1 parent 003de36 commit 310bba9
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 176 deletions.
1 change: 0 additions & 1 deletion TMessagesProj/build.gradle
Expand Up @@ -30,7 +30,6 @@ dependencies {
implementation 'com.google.firebase:firebase-config:19.2.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-auth:18.1.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'
Expand Down
2 changes: 0 additions & 2 deletions TMessagesProj/src/main/AndroidManifest.xml
Expand Up @@ -397,8 +397,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" />

</application>
Expand Down
Expand Up @@ -11,10 +11,6 @@
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;

Expand Down Expand Up @@ -42,7 +38,8 @@ public static Result recognize(Bitmap bitmap, boolean tryDriverLicenseFirst) {
}

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);
Expand Down Expand Up @@ -127,7 +124,7 @@ private static Result recognizeBarcode(Bitmap bitmap) {
}
}
}
}
}*/
return null;
}

Expand Down
Expand Up @@ -33,9 +33,6 @@
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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -173,7 +170,7 @@ public CameraScanActivity(int type) {
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();
}
}

Expand All @@ -184,9 +181,9 @@ public void onFragmentDestroy() {
if (getParentActivity() != null) {
getParentActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}
if (visionQrReader != null) {
/*if (visionQrReader != null) {
visionQrReader.release();
}
}*/
}

@Override
Expand Down Expand Up @@ -596,7 +593,7 @@ public void onPreviewFrame(final byte[] data, final Camera camera) {
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();
Expand All @@ -609,7 +606,7 @@ private String tryReadQr(byte[] data, Size size, int x, int y, int side, Bitmap
} else {
text = null;
}
} else {
} else {*/
LuminanceSource source;
if (bitmap != null) {
int[] intArray = new int[bitmap.getWidth() * bitmap.getHeight()];
Expand All @@ -625,7 +622,7 @@ private String tryReadQr(byte[] data, Size size, int x, int y, int side, Bitmap
return null;
}
text = result.getText();
}
//}
if (TextUtils.isEmpty(text)) {
onNoQrFound();
return null;
Expand Down

This file was deleted.

Expand Up @@ -24,10 +24,6 @@
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;
Expand All @@ -46,7 +42,6 @@
import org.telegram.ui.ActionBar.AlertDialog;
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.BubbleActivity;
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;
Expand Down Expand Up @@ -118,7 +113,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;

Expand Down Expand Up @@ -437,7 +432,7 @@ public void init() {
entitiesView.setVisibility(VISIBLE);
renderView.setVisibility(View.VISIBLE);
if (facesBitmap != null) {
detectFaces();
//detectFaces();
}
}

Expand Down Expand Up @@ -1459,6 +1454,7 @@ private void showPopup(Runnable setupRunnable, View parent, int gravity, int x,
popupWindow.startAnimation();
}

/*
private int getFrameRotation() {
switch (originalBitmapRotation) {
case 90: {
Expand Down Expand Up @@ -1526,6 +1522,7 @@ private void detectFaces() {
}
});
}
*/

private StickerPosition calculateStickerPosition(TLRPC.Document document) {
TLRPC.TL_maskCoords maskCoords = null;
Expand All @@ -1548,15 +1545,16 @@ private StickerPosition calculateStickerPosition(TLRPC.Document document) {
baseScale = 0.75f;
}
StickerPosition defaultPosition = new StickerPosition(centerPositionForEntity(), baseScale, rotation);
/*
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);
Expand Down Expand Up @@ -1627,7 +1625,7 @@ private boolean isFaceAnchorOccupied(PhotoFace face, int anchor, long documentId
return false;
}

*/
private static class StickerPosition {
private Point position;
private float scale;
Expand Down
10 changes: 4 additions & 6 deletions TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java
Expand Up @@ -120,9 +120,6 @@
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.analytics.AnalyticsListener;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
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;
Expand Down Expand Up @@ -7023,6 +7020,7 @@ private void detectFaces(String key, ImageReceiver.BitmapHolder bitmap, int orie
return;
}
Utilities.globalQueue.postRunnable(() -> {
/*
FaceDetector faceDetector = null;
try {
faceDetector = new FaceDetector.Builder(ApplicationLoader.applicationContext)
Expand All @@ -7043,23 +7041,23 @@ private void detectFaces(String key, ImageReceiver.BitmapHolder bitmap, int orie
} else {
if (BuildVars.LOGS_ENABLED) {
FileLog.e("face detection is not operational");
}
}*/
AndroidUtilities.runOnUIThread(() -> {
bitmap.release();
String imageKey = centerImage.getImageKey();
if (key.equals(imageKey)) {
currentImageHasFace = 2;
currentImageFaceKey = key;
}
});
});/*
}
} catch (Exception e) {
FileLog.e(e);
} finally {
if (faceDetector != null) {
faceDetector.release();
}
}
}*/
});
}

Expand Down

0 comments on commit 310bba9

Please sign in to comment.