Commit 9ea93f93 authored by samesh97's avatar samesh97

cleaning files.

parent 6297cc0f
...@@ -74,8 +74,6 @@ public class AddEffects extends AppCompatActivity ...@@ -74,8 +74,6 @@ public class AddEffects extends AppCompatActivity
private ArrayList<View> viewsInDisplay = new ArrayList<>(); private ArrayList<View> viewsInDisplay = new ArrayList<>();
private View lastLookedView = null;
private ComputerVision computerVision; private ComputerVision computerVision;
...@@ -317,80 +315,6 @@ public class AddEffects extends AppCompatActivity ...@@ -317,80 +315,6 @@ public class AddEffects extends AppCompatActivity
}); });
} }
void findViewPoint(int x,int y)
{
ImageView cursor = findViewById(R.id.cursor);
int viewMaxX = 0;
int viewMaxY = 0;
for(View view : viewsInDisplay)
{
int[] location = new int[2];
view.getLocationOnScreen(location);
int viewX = location[0] + (view.getWidth() / 2);
int viewY = location[1] / 2;
if(viewX >= viewMaxX)
{
viewMaxX = viewX;
}
if(viewY >= viewMaxY)
{
viewMaxY = viewY;
}
}
if(x > viewMaxX)
{
x = viewMaxX;
}
if(y > viewMaxY)
{
y = viewMaxY;
}
for(View view : viewsInDisplay)
{
int[] location = new int[2];
view.getLocationOnScreen(location);
int viewX = location[0];
int viewY = location[1];
int viewMaxWidth = viewX + view.getWidth();
int viewMinWidth = viewX - view.getWidth();
int viewMaxHeight = viewY + view.getHeight();
int viewMinHeight = viewY - view.getHeight();
if ((x >= viewMinWidth && x <= viewMaxWidth))
{
view.setBackgroundColor(Color.RED);
cursor.animate().x((viewMinWidth + viewMaxWidth) / 2);
cursor.animate().y((viewMinHeight + viewMaxHeight) / 2);
}
else
{
view.setBackgroundColor(Color.BLACK);
}
}
cursor.animate().x(x);
cursor.animate().y(y);
}
@Override @Override
public void opened() { public void opened() {
...@@ -407,21 +331,43 @@ public class AddEffects extends AppCompatActivity ...@@ -407,21 +331,43 @@ public class AddEffects extends AppCompatActivity
} }
// @Override
// public void onPupilChanged(Mat binary,int x, int y,int range,int pupilX)
// {
// findViewPoint(x,y);
// }
@Override @Override
public void eyeLeft(Mat mat) { public void eyeLeft(Mat mat)
{
moveCursor(1);
} }
@Override @Override
public void eyeRight(Mat mat) { public void eyeRight(Mat mat) {
moveCursor(0);
}
public void moveCursor(int pos)
{
View selectedView = viewsInDisplay.get(pos);
for(View view : viewsInDisplay)
{
if(selectedView == view)
{
view.setBackgroundColor(Color.RED);
continue;
}
view.setBackgroundColor(Color.BLACK);
}
int[] location = new int[2];
selectedView.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
ImageView cursor = findViewById(R.id.cursor);
cursor.animate().x(x);
cursor.animate().y(y);
} }
@Override @Override
......
...@@ -40,12 +40,8 @@ public class AdjustBrightness extends AppCompatActivity ...@@ -40,12 +40,8 @@ public class AdjustBrightness extends AppCompatActivity
float brightnessValue = 0.0f; float brightnessValue = 0.0f;
private ComputerVision computerVision; private ComputerVision computerVision;
private int count = 0;
private View lastLookedView = null;
private ArrayList<View> viewsInDisplay = new ArrayList<>(); private ArrayList<View> viewsInDisplay = new ArrayList<>();
private TickSeekBar seekBar; private TickSeekBar seekBar;
private boolean isPossible = true;
private SpeechService speechService; private SpeechService speechService;
...@@ -162,93 +158,6 @@ public class AdjustBrightness extends AppCompatActivity ...@@ -162,93 +158,6 @@ public class AdjustBrightness extends AppCompatActivity
} }
Back(null); Back(null);
} }
void findViewPoint(int x,int y)
{
ImageView cursor = findViewById(R.id.cursor);
int viewMaxX = 0;
int viewMaxY = 0;
for(View view : viewsInDisplay)
{
int[] location = new int[2];
view.getLocationOnScreen(location);
int viewX = location[0] + (view.getWidth() / 2);
int viewY = location[1] / 2;
if(viewX >= viewMaxX)
{
viewMaxX = viewX;
}
if(viewY >= viewMaxY)
{
viewMaxY = viewY;
}
}
if(x > viewMaxX)
{
x = viewMaxX;
}
if(y > viewMaxY)
{
y = viewMaxY;
}
for(View view : viewsInDisplay)
{
int[] location = new int[2];
view.getLocationOnScreen(location);
int viewX = location[0];
int viewY = location[1];
int viewMaxWidth = viewX + view.getWidth();
int viewMinWidth = viewX - view.getWidth();
int viewMaxHeight = viewY + view.getHeight();
int viewMinHeight = viewY - view.getHeight();
if ((x >= viewMinWidth && x <= viewMaxWidth))
{
view.setBackgroundColor(Color.RED);
cursor.animate().x((viewMinWidth + viewMaxWidth) / 2);
cursor.animate().y((viewMinHeight + viewMaxHeight) / 2);
}
else
{
view.setBackgroundColor(Color.BLACK);
}
}
cursor.animate().x(x);
cursor.animate().y(y);
}
private void checkCount()
{
count++;
if(count >= 5)
{
isPossible = true;
count = 0;
}
else
{
isPossible = false;
}
}
@Override @Override
public void opened() { public void opened() {
...@@ -265,21 +174,43 @@ public class AdjustBrightness extends AppCompatActivity ...@@ -265,21 +174,43 @@ public class AdjustBrightness extends AppCompatActivity
} }
// @Override
// public void onPupilChanged(Mat binary, int x, int y, int range, int pupilX) {
//
// findViewPoint(x,y);
// }
@Override @Override
public void eyeLeft(Mat mat) { public void eyeLeft(Mat mat)
{
moveCursor(1);
} }
@Override @Override
public void eyeRight(Mat mat) { public void eyeRight(Mat mat) {
moveCursor(0);
}
public void moveCursor(int pos)
{
View selectedView = viewsInDisplay.get(pos);
for(View view : viewsInDisplay)
{
if(selectedView == view)
{
view.setBackgroundColor(Color.RED);
continue;
}
view.setBackgroundColor(Color.BLACK);
}
int[] location = new int[2];
selectedView.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
ImageView cursor = findViewById(R.id.cursor);
cursor.animate().x(x);
cursor.animate().y(y);
} }
@Override @Override
......
...@@ -3,7 +3,6 @@ package com.app.smartphotoeditor.activities; ...@@ -3,7 +3,6 @@ package com.app.smartphotoeditor.activities;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
...@@ -40,11 +39,8 @@ public class AdjustSaturation extends AppCompatActivity ...@@ -40,11 +39,8 @@ public class AdjustSaturation extends AppCompatActivity
float saturationLevel = 0.0f; float saturationLevel = 0.0f;
private ComputerVision computerVision; private ComputerVision computerVision;
private int count = 0;
private View lastLookedView = null;
private ArrayList<View> viewsInDisplay = new ArrayList<>(); private ArrayList<View> viewsInDisplay = new ArrayList<>();
private TickSeekBar seekBar; private TickSeekBar seekBar;
private boolean isPossible = true;
private SpeechService speechService; private SpeechService speechService;
...@@ -159,92 +155,6 @@ public class AdjustSaturation extends AppCompatActivity ...@@ -159,92 +155,6 @@ public class AdjustSaturation extends AppCompatActivity
} }
Back(null); Back(null);
} }
void findViewPoint(int x,int y)
{
ImageView cursor = findViewById(R.id.cursor);
int viewMaxX = 0;
int viewMaxY = 0;
for(View view : viewsInDisplay)
{
int[] location = new int[2];
view.getLocationOnScreen(location);
int viewX = location[0] + (view.getWidth() / 2);
int viewY = location[1] / 2;
if(viewX >= viewMaxX)
{
viewMaxX = viewX;
}
if(viewY >= viewMaxY)
{
viewMaxY = viewY;
}
}
if(x > viewMaxX)
{
x = viewMaxX;
}
if(y > viewMaxY)
{
y = viewMaxY;
}
for(View view : viewsInDisplay)
{
int[] location = new int[2];
view.getLocationOnScreen(location);
int viewX = location[0];
int viewY = location[1];
int viewMaxWidth = viewX + view.getWidth();
int viewMinWidth = viewX - view.getWidth();
int viewMaxHeight = viewY + view.getHeight();
int viewMinHeight = viewY - view.getHeight();
if ((x >= viewMinWidth && x <= viewMaxWidth))
{
view.setBackgroundColor(Color.RED);
cursor.animate().x((viewMinWidth + viewMaxWidth) / 2);
cursor.animate().y((viewMinHeight + viewMaxHeight) / 2);
}
else
{
view.setBackgroundColor(Color.BLACK);
}
}
cursor.animate().x(x);
cursor.animate().y(y);
}
private void checkCount()
{
count++;
if(count >= 5)
{
isPossible = true;
count = 0;
}
else
{
isPossible = false;
}
}
@Override @Override
public void opened() { public void opened() {
...@@ -261,19 +171,43 @@ public class AdjustSaturation extends AppCompatActivity ...@@ -261,19 +171,43 @@ public class AdjustSaturation extends AppCompatActivity
} }
// @Override @Override
// public void onPupilChanged(Mat binary, int x, int y, int range, int pupilX) { public void eyeLeft(Mat mat)
// {
// findViewPoint(x,y);
// }
@Override
public void eyeLeft(Mat mat) {
} moveCursor(1);
}
@Override @Override
public void eyeRight(Mat mat) { public void eyeRight(Mat mat) {
moveCursor(0);
}
public void moveCursor(int pos)
{
View selectedView = viewsInDisplay.get(pos);
for(View view : viewsInDisplay)
{
if(selectedView == view)
{
view.setBackgroundColor(Color.RED);
continue;
}
view.setBackgroundColor(Color.BLACK);
}
int[] location = new int[2];
selectedView.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
ImageView cursor = findViewById(R.id.cursor);
cursor.animate().x(x);
cursor.animate().y(y);
} }
@Override @Override
......
...@@ -350,22 +350,14 @@ public class CustomGallery extends AppCompatActivity implements ...@@ -350,22 +350,14 @@ public class CustomGallery extends AppCompatActivity implements
}); });
} }
// @Override
// public void onPupilChanged(Mat binary,int x, int y,int range,int pupilX)
// {
// setPreviewFrame(binary);
// }
@Override @Override
public void eyeLeft(Mat mat) { public void eyeLeft(Mat mat) {
//setPreviewFrame(mat);
} }
@Override @Override
public void eyeRight(Mat mat) { public void eyeRight(Mat mat) {
//setPreviewFrame(mat);
} }
@Override @Override
......
...@@ -56,10 +56,7 @@ public class DenoisingActivity extends AppCompatActivity ...@@ -56,10 +56,7 @@ public class DenoisingActivity extends AppCompatActivity
private ComputerVision computerVision; private ComputerVision computerVision;
private int count = 0;
private View lastLookedView = null;
private ArrayList<View> viewsInDisplay = new ArrayList<>(); private ArrayList<View> viewsInDisplay = new ArrayList<>();
private boolean isPossible = true;
private SpeechService speechService; private SpeechService speechService;
@Override @Override
...@@ -218,78 +215,6 @@ public class DenoisingActivity extends AppCompatActivity ...@@ -218,78 +215,6 @@ public class DenoisingActivity extends AppCompatActivity
} }
Back(null); Back(null);
} }
void findViewPoint(int x,int y)
{
ImageView cursor = findViewById(R.id.cursor);
int viewMaxX = 0;
int viewMaxY = 0;
for(View view : viewsInDisplay)
{
int[] location = new int[2];
view.getLocationOnScreen(location);
int viewX = location[0] + (view.getWidth() / 2);
int viewY = location[1] / 2;
if(viewX >= viewMaxX)
{
viewMaxX = viewX;
}
if(viewY >= viewMaxY)
{
viewMaxY = viewY;
}
}
if(x > viewMaxX)
{
x = viewMaxX;
}
if(y > viewMaxY)
{
y = viewMaxY;
}
for(View view : viewsInDisplay)
{
int[] location = new int[2];
view.getLocationOnScreen(location);
int viewX = location[0];
int viewY = location[1];
int viewMaxWidth = viewX + view.getWidth();
int viewMinWidth = viewX - view.getWidth();
int viewMaxHeight = viewY + view.getHeight();
int viewMinHeight = viewY - view.getHeight();
if ((x >= viewMinWidth && x <= viewMaxWidth))
{
view.setBackgroundColor(Color.RED);
cursor.animate().x((viewMinWidth + viewMaxWidth) / 2);
cursor.animate().y((viewMinHeight + viewMaxHeight) / 2);
}
else
{
view.setBackgroundColor(Color.BLACK);
}
}
cursor.animate().x(x);
cursor.animate().y(y);
}
@Override @Override
public void opened() { public void opened() {
...@@ -306,20 +231,43 @@ public class DenoisingActivity extends AppCompatActivity ...@@ -306,20 +231,43 @@ public class DenoisingActivity extends AppCompatActivity
} }
// @Override
// public void onPupilChanged(Mat binary, int x, int y, int range, int pupilX) {
//
// findViewPoint(x,y);
// }
@Override @Override
public void eyeLeft(Mat mat) { public void eyeLeft(Mat mat)
{
moveCursor(1);
} }
@Override @Override
public void eyeRight(Mat mat) { public void eyeRight(Mat mat) {
moveCursor(0);
}
public void moveCursor(int pos)
{
View selectedView = viewsInDisplay.get(pos);
for(View view : viewsInDisplay)
{
if(selectedView == view)
{
view.setBackgroundColor(Color.RED);
continue;
}
view.setBackgroundColor(Color.BLACK);
}
int[] location = new int[2];
selectedView.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
ImageView cursor = findViewById(R.id.cursor);
cursor.animate().x(x);
cursor.animate().y(y);
} }
@Override @Override
......
...@@ -530,25 +530,43 @@ public class EditorActivity extends AppCompatActivity ...@@ -530,25 +530,43 @@ public class EditorActivity extends AppCompatActivity
} }
// @Override
// public void onPupilChanged(Mat binary,int x, int y,int range, int pupilX) {
//
// findViewPoint(x,y);
// }
@Override @Override
public void eyeLeft(Mat mat) { public void eyeLeft(Mat mat)
{
viewsInDisplay.get(1).setBackgroundColor(Color.RED); moveCursor(1);
viewsInDisplay.get(0).setBackgroundColor(Color.BLACK);
} }
@Override @Override
public void eyeRight(Mat mat) { public void eyeRight(Mat mat) {
viewsInDisplay.get(0).setBackgroundColor(Color.RED); moveCursor(0);
viewsInDisplay.get(1).setBackgroundColor(Color.BLACK); }
public void moveCursor(int pos)
{
View selectedView = viewsInDisplay.get(pos);
for(View view : viewsInDisplay)
{
if(selectedView == view)
{
view.setBackgroundColor(Color.RED);
continue;
}
view.setBackgroundColor(Color.BLACK);
}
int[] location = new int[2];
selectedView.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
ImageView cursor = findViewById(R.id.cursor);
cursor.animate().x(x);
cursor.animate().y(y);
} }
@Override @Override
......
package com.app.smartphotoeditor.activities;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.app.smartphotoeditor.R;
import com.app.smartphotoeditor.models.EyeDetectionResultSet;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.android.Utils;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;
import org.opencv.imgproc.Moments;
import org.opencv.objdetect.CascadeClassifier;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
public class HeadPoseActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 {
static
{
OpenCVLoader.initDebug();
}
private static final String TAG="MainActivity";
private Mat mRgba;
private Mat mGray;
private CameraBridgeViewBase mOpenCvCameraView;
private CascadeClassifier cascadeClassifier;
private ImageView frame;
private TextView view_point,view;
private TextToSpeech tts = null;
private String lastSpeechText = "";
private boolean isFirstTime = true;
private int lastX,lastY = 0;
int count = 0;
private ProgressBar progress_bar;
private int leftGestureBound,rightGestureBound,topGestureBound,bottomGestureBound = 0;
private final BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status)
{
if (status == LoaderCallbackInterface.SUCCESS)
{
Log.i(TAG, "OpenCv Is loaded");
mOpenCvCameraView.setCameraIndex(1);
mOpenCvCameraView.enableView();
}
super.onManagerConnected(status);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_head_pose);
progress_bar = findViewById(R.id.progress_bar);
tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status)
{
if(status == TextToSpeech.SUCCESS)
{
tts.setLanguage(Locale.US);
}
}
});
int MY_PERMISSIONS_REQUEST_CAMERA = 0;
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
== PackageManager.PERMISSION_DENIED){
ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.CAMERA}, MY_PERMISSIONS_REQUEST_CAMERA);
}
mOpenCvCameraView = findViewById(R.id.frame_Surface);
mOpenCvCameraView.setAlpha(0);
mOpenCvCameraView.setCvCameraViewListener(this);
frame = findViewById(R.id.frame);
view_point = findViewById(R.id.view_point);
view = findViewById(R.id.view_p);
InputStream is2 =getResources().openRawResource(R.raw.haarcascade_frontalface_alt);
cascadeClassifier = loadCascadeModel(is2,"Frontal_Face.xml");
}
@Override
protected void onResume()
{
super.onResume();
if (OpenCVLoader.initDebug())
{
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
}
else
{
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_4_0,this,mLoaderCallback);
}
}
@Override
protected void onPause()
{
super.onPause();
if (mOpenCvCameraView !=null)
{
mOpenCvCameraView.disableView();
}
}
public void onDestroy()
{
super.onDestroy();
if(mOpenCvCameraView !=null)
{
mOpenCvCameraView.disableView();
}
}
public void onCameraViewStarted(int width ,int height)
{
mRgba = new Mat(height,width, CvType.CV_8UC1);
mGray = new Mat(height,width,CvType.CV_8UC1);
}
public void onCameraViewStopped()
{
mRgba.release();
}
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame)
{
//catch input frames in RGB and Gray
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
//rotate by 180
Core.flip(mRgba,mRgba,-1);
Core.flip(mGray,mGray,-1);
//find face and eyes and return the image frame
Mat mat = findFace(mRgba);
//Core.flip(mRgba, mRgba, 1);
Bitmap b = matToBitmap(mat);
setBitmapImage(frame,b);
return mRgba;
}
CascadeClassifier loadCascadeModel(InputStream is,String name)
{
try
{
File cascadeDir = getDir("cascade", Context.MODE_PRIVATE); // creating a folder
File mCascadeFile = new File(cascadeDir,name); // creating file on that folder
FileOutputStream os=new FileOutputStream(mCascadeFile);
byte[] buffer=new byte[4096];
int byteRead;
// writing that file from raw folder
while((byteRead =is.read(buffer)) != -1)
{
os.write(buffer,0,byteRead);
}
is.close();
os.close();
// loading file from cascade folder created above
return new CascadeClassifier(mCascadeFile.getAbsolutePath());
}
catch (IOException e)
{
Log.i(TAG,"Cascade file not found");
}
return null;
}
private Mat findFace(Mat mRgba)
{
// original frame is -90 degree so we have to rotate is to 90 to get proper face for detection
Mat m = mRgba.t();
Core.flip(m,mRgba,1);
m.release();
// convert it into RGB
Mat mRbg = new Mat();
Imgproc.cvtColor(mRgba,mRbg,Imgproc.COLOR_RGBA2RGB);
int height=mRbg.height();
// minimum size of face in frame
int absoluteFaceSize=(int) (height*0.1);
MatOfRect faces=new MatOfRect();
if(cascadeClassifier !=null)
{
// input output // minimum size of output
cascadeClassifier.detectMultiScale(mRbg,faces,1.1,2,2, new Size(absoluteFaceSize,absoluteFaceSize),new Size());
}
// loop through all faces
Rect[] facesArray=faces.toArray();
for (Rect value : facesArray)
{
int x = (int) (((value.br().x - value.tl().x) / 2) + value.tl().x);
int y = (int) ((int) ((value.br().y - value.tl().y) / 2) + value.tl().y);
drawMiddlePoint(x,y,mRgba);
Imgproc.line(mRgba,new Point(value.tl().x,y),new Point(value.br().x,y),new Scalar(255,0,0,255),3);
Imgproc.line(mRgba,new Point(x,value.tl().y),new Point(x,value.br().y),new Scalar(255,0,0,255),3);
Imgproc.circle(mRgba,new Point(x,y),5,new Scalar(0,255,0,255),15);
setTextViewValue(view_point,"Coordinates X - " + x + ", Y - " + y);
detectGesture(x,y);
// draw face on original frame mRgba
//Imgproc.rectangle(mRgba, value.tl(), value.br(), new Scalar(0, 255, 0, 255), 2);
// crop face image and then pass it through eye classifier
// starting point
Rect roi = new Rect((int) value.tl().x, (int) value.tl().y, (int) value.br().x - (int) value.tl().x, (int) value.br().y - (int) value.tl().y);
// cropped mat image
Mat cropped = new Mat(mRgba, roi);
break;
}
// rotate back original frame to -90 degree
Mat a = mRgba.t();
Core.flip(a,mRgba,0);
a.release();
return mRgba;
}
private synchronized void drawMiddlePoint(int x, int y, Mat mRgba)
{
if(!isFirstTime)
{
x = lastX;
y = lastY;
count++;
if(count >= 8)
{
isFirstTime = true;
}
}
else
{
count = 0;
lastX = x;
lastY = y;
isFirstTime = false;
}
// int width1 = mRgba.cols();
// int height1 = mRgba.rows();
int width1 = x;
int height1 = y;
//Imgproc.line(mRgba,new Point(0,height1),new Point(width1,height1),new Scalar(0,255,0,255),3);
//Imgproc.line(mRgba,new Point(width1,0),new Point(width1,height1),new Scalar(0,255,0,255),3);
double middleFrameX = width1;
double middleFrameY = height1;
int range = 50;
//right bound
rightGestureBound = (int) (middleFrameX + range);
Imgproc.line(mRgba,new Point(middleFrameX + range,middleFrameY - range),new Point(middleFrameX + range,middleFrameY + range),new Scalar(0,0,255,255),3);
//left bound
leftGestureBound = (int) (middleFrameX - range);
Imgproc.line(mRgba,new Point(middleFrameX - range,middleFrameY - range),new Point(middleFrameX - range,middleFrameY + range),new Scalar(0,0,255,255),3);
//top bound
topGestureBound = (int) middleFrameY - range;
Imgproc.line(mRgba,new Point(middleFrameX - range,middleFrameY - range),new Point(middleFrameX + range,middleFrameY - range),new Scalar(0,0,255,255),3);
//bottom bound
bottomGestureBound = (int) middleFrameY + range;
Imgproc.line(mRgba,new Point(middleFrameX - range,middleFrameY + range),new Point(middleFrameX + range,middleFrameY + range),new Scalar(0,0,255,255),3);
}
private void detectGesture(int x, int y)
{
int margin = 10;
if((x + margin > rightGestureBound) && (x - margin < rightGestureBound))
{
speak("Left");
setTextViewValue(view,"Left Gesture Detected");
}
else if((x + margin > leftGestureBound) && (x - margin < leftGestureBound))
{
speak("Right");
setTextViewValue(view,"Right Gesture Detected");
}
else if((y + margin > bottomGestureBound) && ( y - margin < bottomGestureBound))
{
speak("Bottom");
setTextViewValue(view,"Bottom Gesture Detected");
}
else if((y + margin > topGestureBound) && (y - margin < topGestureBound))
{
speak("Top");
setTextViewValue(view,"Top Gesture Detected");
}
setProgressBarValue(x);
}
public Bitmap matToBitmap(Mat mat)
{
Bitmap bitmap =
Bitmap.createBitmap(mat.cols(), mat.rows(), Bitmap.Config.RGB_565);
Utils.matToBitmap(mat, bitmap);
return bitmap;
}
public void setTextViewValue(TextView txt,String text)
{
runOnUiThread(new Runnable() {
@Override
public void run() {
txt.setText(text);
}
});
}
public void speak(String text)
{
if(lastSpeechText.equals(text))
{
return;
}
tts.speak("" + text, TextToSpeech.QUEUE_ADD,null,null);
lastSpeechText = text;
}
void setBitmapImage(ImageView img,Bitmap bmp)
{
runOnUiThread(new Runnable() {
@Override
public void run() {
img.setImageBitmap(bmp);
}
});
}
void setProgressBarValue(int progress)
{
int calculatedProgress = 0;
if(progress <= 200) calculatedProgress = 0;
else if(progress >= 300) calculatedProgress = 100;
else if(progress <= 225) calculatedProgress = 25;
else if(progress <= 250) calculatedProgress = 50;
else if(progress <= 275) calculatedProgress = 75;
else if(progress <= 300) calculatedProgress = 100;
int finalCalculatedProgress = calculatedProgress;
runOnUiThread(new Runnable() {
@Override
public void run() {
progress_bar.setProgress(finalCalculatedProgress);
}
});
}
public void goToEnv(View view)
{
Intent intent = new Intent(this,EnvironmentChecker.class);
startActivity(intent);
}
}
\ No newline at end of file
...@@ -79,10 +79,7 @@ public class LowLightEnhanceActivity extends AppCompatActivity ...@@ -79,10 +79,7 @@ public class LowLightEnhanceActivity extends AppCompatActivity
private EqualizeHistogram equalizeHistogram; private EqualizeHistogram equalizeHistogram;
private ComputerVision computerVision; private ComputerVision computerVision;
private int count = 0;
private View lastLookedView = null;
private ArrayList<View> viewsInDisplay = new ArrayList<>(); private ArrayList<View> viewsInDisplay = new ArrayList<>();
private boolean isPossible = true;
private SpeechService speechService; private SpeechService speechService;
...@@ -257,93 +254,6 @@ public class LowLightEnhanceActivity extends AppCompatActivity ...@@ -257,93 +254,6 @@ public class LowLightEnhanceActivity extends AppCompatActivity
revertButton.setText("TURN OFF"); revertButton.setText("TURN OFF");
} }
} }
void findViewPoint(int x,int y)
{
ImageView cursor = findViewById(R.id.cursor);
int viewMaxX = 0;
int viewMaxY = 0;
for(View view : viewsInDisplay)
{
int[] location = new int[2];
view.getLocationOnScreen(location);
int viewX = location[0] + (view.getWidth() / 2);
int viewY = location[1] / 2;
if(viewX >= viewMaxX)
{
viewMaxX = viewX;
}
if(viewY >= viewMaxY)
{
viewMaxY = viewY;
}
}
if(x > viewMaxX)
{
x = viewMaxX;
}
if(y > viewMaxY)
{
y = viewMaxY;
}
for(View view : viewsInDisplay)
{
int[] location = new int[2];
view.getLocationOnScreen(location);
int viewX = location[0];
int viewY = location[1];
int viewMaxWidth = viewX + view.getWidth();
int viewMinWidth = viewX - view.getWidth();
int viewMaxHeight = viewY + view.getHeight();
int viewMinHeight = viewY - view.getHeight();
if ((x >= viewMinWidth && x <= viewMaxWidth))
{
view.setBackgroundColor(Color.RED);
cursor.animate().x((viewMinWidth + viewMaxWidth) / 2);
cursor.animate().y((viewMinHeight + viewMaxHeight) / 2);
}
else
{
view.setBackgroundColor(Color.BLACK);
}
}
cursor.animate().x(x);
cursor.animate().y(y);
}
private void checkCount()
{
count++;
if(count >= 5)
{
isPossible = true;
count = 0;
}
else
{
isPossible = false;
}
}
@Override @Override
public void opened() { public void opened() {
...@@ -360,20 +270,44 @@ public class LowLightEnhanceActivity extends AppCompatActivity ...@@ -360,20 +270,44 @@ public class LowLightEnhanceActivity extends AppCompatActivity
} }
// @Override
// public void onPupilChanged(Mat binary, int x, int y, int range, int pupilX) {
//
// findViewPoint(x,y);
// }
@Override @Override
public void eyeLeft(Mat mat) { public void eyeLeft(Mat mat)
{
moveCursor(1);
} }
@Override @Override
public void eyeRight(Mat mat) { public void eyeRight(Mat mat) {
moveCursor(0);
}
public void moveCursor(int pos)
{
View selectedView = viewsInDisplay.get(pos);
for(View view : viewsInDisplay)
{
if(selectedView == view)
{
view.setBackgroundColor(Color.RED);
continue;
}
view.setBackgroundColor(Color.BLACK);
}
int[] location = new int[2];
selectedView.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
ImageView cursor = findViewById(R.id.cursor);
cursor.animate().x(x);
cursor.animate().y(y);
} }
@Override @Override
......
...@@ -50,10 +50,7 @@ public class RestorationActivity extends AppCompatActivity ...@@ -50,10 +50,7 @@ public class RestorationActivity extends AppCompatActivity
private Handler handler = null; private Handler handler = null;
private ComputerVision computerVision; private ComputerVision computerVision;
private int count = 0;
private View lastLookedView = null;
private ArrayList<View> viewsInDisplay = new ArrayList<>(); private ArrayList<View> viewsInDisplay = new ArrayList<>();
private boolean isPossible = true;
private SpeechService speechService; private SpeechService speechService;
...@@ -218,93 +215,6 @@ public class RestorationActivity extends AppCompatActivity ...@@ -218,93 +215,6 @@ public class RestorationActivity extends AppCompatActivity
} }
Back(null); Back(null);
} }
void findViewPoint(int x,int y)
{
ImageView cursor = findViewById(R.id.cursor);
int viewMaxX = 0;
int viewMaxY = 0;
for(View view : viewsInDisplay)
{
int[] location = new int[2];
view.getLocationOnScreen(location);
int viewX = location[0] + (view.getWidth() / 2);
int viewY = location[1] / 2;
if(viewX >= viewMaxX)
{
viewMaxX = viewX;
}
if(viewY >= viewMaxY)
{
viewMaxY = viewY;
}
}
if(x > viewMaxX)
{
x = viewMaxX;
}
if(y > viewMaxY)
{
y = viewMaxY;
}
for(View view : viewsInDisplay)
{
int[] location = new int[2];
view.getLocationOnScreen(location);
int viewX = location[0];
int viewY = location[1];
int viewMaxWidth = viewX + view.getWidth();
int viewMinWidth = viewX - view.getWidth();
int viewMaxHeight = viewY + view.getHeight();
int viewMinHeight = viewY - view.getHeight();
if ((x >= viewMinWidth && x <= viewMaxWidth))
{
view.setBackgroundColor(Color.RED);
cursor.animate().x((viewMinWidth + viewMaxWidth) / 2);
cursor.animate().y((viewMinHeight + viewMaxHeight) / 2);
}
else
{
view.setBackgroundColor(Color.BLACK);
}
}
cursor.animate().x(x);
cursor.animate().y(y);
}
private void checkCount()
{
count++;
if(count >= 5)
{
isPossible = true;
count = 0;
}
else
{
isPossible = false;
}
}
@Override @Override
public void opened() { public void opened() {
...@@ -321,20 +231,44 @@ public class RestorationActivity extends AppCompatActivity ...@@ -321,20 +231,44 @@ public class RestorationActivity extends AppCompatActivity
} }
// @Override
// public void onPupilChanged(Mat binary, int x, int y, int range, int pupilX) {
//
// findViewPoint(x,y);
// }
@Override @Override
public void eyeLeft(Mat mat) { public void eyeLeft(Mat mat)
{
moveCursor(1);
} }
@Override @Override
public void eyeRight(Mat mat) { public void eyeRight(Mat mat) {
moveCursor(0);
}
public void moveCursor(int pos)
{
View selectedView = viewsInDisplay.get(pos);
for(View view : viewsInDisplay)
{
if(selectedView == view)
{
view.setBackgroundColor(Color.RED);
continue;
}
view.setBackgroundColor(Color.BLACK);
}
int[] location = new int[2];
selectedView.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
ImageView cursor = findViewById(R.id.cursor);
cursor.animate().x(x);
cursor.animate().y(y);
} }
@Override @Override
......
package com.app.smartphotoeditor.activities;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.app.smartphotoeditor.R;
import com.app.smartphotoeditor.services.MyService;
import java.util.ArrayList;
import static android.Manifest.permission.RECORD_AUDIO;
public class SpeechTest extends AppCompatActivity {
private SpeechRecognizer speechRecognizer;
//private Intent intentRecognizer;
//private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_speech_test);
ActivityCompat.requestPermissions(this, new String[]{RECORD_AUDIO}, PackageManager.PERMISSION_GRANTED);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_BOOT_COMPLETED);
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Hello", Toast.LENGTH_SHORT).show();
}
}, filter);
startForegroundService(new Intent(SpeechTest.this, MyService.class));
}
else
{
startService(new Intent(SpeechTest.this,MyService.class));
}
// textView = findViewById(R.id.textView);
// intentRecognizer = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
// intentRecognizer.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
//
// speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
// speechRecognizer.setRecognitionListener(new RecognitionListener() {
// @Override
// public void onReadyForSpeech(Bundle bundle) {
//
// }
//
// @Override
// public void onBeginningOfSpeech() { }
//
// @Override
// public void onRmsChanged(float v) { }
//
// @Override
// public void onBufferReceived(byte[] bytes) {
//
// }
//
// @Override
// public void onEndOfSpeech() { }
//
// @Override
// public void onError(int i) { }
//
// @Override
// public void onResults(Bundle bundle) {
//
// ArrayList<String> matches = bundle.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
// String string = "";
// if(matches!=null)
// {
// string = matches.get(0);
// textView.setText(string);
// speechRecognizer.startListening(intentRecognizer);
// }
// }
//
// @Override
// public void onPartialResults(Bundle bundle) {
//
// }
//
// @Override
// public void onEvent(int i, Bundle bundle)
// {
//
// }
// });
// speechRecognizer.startListening(intentRecognizer);
}
// public void Enable(View view)
// {
// speechRecognizer.startListening(intentRecognizer);
// }
//
// public void Disable(View view)
// {
// speechRecognizer.stopListening();
// }
}
\ No newline at end of file
...@@ -151,4 +151,14 @@ ...@@ -151,4 +151,14 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/preview" /> app:layout_constraintTop_toBottomOf="@+id/preview" />
<ImageView
android:id="@+id/cursor"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/cursor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/preview" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
...@@ -151,4 +151,14 @@ ...@@ -151,4 +151,14 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/preview" /> app:layout_constraintTop_toBottomOf="@+id/preview" />
<ImageView
android:id="@+id/cursor"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/cursor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/preview" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
...@@ -128,4 +128,14 @@ ...@@ -128,4 +128,14 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/preview" /> app:layout_constraintTop_toBottomOf="@+id/preview" />
<ImageView
android:id="@+id/cursor"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/cursor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/preview" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
...@@ -145,4 +145,15 @@ ...@@ -145,4 +145,15 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/preview" /> app:layout_constraintTop_toBottomOf="@+id/preview" />
<ImageView
android:id="@+id/cursor"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/cursor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/preview" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
...@@ -129,4 +129,14 @@ ...@@ -129,4 +129,14 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/preview" /> app:layout_constraintTop_toBottomOf="@+id/preview" />
<ImageView
android:id="@+id/cursor"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/cursor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/preview" />
</androidx.constraintlayout.widget.ConstraintLayout> </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