Commit ca4e39bd authored by samesh97's avatar samesh97

changes

parent bb605480
......@@ -238,7 +238,7 @@ public class EditorActivity extends AppCompatActivity
public void eyeLeft(Mat mat) {
viewsInDisplay.get(1).setBackgroundColor(Color.RED);
viewsInDisplay.get(0).setBackgroundColor(Color.TRANSPARENT);
viewsInDisplay.get(0).setBackgroundColor(Color.BLACK);
}
......@@ -246,7 +246,7 @@ public class EditorActivity extends AppCompatActivity
public void eyeRight(Mat mat) {
viewsInDisplay.get(0).setBackgroundColor(Color.RED);
viewsInDisplay.get(1).setBackgroundColor(Color.TRANSPARENT);
viewsInDisplay.get(1).setBackgroundColor(Color.BLACK);
}
@Override
......
......@@ -93,16 +93,6 @@ public class ComputerVision
public void onSkeletonDrawn(Mat mat)
{
Bitmap bitmap = Methods.matToBit(mat);
// try
// {
// Methods.saveImage(activity.getApplicationContext(),bitmap,"Idle");
// }
// catch (IOException e)
// {
// e.printStackTrace();
// }
gestureDetection.detectGestures(bitmap);
}
......@@ -111,15 +101,6 @@ public class ComputerVision
{
Bitmap bitmap = Methods.matToBit(mat);
// try
// {
// Methods.saveImage(activity.getApplicationContext(),bitmap,"EyeOpen");
// }
// catch (IOException e)
// {
// e.printStackTrace();
// }
if(eyeBlinkDetection != null)
eyeBlinkDetection.detectEyeBlinkState(bitmap);
......@@ -130,7 +111,6 @@ public class ComputerVision
@Override
public void onPupilChanged(Mat binary,boolean isLeft,boolean isRight)
{
// eyeStateListener.eyeLeft(binary);
if(isLeft)eyeStateListener.eyeLeft(binary);
if(isRight)eyeStateListener.eyeRight(binary);
}
......
......@@ -36,7 +36,6 @@ import java.nio.ByteOrder;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static com.app.smartphotoeditor.config.Constants.EYE_END_POSITION_X;
......@@ -86,7 +85,7 @@ public class FacialLandmarkDetection
options.setNumThreads(4);
//load CNN model
interpreter = new Interpreter(loadModelFile(assetManager,modelPath),options);
interpreter = new Interpreter(Methods.loadModelFile(assetManager,modelPath),options);
//load haar cascade classifier
loadCascadeClassifier();
......@@ -193,7 +192,7 @@ public class FacialLandmarkDetection
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, inputImageSize, inputImageSize, false);
//create buffer from bitmap
ByteBuffer byteBuffer = convertBitmapToByteBuffer(scaledBitmap);
ByteBuffer byteBuffer = Methods.convertBitmapToByteBuffer(scaledBitmap,inputImageSize);
//landmark resulting array
......@@ -416,24 +415,16 @@ public class FacialLandmarkDetection
} catch (Exception e) { }
}
public Mat setDefaultValues(Mat srcMat) {
// final Bitmap bitmap = Bitmap.createBitmap(srcMat.clone().width(), srcMat.clone().height(), Bitmap.Config.ARGB_8888);
public Mat setDefaultValues(Mat srcMat)
{
Imgproc.cvtColor(srcMat, srcMat, Imgproc.COLOR_BGR2GRAY, 0);
Mat srcMat1 = srcMat;
Imgproc.GaussianBlur(srcMat1, srcMat1, new Size(1, 1), 0);
//Mat srcMat1 = new Mat(srcMat.rows(), srcMat.cols(), CV_8UC1);
//int kernalsize = 3;
//Imgproc.bilateralFilter(srcMat, srcMat1, kernalsize, kernalsize * 2, kernalsize / 2);
srcMat1.convertTo(srcMat1, 0, 1.9, 1);
srcMat1.convertTo(srcMat1, CvType.CV_8U, 1.9, -255);
//Imgproc.cvtColor(srcMat1, srcMat1, Imgproc.COLOR_GRAY2RGBA, 4);
int whiteCount = 0;
int leftWhiteCount = 0;
......@@ -454,7 +445,7 @@ public class FacialLandmarkDetection
{
whiteCount++;
if(i < 5)
if(i < 15)
{
rightWhiteCount++;
}
......@@ -484,7 +475,6 @@ public class FacialLandmarkDetection
Log.d("cccccccccccccccc","left looked");
listener.onPupilChanged(srcMat1,true,false);
}
// Log.d("cccccccccccccccc","" + leftWhiteCount + "-" + rightWhiteCount);
}
......@@ -604,59 +594,12 @@ public class FacialLandmarkDetection
//listener.onPupilChanged(binary,calcX,calcY,range,pupilX);
Log.d("fsffsefsess","Y - " + pupilY + " Range - " + (eyeEndY - eyeStartY));
}
private ByteBuffer convertBitmapToByteBuffer(Bitmap scaledBitmap)
{
ByteBuffer byteBuffer;
int inputSize = inputImageSize;// 96
int quant = 1;
if(quant == 0)
{
byteBuffer = ByteBuffer.allocateDirect(3 * 1 * inputSize * inputSize);
}
else
{
byteBuffer = ByteBuffer.allocateDirect(4 * 1 * inputSize * inputSize * 3);
}
byteBuffer.order(ByteOrder.nativeOrder());
int pixel=0;
int [] intValues=new int [inputSize*inputSize];
scaledBitmap.getPixels(intValues,0,scaledBitmap.getWidth(),0,0,scaledBitmap.getWidth(),scaledBitmap.getHeight());
for (int i=0;i<inputSize;++i){
for(int j=0;j<inputSize;++j){
final int val= intValues[pixel++];
byteBuffer.putFloat((((val >> 16) & 0xFF))/255.0f);
byteBuffer.putFloat((((val >> 8) & 0xFF))/255.0f);
byteBuffer.putFloat(((val & 0xFF))/255.0f);
}
}
return byteBuffer;
}
// now call this function in CameraActivity
private MappedByteBuffer loadModelFile(AssetManager assetManager, String modelPath) throws IOException
{
// description of file
AssetFileDescriptor assetFileDescriptor=assetManager.openFd(modelPath);
FileInputStream inputStream=new FileInputStream(assetFileDescriptor.getFileDescriptor());
FileChannel fileChannel=inputStream.getChannel();
long startOffset=assetFileDescriptor.getStartOffset();
long declaredLength=assetFileDescriptor.getDeclaredLength();
return fileChannel.map(FileChannel.MapMode.READ_ONLY,startOffset,declaredLength);
}
private void loadCascadeClassifier()
{
try
......
package com.app.smartphotoeditor.vision;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.util.Log;
import com.app.smartphotoeditor.listeners.ml.OnGestureDetected;
import com.app.smartphotoeditor.sdk.Methods;
import org.tensorflow.lite.Interpreter;
import org.tensorflow.lite.gpu.GpuDelegate;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Array;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
public class GestureDetection
{
private Interpreter interpreter;
private GpuDelegate gpuDelegate;
private final int INPUT_SIZE;
private OnGestureDetected listener;
private final Interpreter interpreter;
private final int inputSize;
private final OnGestureDetected listener;
public GestureDetection(AssetManager assetManager, Context context, String modelPath, int inputSize,OnGestureDetected listener) throws IOException
{
INPUT_SIZE = inputSize;
this.inputSize = inputSize;
this.listener = listener;
// Interpreter.Options options = new Interpreter.Options();
// gpuDelegate = new GpuDelegate();
// options.addDelegate(gpuDelegate);
// options.setNumThreads(4);
interpreter = new Interpreter(loadModelFile(assetManager,modelPath));
Log.d("sssssssssssssss","Model Loaded");
}
private MappedByteBuffer loadModelFile(AssetManager assetManager, String modelPath) throws IOException
{
// description of file
AssetFileDescriptor assetFileDescriptor=assetManager.openFd(modelPath);
FileInputStream inputStream=new FileInputStream(assetFileDescriptor.getFileDescriptor());
FileChannel fileChannel=inputStream.getChannel();
long startOffset=assetFileDescriptor.getStartOffset();
long declaredLength=assetFileDescriptor.getDeclaredLength();
return fileChannel.map(FileChannel.MapMode.READ_ONLY,startOffset,declaredLength);
}
private ByteBuffer convertBitmapToByteBuffer(Bitmap scaledBitmap)
{
ByteBuffer byteBuffer;
int inputSize=INPUT_SIZE;// 96
int quant = 1;
if(quant == 0)
{
byteBuffer = ByteBuffer.allocateDirect(3 * 1 * inputSize * inputSize);
}
else
{
byteBuffer = ByteBuffer.allocateDirect(4 * 1 * inputSize * inputSize * 3);
}
byteBuffer.order(ByteOrder.nativeOrder());
int pixel=0;
int [] intValues=new int [inputSize*inputSize];
scaledBitmap.getPixels(intValues,0,scaledBitmap.getWidth(),0,0,scaledBitmap.getWidth(),scaledBitmap.getHeight());
for (int i=0;i<inputSize;++i){
for(int j=0;j<inputSize;++j){
final int val= intValues[pixel++];
byteBuffer.putFloat((((val >> 16) & 0xFF))/255.0f);
byteBuffer.putFloat((((val >> 8) & 0xFF))/255.0f);
byteBuffer.putFloat(((val & 0xFF))/255.0f);
}
}
return byteBuffer;
interpreter = new Interpreter(Methods.loadModelFile(assetManager,modelPath),null);
}
public String detectGestures(Bitmap bitmap)
{
String output = "Idle";
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap,INPUT_SIZE,INPUT_SIZE,false);
ByteBuffer byteBuffer = convertBitmapToByteBuffer(scaledBitmap);
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap,inputSize,inputSize,false);
ByteBuffer byteBuffer = Methods.convertBitmapToByteBuffer(scaledBitmap,inputSize);
float[][] result = new float[1][5];
......@@ -104,8 +45,6 @@ public class GestureDetection
float top = (float) Array.get(Array.get(result,0),i + 3);
float bottom = (float) Array.get(Array.get(result,0),i + 4);
Log.d("Leftccc", "" + idle);
float max = 0;
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
tools:context=".activities.CameraView">
<org.opencv.android.JavaCameraView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frame_Surface"/>
<ImageView
android:id="@+id/frame"
android:layout_width="100dp"
android:layout_height="130dp"
android:layout_marginStart="32dp"
android:layout_marginTop="32dp"
android:scaleType="centerCrop"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/left"
android:layout_width="100dp"
android:layout_height="0dp"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="@+id/frame"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toEndOf="@+id/frame"
app:layout_constraintTop_toTopOf="@+id/frame" />
<ImageView
android:id="@+id/center"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginEnd="32dp"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/right" />
<ImageView
android:id="@+id/right"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginEnd="32dp"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="@+id/center"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="@+id/view_point"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="View Point"
android:textColor="@android:color/black"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="@+id/center"
app:layout_constraintTop_toBottomOf="@+id/frame" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment