This repository has been archived by the owner on Sep 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from coderbunker/issue#27-eye_tracking
Issue#27 eye tracking
- Loading branch information
Showing
7 changed files
with
254 additions
and
8 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
app/src/main/java/com/coderbunker/kioskapp/facerecognition/CameraPreview.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.coderbunker.kioskapp.facerecognition; | ||
|
||
import android.content.Context; | ||
import android.hardware.Camera; | ||
import android.util.Log; | ||
import android.view.SurfaceHolder; | ||
import android.view.SurfaceView; | ||
|
||
import java.io.IOException; | ||
|
||
import static android.content.ContentValues.TAG; | ||
|
||
/** | ||
* A basic Camera preview class | ||
*/ | ||
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { | ||
private SurfaceHolder mHolder; | ||
private Camera mCamera; | ||
|
||
public CameraPreview(Context context, Camera camera) { | ||
super(context); | ||
mCamera = camera; | ||
|
||
// Install a SurfaceHolder.Callback so we get notified when the | ||
// underlying surface is created and destroyed. | ||
mHolder = getHolder(); | ||
mHolder.addCallback(this); | ||
// deprecated setting, but required on Android versions prior to 3.0 | ||
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); | ||
} | ||
|
||
public void surfaceCreated(SurfaceHolder holder) { | ||
try { | ||
mCamera.setPreviewDisplay(holder); | ||
mCamera.startPreview(); | ||
|
||
startFaceDetection(); // start face detection feature | ||
|
||
} catch (IOException e) { | ||
Log.d(TAG, "Error setting camera preview: " + e.getMessage()); | ||
} | ||
} | ||
|
||
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { | ||
|
||
if (holder.getSurface() == null) { | ||
// preview surface does not exist | ||
Log.d(TAG, "holder.getSurface() == null"); | ||
return; | ||
} | ||
|
||
try { | ||
mCamera.stopPreview(); | ||
|
||
} catch (Exception e) { | ||
// ignore: tried to stop a non-existent preview | ||
Log.d(TAG, "Error stopping camera preview: " + e.getMessage()); | ||
} | ||
|
||
try { | ||
mCamera.setPreviewDisplay(holder); | ||
mCamera.startPreview(); | ||
|
||
startFaceDetection(); // re-start face detection feature | ||
|
||
} catch (Exception e) { | ||
// ignore: tried to stop a non-existent preview | ||
Log.d(TAG, "Error starting camera preview: " + e.getMessage()); | ||
} | ||
} | ||
|
||
public void surfaceDestroyed(SurfaceHolder holder) { | ||
// empty. Take care of releasing the Camera preview in your activity. | ||
} | ||
|
||
public void startFaceDetection() { | ||
// Try starting Face Detection | ||
Camera.Parameters params = mCamera.getParameters(); | ||
|
||
// start face detection only *after* preview has started | ||
if (params.getMaxNumDetectedFaces() > 0) { | ||
// camera supports face detection, so can start it: | ||
mCamera.startFaceDetection(); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/coderbunker/kioskapp/facerecognition/FaceDetectionListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.coderbunker.kioskapp.facerecognition; | ||
|
||
import android.hardware.Camera; | ||
|
||
import java.util.Observable; | ||
|
||
public class FaceDetectionListener extends Observable implements Camera.FaceDetectionListener { | ||
|
||
@Override | ||
public void onFaceDetection(Camera.Face[] faces, Camera camera) { | ||
if (faces.length > 0) { | ||
for (Camera.Face face : faces) { | ||
try { | ||
/*System.out.println("--------------------------"); | ||
System.out.println(face.score);*/ | ||
setChanged(); | ||
notifyObservers(face); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,53 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<WebView android:id="@+id/webview" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<WebView | ||
android:id="@+id/webview" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent"> | ||
|
||
</WebView> | ||
|
||
|
||
<FrameLayout | ||
android:id="@+id/camera_preview" | ||
android:layout_width="1dp" | ||
android:layout_height="1dp" | ||
android:visibility="visible"> | ||
|
||
</FrameLayout> | ||
|
||
<TextView | ||
android:id="@+id/face_detection_score" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentBottom="true" | ||
android:layout_alignParentEnd="true" | ||
android:layout_marginBottom="21dp" | ||
android:layout_marginEnd="30dp" | ||
android:text="TextView" | ||
android:visibility="gone" | ||
tools:layout_editor_absoluteX="758dp" | ||
tools:layout_editor_absoluteY="1123dp" /> | ||
|
||
<TextView | ||
android:id="@+id/face_counter" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentBottom="true" | ||
android:layout_centerHorizontal="true" | ||
android:background="#000" | ||
android:text="0" | ||
android:textColor="#FFF" | ||
android:textSize="18sp" | ||
android:visibility="visible" | ||
tools:layout_editor_absoluteX="758dp" | ||
tools:layout_editor_absoluteY="1123dp" /> | ||
|
||
</RelativeLayout> | ||
|
||
|