Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Fixed crash on taking multiple pictures and general updates #15

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
../.idea/
Camera2/.gradle/
.idea/
app/build/
build/
2 changes: 1 addition & 1 deletion Camera2/Camera2.iml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
145 changes: 96 additions & 49 deletions Camera2/app/app.iml

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions Camera2/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.example.ezequiel.camera2"
minSdkVersion 16
targetSdkVersion 25
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -20,11 +20,12 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.google.android.gms:play-services-vision:10.2.0'
testCompile 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.google.android.gms:play-services-vision:17.0.2'
testImplementation 'junit:junit:4.12'
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
context = getApplicationContext();

takePictureButton = (Button) findViewById(R.id.btn_takepicture);
switchButton = (Button) findViewById(R.id.btn_switch);
videoButton = (Button) findViewById(R.id.btn_video);
mPreview = (CameraSourcePreview) findViewById(R.id.preview);
mGraphicOverlay = (GraphicOverlay) findViewById(R.id.faceOverlay);
cameraVersion = (TextView) findViewById(R.id.cameraVersion);
ivAutoFocus = (ImageView) findViewById(R.id.ivAutoFocus);
takePictureButton = findViewById(R.id.btn_takepicture);
switchButton = findViewById(R.id.btn_switch);
videoButton = findViewById(R.id.btn_video);
mPreview = findViewById(R.id.preview);
mGraphicOverlay = findViewById(R.id.faceOverlay);
cameraVersion = findViewById(R.id.cameraVersion);
ivAutoFocus = findViewById(R.id.ivAutoFocus);

if(checkGooglePlayAvailability()) {
requestPermissionThenOpenCamera();
Expand Down Expand Up @@ -151,7 +151,7 @@ public void onClick(View v) {
final CameraSource.PictureCallback cameraSourcePictureCallback = new CameraSource.PictureCallback() {
@Override
public void onPictureTaken(Bitmap picture) {
Log.d(TAG, "Taken picture is here!");
Log.d(TAG, "Picture is taken here!");
runOnUiThread(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -280,7 +280,7 @@ public void run() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onPictureTaken(Image image) {
Log.d(TAG, "Taken picture is here!");
Log.d(TAG, "Picture is taken here!");
runOnUiThread(new Runnable() {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import android.os.Handler;
import android.os.HandlerThread;
import android.os.SystemClock;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresPermission;
Expand All @@ -41,7 +40,6 @@
import android.util.SparseIntArray;
import android.view.MotionEvent;
import android.view.Surface;
import android.widget.Toast;

import com.example.ezequiel.camera2.utils.Utils;
import com.google.android.gms.common.images.Size;
Expand All @@ -50,8 +48,6 @@

import java.io.IOException;
import java.lang.Thread.State;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -1443,7 +1439,9 @@ private class PictureDoneCallback implements ImageReader.OnImageAvailableListene
@Override
public void onImageAvailable(ImageReader reader) {
if(mDelegate != null) {
mDelegate.onPictureTaken(reader.acquireNextImage());
Image img = reader.acquireNextImage();
mDelegate.onPictureTaken(img);
img.close();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import android.graphics.PorterDuff;

import com.example.ezequiel.camera2.R;
import com.example.ezequiel.camera2.others.GraphicOverlay;
import com.google.android.gms.vision.face.Face;
import com.google.android.gms.vision.face.Landmark;

Expand All @@ -30,27 +29,27 @@ public class FaceGraphic extends GraphicOverlay.Graphic {
private Resources resources;

private int faceId;
PointF facePosition;
float faceWidth;
float faceHeight;
PointF faceCenter;
float isSmilingProbability = -1;
float eyeRightOpenProbability = -1;
float eyeLeftOpenProbability = -1;
float eulerZ;
float eulerY;
PointF leftEyePos = null;
PointF rightEyePos = null;
PointF noseBasePos = null;
PointF leftMouthCorner = null;
PointF rightMouthCorner = null;
PointF mouthBase = null;
PointF leftEar = null;
PointF rightEar = null;
PointF leftEarTip = null;
PointF rightEarTip = null;
PointF leftCheek = null;
PointF rightCheek = null;
private PointF facePosition;
private float faceWidth;
private float faceHeight;
private PointF faceCenter;
private float isSmilingProbability = -1;
private float eyeRightOpenProbability = -1;
private float eyeLeftOpenProbability = -1;
private float eulerZ;
private float eulerY;
private PointF leftEyePos = null;
private PointF rightEyePos = null;
private PointF noseBasePos = null;
private PointF leftMouthCorner = null;
private PointF rightMouthCorner = null;
private PointF mouthBase = null;
private PointF leftEar = null;
private PointF rightEar = null;
private PointF leftEarTip = null;
private PointF rightEarTip = null;
private PointF leftCheek = null;
private PointF rightCheek = null;

private volatile Face mFace;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

import com.google.android.gms.common.images.Size;

import java.util.ArrayList;

public class Utils {

public static int dpToPx(int dp) {
Expand Down
10 changes: 9 additions & 1 deletion Camera2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.2.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -15,6 +19,10 @@ buildscript {
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions Camera2/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Mar 21 12:45:03 ART 2017
#Thu Dec 20 16:19:16 CST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
20 changes: 8 additions & 12 deletions Camera2/local.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Fri Feb 24 18:50:43 ART 2017
ndk.dir=C\:\\Users\\Ezequiel\\AppData\\Local\\Android\\Sdk\\ndk-bundle
sdk.dir=C\:\\Users\\Ezequiel\\AppData\\Local\\Android\\Sdk
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Thu Dec 20 15:56:11 CST 2018
sdk.dir=/Users/stephenakers/Library/Android/sdk