Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021-129
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2021-129
2021-129
Commits
56acdc7f
Commit
56acdc7f
authored
Oct 18, 2021
by
samesh97
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finalizing integration.
parent
674c4033
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
401 additions
and
852 deletions
+401
-852
app/src/main/AndroidManifest.xml
app/src/main/AndroidManifest.xml
+1
-1
app/src/main/java/com/app/smartphotoeditor/activities/AddEffects.java
.../java/com/app/smartphotoeditor/activities/AddEffects.java
+108
-166
app/src/main/java/com/app/smartphotoeditor/activities/EditorActivity.java
...a/com/app/smartphotoeditor/activities/EditorActivity.java
+82
-0
app/src/main/java/com/app/smartphotoeditor/activities/EnvironmentChecker.java
...m/app/smartphotoeditor/activities/EnvironmentChecker.java
+137
-614
app/src/main/java/com/app/smartphotoeditor/activities/SplashScreen.java
...ava/com/app/smartphotoeditor/activities/SplashScreen.java
+1
-1
app/src/main/java/com/app/smartphotoeditor/vision/EyeBlinkDetection.java
...va/com/app/smartphotoeditor/vision/EyeBlinkDetection.java
+2
-2
app/src/main/res/drawable/arrow.png
app/src/main/res/drawable/arrow.png
+0
-0
app/src/main/res/drawable/icon.png
app/src/main/res/drawable/icon.png
+0
-0
app/src/main/res/layout/activity_editor.xml
app/src/main/res/layout/activity_editor.xml
+10
-0
app/src/main/res/layout/activity_environment_checker.xml
app/src/main/res/layout/activity_environment_checker.xml
+50
-60
app/src/main/res/layout/activity_splash_screen.xml
app/src/main/res/layout/activity_splash_screen.xml
+10
-8
No files found.
app/src/main/AndroidManifest.xml
View file @
56acdc7f
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
<application
<application
android:allowBackup=
"true"
android:allowBackup=
"true"
android:icon=
"@
mipmap/ic_launcher
"
android:icon=
"@
drawable/icon
"
android:label=
"@string/app_name"
android:label=
"@string/app_name"
android:requestLegacyExternalStorage=
"true"
android:requestLegacyExternalStorage=
"true"
android:roundIcon=
"@mipmap/ic_launcher_round"
android:roundIcon=
"@mipmap/ic_launcher_round"
...
...
app/src/main/java/com/app/smartphotoeditor/activities/AddEffects.java
View file @
56acdc7f
...
@@ -21,11 +21,13 @@ import com.app.smartphotoeditor.adapters.FilterAdapter;
...
@@ -21,11 +21,13 @@ import com.app.smartphotoeditor.adapters.FilterAdapter;
import
com.app.smartphotoeditor.config.ImageList
;
import
com.app.smartphotoeditor.config.ImageList
;
import
com.app.smartphotoeditor.listeners.OnBitmapChanged
;
import
com.app.smartphotoeditor.listeners.OnBitmapChanged
;
import
com.app.smartphotoeditor.listeners.OnCameraPreviewChanged
;
import
com.app.smartphotoeditor.listeners.OnCameraPreviewChanged
;
import
com.app.smartphotoeditor.listeners.OnVoiceCommandResultChanged
;
import
com.app.smartphotoeditor.listeners.ml.OnEyeStatusChanged
;
import
com.app.smartphotoeditor.listeners.ml.OnEyeStatusChanged
;
import
com.app.smartphotoeditor.listeners.ml.OnGestureDetected
;
import
com.app.smartphotoeditor.listeners.ml.OnGestureDetected
;
import
com.app.smartphotoeditor.sdk.Methods
;
import
com.app.smartphotoeditor.sdk.Methods
;
import
com.app.smartphotoeditor.sdk.RealTimeCamera
;
import
com.app.smartphotoeditor.sdk.RealTimeCamera
;
import
com.app.smartphotoeditor.services.ComputerVision
;
import
com.app.smartphotoeditor.services.ComputerVision
;
import
com.app.smartphotoeditor.services.SpeechService
;
import
com.bumptech.glide.Glide
;
import
com.bumptech.glide.Glide
;
import
com.warkiz.tickseekbar.OnSeekChangeListener
;
import
com.warkiz.tickseekbar.OnSeekChangeListener
;
import
com.warkiz.tickseekbar.SeekParams
;
import
com.warkiz.tickseekbar.SeekParams
;
...
@@ -47,7 +49,7 @@ import java.util.List;
...
@@ -47,7 +49,7 @@ import java.util.List;
public
class
AddEffects
extends
AppCompatActivity
public
class
AddEffects
extends
AppCompatActivity
implements
OnBitmapChanged
,
implements
OnBitmapChanged
,
OnGestureDetected
,
OnEyeStatusChanged
{
OnGestureDetected
,
OnEyeStatusChanged
,
OnVoiceCommandResultChanged
{
static
static
{
{
...
@@ -66,7 +68,6 @@ public class AddEffects extends AppCompatActivity
...
@@ -66,7 +68,6 @@ public class AddEffects extends AppCompatActivity
private
TickSeekBar
listener
,
listener2
,
listener3
;
private
TickSeekBar
listener
,
listener2
,
listener3
;
private
Bitmap
subFilterBitmap
=
null
;
private
Bitmap
subFilterBitmap
=
null
;
private
boolean
isAnEffectAdded
=
false
;
private
boolean
isAllowedToChangeFilters
=
true
;
private
boolean
isAllowedToChangeFilters
=
true
;
...
@@ -77,38 +78,35 @@ public class AddEffects extends AppCompatActivity
...
@@ -77,38 +78,35 @@ public class AddEffects extends AppCompatActivity
private
ComputerVision
computerVision
;
private
ComputerVision
computerVision
;
int
count
=
0
;
int
count2
=
0
;
boolean
isPossible
=
true
;
private
SpeechService
speechService
;
@Override
@Override
protected
void
on
Destroy
()
protected
void
on
Resume
()
{
{
super
.
onResume
();
s
uper
.
onDestroy
();
s
peechService
.
onResume
();
}
}
@Override
@Override
public
void
onBackPressed
()
protected
void
onPause
()
{
{
super
.
onPause
();
speechService
.
onPause
();
}
if
(
subFiltersLayout
.
getVisibility
()
==
View
.
VISIBLE
)
{
subFiltersLayout
.
setVisibility
(
View
.
GONE
);
}
else
{
super
.
onBackPressed
();
}
@Override
protected
void
onStop
()
{
super
.
onStop
();
speechService
.
onStop
();
}
@Override
protected
void
onDestroy
()
{
super
.
onDestroy
();
}
}
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
...
@@ -137,6 +135,8 @@ public class AddEffects extends AppCompatActivity
...
@@ -137,6 +135,8 @@ public class AddEffects extends AppCompatActivity
init
();
init
();
setData
();
setData
();
speechService
=
new
SpeechService
(
getApplicationContext
(),
findViewById
(
R
.
id
.
progress
),
this
);
}
}
private
void
setPreviewFrame
(
Mat
previewMat
)
private
void
setPreviewFrame
(
Mat
previewMat
)
{
{
...
@@ -281,7 +281,6 @@ public class AddEffects extends AppCompatActivity
...
@@ -281,7 +281,6 @@ public class AddEffects extends AppCompatActivity
Glide
.
with
(
getApplicationContext
()).
load
(
subFilterBitmap
).
into
(
userSelectedImage
);
Glide
.
with
(
getApplicationContext
()).
load
(
subFilterBitmap
).
into
(
userSelectedImage
);
isAnEffectAdded
=
true
;
}
}
...
@@ -293,7 +292,6 @@ public class AddEffects extends AppCompatActivity
...
@@ -293,7 +292,6 @@ public class AddEffects extends AppCompatActivity
listener2
.
setProgress
(
0
);
listener2
.
setProgress
(
0
);
listener3
.
setProgress
(
0
);
listener3
.
setProgress
(
0
);
subFilterBitmap
=
null
;
subFilterBitmap
=
null
;
isAnEffectAdded
=
true
;
currentEditingBitmap
=
bitmap
;
currentEditingBitmap
=
bitmap
;
...
@@ -322,7 +320,13 @@ public class AddEffects extends AppCompatActivity
...
@@ -322,7 +320,13 @@ public class AddEffects extends AppCompatActivity
void
findViewPoint
(
int
x
,
int
y
)
void
findViewPoint
(
int
x
,
int
y
)
{
{
ImageView
cursor
=
findViewById
(
R
.
id
.
cursor
);
int
viewMaxX
=
0
;
int
viewMaxY
=
0
;
int
viewMaxY
=
0
;
for
(
View
view
:
viewsInDisplay
)
for
(
View
view
:
viewsInDisplay
)
{
{
int
[]
location
=
new
int
[
2
];
int
[]
location
=
new
int
[
2
];
...
@@ -331,6 +335,10 @@ public class AddEffects extends AppCompatActivity
...
@@ -331,6 +335,10 @@ public class AddEffects extends AppCompatActivity
int
viewX
=
location
[
0
]
+
(
view
.
getWidth
()
/
2
);
int
viewX
=
location
[
0
]
+
(
view
.
getWidth
()
/
2
);
int
viewY
=
location
[
1
]
/
2
;
int
viewY
=
location
[
1
]
/
2
;
if
(
viewX
>=
viewMaxX
)
{
viewMaxX
=
viewX
;
}
if
(
viewY
>=
viewMaxY
)
if
(
viewY
>=
viewMaxY
)
{
{
viewMaxY
=
viewY
;
viewMaxY
=
viewY
;
...
@@ -338,130 +346,50 @@ public class AddEffects extends AppCompatActivity
...
@@ -338,130 +346,50 @@ public class AddEffects extends AppCompatActivity
}
}
if
(
x
>
viewMaxX
)
ImageView
b
=
findViewById
(
R
.
id
.
cursor
);
if
(
x
==
620
||
x
==
720
||
x
==
360
)
{
{
viewsInDisplay
.
get
(
1
).
setBackgroundColor
(
Color
.
RED
);
x
=
viewMaxX
;
viewsInDisplay
.
get
(
0
).
setBackgroundColor
(
Color
.
BLACK
);
}
}
else
if
(
y
>
viewMaxY
)
{
{
viewsInDisplay
.
get
(
0
).
setBackgroundColor
(
Color
.
RED
);
y
=
viewMaxY
;
viewsInDisplay
.
get
(
1
).
setBackgroundColor
(
Color
.
BLACK
);
}
}
b
.
animate
().
x
(
x
);
b
.
animate
().
y
(
viewMaxY
);
for
(
View
view
:
viewsInDisplay
)
{
int
[]
location
=
new
int
[
2
];
Log
.
d
(
"XXXXXX"
,
"x-"
+
x
);
view
.
getLocationOnScreen
(
location
);
// ImageView b = findViewById(R.id.cursor);
//
int
viewX
=
location
[
0
];
//
int
viewY
=
location
[
1
];
// int viewMaxX = 0;
// int viewMaxY = 0;
//
int
viewMaxWidth
=
viewX
+
view
.
getWidth
();
//
int
viewMinWidth
=
viewX
-
view
.
getWidth
();
//
// for(View view : viewsInDisplay)
int
viewMaxHeight
=
viewY
+
view
.
getHeight
();
// {
int
viewMinHeight
=
viewY
-
view
.
getHeight
();
// int[] location = new int[2];
// view.getLocationOnScreen(location);
//
if
((
x
>=
viewMinWidth
&&
x
<=
viewMaxWidth
))
// int viewX = location[0] + (view.getWidth() / 2);
{
// int viewY = location[1] / 2;
//
view
.
setBackgroundColor
(
Color
.
RED
);
// if(viewX >= viewMaxX)
// {
cursor
.
animate
().
x
((
viewMinWidth
+
viewMaxWidth
)
/
2
);
// viewMaxX = viewX;
cursor
.
animate
().
y
((
viewMinHeight
+
viewMaxHeight
)
/
2
);
// }
// if(viewY >= viewMaxY)
}
// {
else
// viewMaxY = viewY;
{
// }
view
.
setBackgroundColor
(
Color
.
BLACK
);
//
}
// }
//
}
// if(x > viewMaxX)
cursor
.
animate
().
x
(
x
);
// {
cursor
.
animate
().
y
(
y
);
// 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))
// {
//
// if(lastLookedView != null && lastLookedView.getId() == view.getId())
// {
// count++;
// if(count >= 3)
// {
// //lock for some seconds
// isPossible = false;
// }
// if(count >= 10)
// {
// count = 0;
// isPossible = true;
// lastLookedView = null;
// }
// }
// else
// {
// count = 0;
// }
//
// if(isPossible)
// {
// view.setBackgroundColor(Color.RED);
// b.animate().x((viewMinWidth + viewMaxWidth) / 2);
// b.animate().y((viewMinHeight + viewMaxHeight) / 2);
// lastLookedView = view;
// }
// else
// {
// lastLookedView.setBackgroundColor(Color.RED);
// }
//
//
// }
// else
// {
// view.setBackgroundColor(Color.BLACK);
// }
//
// }
// b.animate().x(x);
// b.animate().y(y);
}
}
@Override
@Override
...
@@ -482,26 +410,6 @@ public class AddEffects extends AppCompatActivity
...
@@ -482,26 +410,6 @@ public class AddEffects extends AppCompatActivity
@Override
@Override
public
void
onPupilChanged
(
Mat
binary
,
int
x
,
int
y
,
int
range
,
int
pupilX
)
public
void
onPupilChanged
(
Mat
binary
,
int
x
,
int
y
,
int
range
,
int
pupilX
)
{
{
// try
// {
// Methods.saveImage(getApplicationContext(),Methods.matToBit(binary),"Right");
// }
// catch (IOException e)
// {
// e.printStackTrace();
// }
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
//setPreviewFrame(binary);
ProgressBar
bar
=
findViewById
(
R
.
id
.
progress
);
bar
.
setMax
(
range
);
bar
.
setProgress
(
pupilX
);
}
});
findViewPoint
(
x
,
y
);
findViewPoint
(
x
,
y
);
}
}
...
@@ -559,9 +467,11 @@ public class AddEffects extends AppCompatActivity
...
@@ -559,9 +467,11 @@ public class AddEffects extends AppCompatActivity
public
void
Save
(
View
view
)
public
void
Save
(
View
view
)
{
{
ImageList
.
getInstance
().
addBitmap
(
currentEditingBitmap
,
true
);
if
(
currentEditingBitmap
!=
null
)
{
ImageList
.
getInstance
().
addBitmap
(
currentEditingBitmap
,
true
);
}
Back
(
null
);
Back
(
null
);
}
}
public
void
Back
(
View
view
)
public
void
Back
(
View
view
)
...
@@ -569,4 +479,36 @@ public class AddEffects extends AppCompatActivity
...
@@ -569,4 +479,36 @@ public class AddEffects extends AppCompatActivity
setResult
(
100
);
setResult
(
100
);
finish
();
finish
();
}
}
@Override
public
void
back
()
{
Back
(
null
);
}
@Override
public
void
exit
()
{
}
@Override
public
void
undo
()
{
}
@Override
public
void
redo
()
{
}
@Override
public
void
save
()
{
Save
(
null
);
}
@Override
public
void
select
()
{
}
}
}
app/src/main/java/com/app/smartphotoeditor/activities/EditorActivity.java
View file @
56acdc7f
...
@@ -2,6 +2,7 @@ package com.app.smartphotoeditor.activities;
...
@@ -2,6 +2,7 @@ package com.app.smartphotoeditor.activities;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.graphics.Bitmap
;
import
android.graphics.Color
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.view.View
;
import
android.view.View
;
import
android.widget.ImageView
;
import
android.widget.ImageView
;
...
@@ -30,6 +31,7 @@ import com.bumptech.glide.Glide;
...
@@ -30,6 +31,7 @@ import com.bumptech.glide.Glide;
import
org.opencv.core.Mat
;
import
org.opencv.core.Mat
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
public
class
EditorActivity
extends
AppCompatActivity
public
class
EditorActivity
extends
AppCompatActivity
...
@@ -45,6 +47,8 @@ public class EditorActivity extends AppCompatActivity
...
@@ -45,6 +47,8 @@ public class EditorActivity extends AppCompatActivity
private
SpeechService
speechService
;
private
SpeechService
speechService
;
private
ArrayList
<
View
>
viewsInDisplay
=
new
ArrayList
<>();
@Override
@Override
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
@Nullable
Intent
data
)
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
@Nullable
Intent
data
)
...
@@ -138,6 +142,9 @@ public class EditorActivity extends AppCompatActivity
...
@@ -138,6 +142,9 @@ public class EditorActivity extends AppCompatActivity
speechService
=
new
SpeechService
(
getApplicationContext
(),
findViewById
(
R
.
id
.
speech_progress
),
this
);
speechService
=
new
SpeechService
(
getApplicationContext
(),
findViewById
(
R
.
id
.
speech_progress
),
this
);
viewsInDisplay
.
add
(
findViewById
(
R
.
id
.
back
));
viewsInDisplay
.
add
(
findViewById
(
R
.
id
.
save
));
}
}
private
void
setPreviewFrame
(
Mat
previewMat
)
private
void
setPreviewFrame
(
Mat
previewMat
)
{
{
...
@@ -218,6 +225,7 @@ public class EditorActivity extends AppCompatActivity
...
@@ -218,6 +225,7 @@ public class EditorActivity extends AppCompatActivity
@Override
@Override
public
void
onPupilChanged
(
Mat
binary
,
int
x
,
int
y
,
int
range
,
int
pupilX
)
{
public
void
onPupilChanged
(
Mat
binary
,
int
x
,
int
y
,
int
range
,
int
pupilX
)
{
findViewPoint
(
x
,
y
);
}
}
@Override
@Override
...
@@ -354,4 +362,78 @@ public class EditorActivity extends AppCompatActivity
...
@@ -354,4 +362,78 @@ public class EditorActivity 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
);
}
}
}
\ No newline at end of file
app/src/main/java/com/app/smartphotoeditor/activities/EnvironmentChecker.java
View file @
56acdc7f
...
@@ -2,21 +2,31 @@ package com.app.smartphotoeditor.activities;
...
@@ -2,21 +2,31 @@ package com.app.smartphotoeditor.activities;
import
android.Manifest
;
import
android.Manifest
;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.pm.PackageManager
;
import
android.content.pm.PackageManager
;
import
android.graphics.Bitmap
;
import
android.graphics.Bitmap
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.speech.tts.TextToSpeech
;
import
android.speech.tts.TextToSpeech
;
import
android.util.Log
;
import
android.util.Log
;
import
android.view.View
;
import
android.widget.ImageView
;
import
android.widget.ImageView
;
import
android.widget.ProgressBar
;
import
android.widget.ProgressBar
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.constraintlayout.widget.ConstraintLayout
;
import
androidx.core.app.ActivityCompat
;
import
androidx.core.app.ActivityCompat
;
import
androidx.core.content.ContextCompat
;
import
androidx.core.content.ContextCompat
;
import
com.app.smartphotoeditor.R
;
import
com.app.smartphotoeditor.R
;
import
com.app.smartphotoeditor.listeners.OnCameraPreviewChanged
;
import
com.app.smartphotoeditor.listeners.ml.OnEyeStatusChanged
;
import
com.app.smartphotoeditor.listeners.ml.OnGestureDetected
;
import
com.app.smartphotoeditor.models.EyeDetectionResultSet
;
import
com.app.smartphotoeditor.models.EyeDetectionResultSet
;
import
com.app.smartphotoeditor.sdk.Methods
;
import
com.app.smartphotoeditor.sdk.RealTimeCamera
;
import
com.app.smartphotoeditor.services.ComputerVision
;
import
org.opencv.android.BaseLoaderCallback
;
import
org.opencv.android.BaseLoaderCallback
;
import
org.opencv.android.CameraBridgeViewBase
;
import
org.opencv.android.CameraBridgeViewBase
;
...
@@ -45,51 +55,16 @@ import java.util.Arrays;
...
@@ -45,51 +55,16 @@ import java.util.Arrays;
import
java.util.List
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Locale
;
public
class
EnvironmentChecker
extends
AppCompatActivity
implements
CameraBridgeViewBase
.
CvCameraViewListener2
{
public
class
EnvironmentChecker
extends
AppCompatActivity
implements
OnEyeStatusChanged
,
OnGestureDetected
{
static
{
OpenCVLoader
.
initDebug
();
}
private
static
final
String
TAG
=
"MainActivity"
;
private
Mat
mRgba
;
private
Mat
mGray
;
private
CameraBridgeViewBase
mOpenCvCameraView
;
private
CascadeClassifier
cascadeClassifier
;
private
CascadeClassifier
cascadeClassifier_eye
;
private
ImageView
frame
;
private
TextView
view_point
;
private
TextToSpeech
tts
=
null
;
private
TextToSpeech
tts
=
null
;
private
String
lastSpeechText
=
""
;
private
ComputerVision
computerVision
;
ImageView
left
,
top
,
right
,
bottom
;
boolean
isLeftDone
,
isRightDone
,
isTopDone
,
isBottomDone
=
false
;
private
List
<
EyeDetectionResultSet
>
detectionResults
;
private
float
brightnessLevel
=
0.0f
;
private
static
final
float
MAX_BRIGHTNESS_LEVEL
=
3
f
;
private
boolean
isAccessingEnvironment
=
true
;
private
ProgressBar
progressBar
;
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
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
protected
void
onCreate
(
Bundle
savedInstanceState
)
...
@@ -97,6 +72,13 @@ public class EnvironmentChecker extends AppCompatActivity implements CameraBridg
...
@@ -97,6 +72,13 @@ public class EnvironmentChecker extends AppCompatActivity implements CameraBridg
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_environment_checker
);
setContentView
(
R
.
layout
.
activity_environment_checker
);
left
=
findViewById
(
R
.
id
.
left
);
top
=
findViewById
(
R
.
id
.
top
);
right
=
findViewById
(
R
.
id
.
right
);
bottom
=
findViewById
(
R
.
id
.
bottom
);
computerVision
=
new
ComputerVision
(
this
,
this
,
this
);
tts
=
new
TextToSpeech
(
this
,
new
TextToSpeech
.
OnInitListener
()
{
tts
=
new
TextToSpeech
(
this
,
new
TextToSpeech
.
OnInitListener
()
{
@Override
@Override
...
@@ -111,641 +93,182 @@ public class EnvironmentChecker extends AppCompatActivity implements CameraBridg
...
@@ -111,641 +93,182 @@ public class EnvironmentChecker extends AppCompatActivity implements CameraBridg
});
});
int
MY_PERMISSIONS_REQUEST_CAMERA
=
0
;
ImageView
frame_Surface
=
findViewById
(
R
.
id
.
frame_Surface
);
ConstraintLayout
main_container
=
findViewById
(
R
.
id
.
main_container
);
if
(
ContextCompat
.
checkSelfPermission
(
this
,
Manifest
.
permission
.
CAMERA
)
new
RealTimeCamera
(
getApplicationContext
(),
main_container
,
new
OnCameraPreviewChanged
()
{
==
PackageManager
.
PERMISSION_DENIED
){
@Override
ActivityCompat
.
requestPermissions
(
this
,
new
String
[]
{
Manifest
.
permission
.
CAMERA
},
MY_PERMISSIONS_REQUEST_CAMERA
);
public
void
updated
(
Mat
rgba
,
Mat
preview
)
}
{
computerVision
.
setMat
(
rgba
);
setPreviewFrame
(
preview
);
mOpenCvCameraView
=
findViewById
(
R
.
id
.
frame_Surface
);
}
//mOpenCvCameraView.setAlpha(0);
}).
initialize
();
mOpenCvCameraView
.
setCvCameraViewListener
(
this
);
frame
=
findViewById
(
R
.
id
.
frame
);
nextGesture
(
left
,
4000
,-
50
,
0
,
"Left"
);
view_point
=
findViewById
(
R
.
id
.
view_point
);
progressBar
=
findViewById
(
R
.
id
.
progress_bar
);
loadCascadeModel
();
}
}
public
void
nextGesture
(
View
view
,
int
seconds
,
int
x
,
int
y
,
String
text
)
@Override
protected
void
onResume
()
{
{
super
.
onResume
();
new
Handler
().
postDelayed
(
new
Runnable
()
{
if
(
OpenCVLoader
.
initDebug
())
@Override
{
public
void
run
()
mLoaderCallback
.
onManagerConnected
(
LoaderCallbackInterface
.
SUCCESS
);
{
}
speak
(
"Please do Gesture "
+
text
);
else
runOnUiThread
(
new
Runnable
()
{
{
@Override
OpenCVLoader
.
initAsync
(
OpenCVLoader
.
OPENCV_VERSION_3_4_0
,
this
,
mLoaderCallback
);
public
void
run
()
}
{
view
.
setVisibility
(
View
.
VISIBLE
);
view
.
animate
().
translationX
(
x
).
translationY
(
y
).
setDuration
(
1000
).
setStartDelay
(
100
).
start
();
}
});
}
},
seconds
);
}
}
private
void
setPreviewFrame
(
Mat
previewMat
)
@Override
protected
void
onPause
()
{
{
super
.
onPause
();
ImageView
preview
=
findViewById
(
R
.
id
.
preview
);
if
(
mOpenCvCameraView
!=
null
)
{
mOpenCvCameraView
.
disableView
();
}
}
public
void
onDestroy
()
Bitmap
previewBitmap
=
Methods
.
matToBit
(
previewMat
);
{
previewBitmap
=
Methods
.
rotateBitmap
(
previewBitmap
,-
90
f
);
super
.
onDestroy
();
if
(
mOpenCvCameraView
!=
null
)
{
mOpenCvCameraView
.
disableView
();
}
Bitmap
finalPreviewBitmap
=
previewBitmap
;
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
if
(
preview
!=
null
)
preview
.
setImageBitmap
(
finalPreviewBitmap
);
}
});
}
}
public
void
onCameraViewStarted
(
int
width
,
int
height
)
@Override
{
public
void
opened
()
{
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
@Override
Core
.
flip
(
mRgba
,
mRgba
,-
1
);
public
void
closed
()
{
Core
.
flip
(
mGray
,
mGray
,-
1
);
//find face and eyes and return the image frame
return
findFace
(
mRgba
);
}
}
void
loadCascadeModel
()
{
try
{
InputStream
is
=
getResources
().
openRawResource
(
R
.
raw
.
haarcascade_frontalface_alt
);
File
cascadeDir
=
getDir
(
"cascade"
,
Context
.
MODE_PRIVATE
);
// creating a folder
File
mCascadeFile
=
new
File
(
cascadeDir
,
"haarcascade_frontalface_alt.xml"
);
// 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
cascadeClassifier
=
new
CascadeClassifier
(
mCascadeFile
.
getAbsolutePath
());
// model is loaded
// load eye haarcascade classifier
InputStream
is2
=
getResources
().
openRawResource
(
R
.
raw
.
haarcascade_righteye_2splits
);
// created before
File
mCascadeFile_eye
=
new
File
(
cascadeDir
,
"haarcascade_eye.xml"
);
// creating file on that folder
FileOutputStream
os2
=
new
FileOutputStream
(
mCascadeFile_eye
);
byte
[]
buffer1
=
new
byte
[
4096
];
int
byteRead1
;
// writing that file from raw folder
while
((
byteRead1
=
is2
.
read
(
buffer1
))
!=
-
1
){
os2
.
write
(
buffer1
,
0
,
byteRead1
);
}
is2
.
close
();
os2
.
close
();
// loading file from cascade folder created above
cascadeClassifier_eye
=
new
CascadeClassifier
(
mCascadeFile_eye
.
getAbsolutePath
());
}
catch
(
IOException
e
)
{
Log
.
i
(
TAG
,
"Cascade file not found"
);
}
}
private
Mat
findFace
(
Mat
mRgba
)
{
// original frame is -90 degree so we have to rotate is to 90 to get proper face for detection
Core
.
flip
(
mRgba
.
t
(),
mRgba
,
1
);
// convert it into RGB
Mat
mRbg
=
new
Mat
();
Imgproc
.
cvtColor
(
mRgba
,
mRbg
,
Imgproc
.
COLOR_RGBA2RGB
);
int
height
=
mRbg
.
height
();
@Override
// minimum size of face in frame
public
void
longClosed
()
{
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
)
@Override
{
public
void
onPupilChanged
(
Mat
binary
,
int
x
,
int
y
,
int
range
,
int
pupilX
)
{
// draw face on original frame mRgba
// Imgproc.rectangle(mRgba, value.tl(), value.br(), new Scalar(0, 255, 0, 255), 2);
}
@Override
public
void
onIdle
()
{
// 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
@Override
Mat
cropped
=
new
Mat
(
mRgba
,
roi
);
public
void
onLeft
()
{
// create a array to store eyes coordinate but we have to pass MatOfRect to classifier
MatOfRect
eyes
=
new
MatOfRect
();
if
(
cascadeClassifier_eye
!=
null
)
{
// find biggest size object
cascadeClassifier_eye
.
detectMultiScale
(
cropped
,
eyes
,
1.15
,
2
,
2
,
new
Size
(
35
,
35
),
new
Size
());
// now create an array
runOnUiThread
(
new
Runnable
()
{
Rect
[]
eyesArray
=
eyes
.
toArray
();
@Override
// loop through each eye
public
void
run
()
{
for
(
Rect
rect
:
eyesArray
)
if
(!
isLeftDone
)
{
{
// find coordinate on original frame mRgba
nextGesture
(
top
,
2000
,
0
,-
50
,
"Top"
);
// starting point
left
.
setVisibility
(
View
.
INVISIBLE
);
int
x1
=
(
int
)
(
rect
.
tl
().
x
+
value
.
tl
().
x
);
int
y1
=
(
int
)
(
rect
.
tl
().
y
+
value
.
tl
().
y
);
// width and height
int
w1
=
(
int
)
(
rect
.
br
().
x
-
rect
.
tl
().
x
);
int
h1
=
(
int
)
(
rect
.
br
().
y
-
rect
.
tl
().
y
);
// end point
int
x2
=
(
int
)
(
w1
+
x1
);
int
y2
=
(
int
)
(
h1
+
y1
);
// draw eye on original frame mRgba
//input starting point ending point color thickness
// Imgproc.rectangle(mRgba,new Point(x1,y1),new Point(x2,y2),new Scalar(0,255,0,255),2);
float
centerX
=
(
float
)
((
x1
+
x2
)
/
2.0
);
float
centerY
=
(
float
)
((
y1
+
y2
)
/
2.0
);
//Imgproc.circle(mRgba, new Point(centerX, centerY + 10), 2, new Scalar(0, 0, 0, 255), 2);
Rect
eye_roi
=
new
Rect
(
x1
,
y1
+
10
,
w1
,
h1
);
Mat
eye_cropped
=
new
Mat
(
mRgba
,
eye_roi
);
markIrisLocation
(
eye_cropped
);
break
;
}
}
isLeftDone
=
true
;
}
}
});
break
;
}
// rotate back original frame to -90 degree
Core
.
flip
(
mRgba
.
t
(),
mRgba
,
0
);
return
mRgba
;
}
}
void
markIrisLocation
(
Mat
eye_cropped
)
{
Mat
gray
=
new
Mat
();
//make gray frame
Imgproc
.
cvtColor
(
eye_cropped
,
gray
,
Imgproc
.
COLOR_BGR2GRAY
);
gray
.
convertTo
(
gray
,-
1
,
brightnessLevel
,
0
);
// gray.convertTo(gray,-1,2,0);
//add blur
Imgproc
.
blur
(
gray
,
gray
,
new
Size
(
11
,
11
));
//Imgproc.GaussianBlur(gray,gray,new Size(11,11),11);
//gray.convertTo(gray,-1,1.1,0);
//Imgproc.Canny(gray,gray,0,120);
//create binary
Mat
binary
=
new
Mat
();
Imgproc
.
threshold
(
gray
,
binary
,
150
,
255
,
Imgproc
.
THRESH_BINARY
);
//find contours
List
<
MatOfPoint
>
contours
=
new
ArrayList
<>();
Mat
hierarchy
=
new
Mat
();
Imgproc
.
findContours
(
binary
,
contours
,
hierarchy
,
Imgproc
.
RETR_TREE
,
Imgproc
.
CHAIN_APPROX_SIMPLE
);
//Collections.sort(contours, Collections.reverseOrder());
if
(
contours
.
size
()
>=
1
)
{
contours
.
remove
(
0
);
}
// now iterate over all top level contours
double
largestContuorArea
=
0
;
int
position
=
0
;
for
(
int
contourIdx
=
0
;
contourIdx
<
contours
.
size
();
contourIdx
++
)
{
Log
.
d
(
"Contour"
,
""
+
contours
.
size
());
double
contourArea
=
Imgproc
.
contourArea
(
contours
.
get
(
contourIdx
));
if
(
largestContuorArea
<
contourArea
)
{
largestContuorArea
=
contourArea
;
position
=
contourIdx
;
}
}
Log
.
d
(
"ContourArea"
,
""
+
largestContuorArea
);
if
(
contours
.
size
()
>
position
)
{
//draw contour
Imgproc
.
drawContours
(
eye_cropped
,
contours
,
position
,
new
Scalar
(
0
,
255
,
0
),
1
);
//draw circle on middle point
Moments
p
=
Imgproc
.
moments
(
contours
.
get
(
position
));
int
x
=
(
int
)
(
p
.
get_m10
()
/
p
.
get_m00
());
int
y
=
(
int
)
(
p
.
get_m01
()
/
p
.
get_m00
());
Imgproc
.
circle
(
eye_cropped
,
new
Point
(
x
,
y
),
4
,
new
Scalar
(
255
,
49
,
0
,
255
));
//draw horizontal and vertical lines to create a cross
Imgproc
.
line
(
eye_cropped
,
new
Point
(
x
-
20
,
y
),
new
Point
(
x
+
20
,
y
),
new
Scalar
(
0
,
255
,
0
));
Imgproc
.
line
(
eye_cropped
,
new
Point
(
x
,
y
-
20
),
new
Point
(
x
,
y
+
20
),
new
Scalar
(
0
,
255
,
0
));
//draw circle in the gray frame
Imgproc
.
circle
(
binary
,
new
Point
(
x
,
y
),
5
,
new
Scalar
(
0
,
0
,
0
,
255
),
10
);
}
Bitmap
grayFrame
=
matToBitmap
(
gray
);
Bitmap
binaryFrame
=
matToBitmap
(
binary
);
Bitmap
croppedOriginalFrame
=
matToBitmap
(
eye_cropped
);
findTheViewPoint
(
binary
);
if
(
isAccessingEnvironment
)
{
accessEnvironment
(
binary
,
contours
.
size
(),
largestContuorArea
);
}
@Override
public
void
onRight
()
{
if
(!
isTopDone
)
return
;
runOnUiThread
(
new
Runnable
()
{
runOnUiThread
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
public
void
run
()
{
{
if
(!
isRightDone
)
frame
.
setImageBitmap
(
croppedOriginalFrame
);
{
nextGesture
(
bottom
,
2000
,
0
,
50
,
"Bottom"
);
right
.
setVisibility
(
View
.
INVISIBLE
);
}
isRightDone
=
true
;
}
}
});
});
}
void
findTheViewPoint
(
Mat
binary
)
{
if
(
binary
==
null
)
return
;
//binary image width and height
int
width
=
binary
.
cols
();
int
height
=
binary
.
rows
();
//calculate the equal proportion of width
int
equalWidth
=
width
/
3
;
//calculate the width pixels percentages
}
int
leftRightWidth
=
(
int
)
(
equalWidth
*
1.2
);
int
centerWidth
=
(
int
)
(
equalWidth
*
0.6
);
//calculate the equal proportion of height
int
equalHeight
=
height
/
3
;
//calculate the height pixels percentages
int
topBottomHeight
=
(
int
)
(
equalHeight
*
1.3
);
int
centerHeight
=
(
int
)
(
equalHeight
*
0.4
);
//--variable naming convention--
//the acquired image (binary image) is divided into 9 subset of images
//topLeft -> TOP in Vertical direction but LEFT in horizontal direction
//centerCenter -> CENTER in Vertical direction and CENTER in horizontal direction
//crop left 3 images
Mat
topLeft
=
binary
.
submat
(
0
,
topBottomHeight
,
0
,
leftRightWidth
);
Mat
centerLeft
=
binary
.
submat
(
topBottomHeight
,(
topBottomHeight
+
centerHeight
),
0
,
leftRightWidth
);
Mat
bottomLeft
=
binary
.
submat
((
topBottomHeight
+
centerHeight
),(
2
*
topBottomHeight
+
centerHeight
),
0
,
leftRightWidth
);
//crop center 3 images
Mat
topCenter
=
binary
.
submat
(
0
,
topBottomHeight
,
leftRightWidth
,(
centerWidth
+
leftRightWidth
));
Mat
centerCenter
=
binary
.
submat
(
topBottomHeight
,(
topBottomHeight
+
centerHeight
),
leftRightWidth
,(
centerWidth
+
leftRightWidth
));
Mat
bottomCenter
=
binary
.
submat
((
topBottomHeight
+
centerHeight
),(
2
*
topBottomHeight
+
centerHeight
),
leftRightWidth
,(
centerWidth
+
leftRightWidth
));
//crop right 3 images
Mat
topRight
=
binary
.
submat
(
0
,
topBottomHeight
,(
centerWidth
+
leftRightWidth
),(
leftRightWidth
*
2
+
centerWidth
));
Mat
centerRight
=
binary
.
submat
(
topBottomHeight
,(
topBottomHeight
+
centerHeight
),(
centerWidth
+
leftRightWidth
),(
leftRightWidth
*
2
+
centerWidth
));
Mat
bottomRight
=
binary
.
submat
((
topBottomHeight
+
centerHeight
),(
2
*
topBottomHeight
+
centerHeight
),(
centerWidth
+
leftRightWidth
),(
leftRightWidth
*
2
+
centerWidth
));
//creating bitmaps
Bitmap
bTopLeft
=
matToBitmap
(
topLeft
);
Bitmap
bCenterLeft
=
matToBitmap
(
centerLeft
);
Bitmap
bBottomLeft
=
matToBitmap
(
bottomLeft
);
//creating bitmaps
Bitmap
bTopCenter
=
matToBitmap
(
topCenter
);
Bitmap
bCenterCenter
=
matToBitmap
(
centerCenter
);
Bitmap
bBottomCenter
=
matToBitmap
(
bottomCenter
);
//creating bitmaps
@Override
Bitmap
bTopRight
=
matToBitmap
(
topRight
);
public
void
onTop
()
{
Bitmap
bCenterRight
=
matToBitmap
(
centerRight
);
Bitmap
bBottomRight
=
matToBitmap
(
bottomRight
);
if
(!
isLeftDone
)
return
;
runOnUiThread
(
new
Runnable
()
{
runOnUiThread
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
public
void
run
()
{
{
if
(!
isTopDone
)
// leftV.setImageBitmap(bCenterLeft);
{
// centerV.setImageBitmap(bCenterCenter);
nextGesture
(
right
,
2000
,
50
,
0
,
"Right"
);
// rightV.setImageBitmap(bCenterRight);
top
.
setVisibility
(
View
.
INVISIBLE
);
// rightV.setImageBitmap(rightViewBitmap);
}
isTopDone
=
true
;
}
}
});
});
}
//Log.d("ViewPoint","Width - " + width + ", Equal width" + equalWidth + " ,left - " + left.cols() + ", Center - " + center.cols());
@Override
public
void
onBottom
()
{
int
topLeftAllPixels
=
topLeft
.
cols
()
*
topLeft
.
rows
();
int
centerLeftAllPixels
=
centerLeft
.
cols
()
*
centerLeft
.
rows
();
int
bottomLeftAllPixels
=
bottomLeft
.
cols
()
*
bottomLeft
.
rows
();
int
topCenterAllPixels
=
topCenter
.
cols
()
*
topCenter
.
rows
();
int
centerCenterAllPixels
=
centerCenter
.
cols
()
*
centerCenter
.
rows
();
int
bottomCenterAllPixels
=
bottomCenter
.
cols
()
*
bottomCenter
.
rows
();
int
topRightAllPixels
=
topRight
.
cols
()
*
topRight
.
rows
();
int
centerRightAllPixels
=
centerRight
.
cols
()
*
centerRight
.
rows
();
int
bottomRightAllPixels
=
bottomRight
.
cols
()
*
bottomRight
.
rows
();
int
topLeftWhitePixels
=
Core
.
countNonZero
(
topLeft
);
int
centerLeftWhitePixels
=
Core
.
countNonZero
(
centerLeft
);
int
bottomLeftWhitePixels
=
Core
.
countNonZero
(
bottomLeft
);
int
topCenterWhitePixels
=
Core
.
countNonZero
(
topCenter
);
int
centerCenterWhitePixels
=
Core
.
countNonZero
(
centerCenter
);
int
bottomCenterWhitePixels
=
Core
.
countNonZero
(
bottomCenter
);
int
topRightWhitePixels
=
Core
.
countNonZero
(
topRight
);
int
centerRightWhitePixels
=
Core
.
countNonZero
(
centerRight
);
int
bottomRightWhitePixels
=
Core
.
countNonZero
(
bottomRight
);
int
topLeftBlackPixels
=
topLeftAllPixels
-
topLeftWhitePixels
;
int
centerLeftBlackPixels
=
centerLeftAllPixels
-
centerLeftWhitePixels
;
int
bottomLeftBlackPixels
=
bottomLeftAllPixels
-
bottomLeftWhitePixels
;
int
topCenterBlackPixels
=
topCenterAllPixels
-
topCenterWhitePixels
;
int
centerCenterBlackPixels
=
centerCenterAllPixels
-
centerCenterWhitePixels
;
int
bottomCenterBlackPixels
=
bottomCenterAllPixels
-
bottomCenterWhitePixels
;
int
topRightBlackPixels
=
topRightAllPixels
-
topRightWhitePixels
;
int
centerRightBlackPixels
=
centerRightAllPixels
-
centerRightWhitePixels
;
int
bottomRightBlackPixels
=
bottomRightAllPixels
-
bottomRightWhitePixels
;
int
[]
arr
=
{
topLeftBlackPixels
,
centerLeftBlackPixels
,
bottomLeftBlackPixels
,
topCenterBlackPixels
,
centerCenterBlackPixels
,
bottomCenterBlackPixels
,
topRightBlackPixels
,
centerRightBlackPixels
,
bottomRightBlackPixels
};
//sort the array, so i can find the largest value
Arrays
.
sort
(
arr
);
//get the final item of list. because the list is sorted and the final item is the largest
int
max
=
arr
[
arr
.
length
-
1
];
if
(
max
!=
0
)
{
if
(
max
==
topLeftBlackPixels
)
{
//left
Log
.
d
(
"ViewPoint"
,
"Top left"
);
setViewPointText
(
"Looking top Left"
);
speak
(
"Top left"
);
}
else
if
(
max
==
centerLeftBlackPixels
)
{
//left
Log
.
d
(
"ViewPoint"
,
"Center left"
);
setViewPointText
(
"Looking center Left"
);
speak
(
"Center left"
);
}
else
if
(
max
==
bottomLeftBlackPixels
)
{
//left
Log
.
d
(
"ViewPoint"
,
"Bottom left"
);
setViewPointText
(
"Looking bottom Left"
);
speak
(
"Bottom left"
);
}
else
if
(
max
==
topRightBlackPixels
)
{
//right
Log
.
d
(
"ViewPoint"
,
"Top Right"
);
setViewPointText
(
"Looking top Right"
);
speak
(
"Top right"
);
}
else
if
(
max
==
centerRightBlackPixels
)
{
//right
Log
.
d
(
"ViewPoint"
,
"Center Right"
);
setViewPointText
(
"Looking center Right"
);
speak
(
"center right"
);
}
else
if
(
max
==
bottomRightBlackPixels
)
{
//right
Log
.
d
(
"ViewPoint"
,
"Bottom Right"
);
setViewPointText
(
"Looking bottom Right"
);
speak
(
"bottom right"
);
}
else
if
(
max
==
topCenterBlackPixels
)
{
//center
Log
.
d
(
"ViewPoint"
,
"Top Center"
);
setViewPointText
(
"Looking top Center"
);
speak
(
"Top center"
);
}
else
if
(
max
==
centerCenterBlackPixels
)
{
//center
Log
.
d
(
"ViewPoint"
,
"Center Center"
);
setViewPointText
(
"Looking center Center"
);
//speak("cent left");
}
else
if
(
max
==
bottomCenterBlackPixels
)
{
//center
Log
.
d
(
"ViewPoint"
,
"Bottom Center"
);
setViewPointText
(
"Looking Bottom Center"
);
speak
(
"bottom center"
);
}
}
if
(!
isTopDone
)
return
;
}
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
setViewPointText
(
String
text
)
{
runOnUiThread
(
new
Runnable
()
{
runOnUiThread
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
view_point
.
setText
(
text
);
if
(!
isBottomDone
)
}
{
});
bottom
.
setVisibility
(
View
.
INVISIBLE
);
}
public
synchronized
void
speak
(
String
text
)
new
Handler
().
postDelayed
(
new
Runnable
()
{
{
@Override
// if(lastSpeechText.equals(text))
public
void
run
()
// {
{
// return;
speak
(
"You're good to go."
);
// }
// tts.speak("" + text, TextToSpeech.QUEUE_ADD,null,null);
new
Handler
().
postDelayed
(
new
Runnable
()
{
// lastSpeechText = text;
@Override
}
public
void
run
()
public
synchronized
void
accessEnvironment
(
Mat
mat
,
int
contourSize
,
double
contourArea
)
{
{
Intent
intent
=
new
Intent
(
EnvironmentChecker
.
this
,
CustomGallery
.
class
);
if
(
detectionResults
==
null
)
detectionResults
=
new
ArrayList
<>();
intent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
if
(
mat
==
null
)
return
;
intent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_CLEAR_TOP
);
startActivity
(
intent
);
int
allPixels
=
mat
.
cols
()
*
mat
.
rows
();
finish
();
int
whitePixels
=
Core
.
countNonZero
(
mat
);
}
int
blackPixels
=
allPixels
-
whitePixels
;
},
1000
);
}
brightnessLevel
+=
0.1f
;
},
2000
);
if
(
brightnessLevel
>
MAX_BRIGHTNESS_LEVEL
)
{
brightnessLevel
=
0.0f
;
isAccessingEnvironment
=
false
;
findBestBrightnessLevel
();
}
if
(
contourSize
==
1
&&
contourArea
<
500
&&
contourArea
>
10
)
{
EyeDetectionResultSet
result
=
new
EyeDetectionResultSet
();
result
.
setBlackPixels
(
blackPixels
);
result
.
setBrightnessLevel
(
brightnessLevel
);
result
.
setContourSize
(
contourSize
);
detectionResults
.
add
(
result
);
}
if
(
isAccessingEnvironment
)
}
{
isBottomDone
=
true
;
double
ratio
=
(
brightnessLevel
/
MAX_BRIGHTNESS_LEVEL
)
*
100
;
Log
.
d
(
"ContourSize"
,
""
+
Math
.
round
(
ratio
));
setProgressValue
((
int
)
Math
.
round
(
ratio
));
}
}
synchronized
void
findBestBrightnessLevel
()
{
if
(
detectionResults
.
isEmpty
())
{
isAccessingEnvironment
=
true
;
return
;
}
float
[]
brightnessArray
=
new
float
[
detectionResults
.
size
()];
for
(
int
i
=
0
;
i
<
detectionResults
.
size
();
i
++)
}
{
});
EyeDetectionResultSet
set
=
detectionResults
.
get
(
i
);
brightnessArray
[
i
]
=
set
.
getBrightnessLevel
();
}
brightnessLevel
=
brightnessArray
[
brightnessArray
.
length
-
1
];
}
}
public
void
s
etProgressValue
(
int
progress
)
public
void
s
peak
(
String
text
)
{
{
// try
tts
.
speak
(
text
,
TextToSpeech
.
QUEUE_FLUSH
,
null
,
null
);
// {
// Thread.sleep(500);
// }
// catch (InterruptedException e)
// {
// e.printStackTrace();
// }
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
progressBar
.
setProgress
(
progress
);
}
});
}
}
}
}
\ No newline at end of file
app/src/main/java/com/app/smartphotoeditor/activities/SplashScreen.java
View file @
56acdc7f
...
@@ -41,7 +41,7 @@ public class SplashScreen extends AppCompatActivity {
...
@@ -41,7 +41,7 @@ public class SplashScreen extends AppCompatActivity {
}
}
else
else
{
{
intent
=
new
Intent
(
SplashScreen
.
this
,
CustomGallery
.
class
);
intent
=
new
Intent
(
SplashScreen
.
this
,
EnvironmentChecker
.
class
);
}
}
startActivity
(
intent
);
startActivity
(
intent
);
...
...
app/src/main/java/com/app/smartphotoeditor/vision/EyeBlinkDetection.java
View file @
56acdc7f
...
@@ -24,8 +24,8 @@ public class EyeBlinkDetection
...
@@ -24,8 +24,8 @@ public class EyeBlinkDetection
private
final
int
imageSize
;
private
final
int
imageSize
;
private
static
final
int
MIN_EYE_CLOSE_COUNT
=
0
;
private
static
final
int
MIN_EYE_CLOSE_COUNT
=
0
;
private
static
final
int
LONG_EYE_CLOSE_COUNT
=
6
;
private
static
final
int
LONG_EYE_CLOSE_COUNT
=
4
;
private
static
final
int
MAX_EYE_CLOSE_TIME
=
10
;
private
static
final
int
MAX_EYE_CLOSE_TIME
=
8
;
private
int
eyeCloseCount
=
MIN_EYE_CLOSE_COUNT
;
private
int
eyeCloseCount
=
MIN_EYE_CLOSE_COUNT
;
private
final
OnEyeStatusChanged
listener
;
private
final
OnEyeStatusChanged
listener
;
...
...
app/src/main/res/drawable/arrow.png
0 → 100644
View file @
56acdc7f
11.4 KB
app/src/main/res/drawable/icon.png
0 → 100644
View file @
56acdc7f
62.4 KB
app/src/main/res/layout/activity_editor.xml
View file @
56acdc7f
...
@@ -109,5 +109,15 @@
...
@@ -109,5 +109,15 @@
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"@+id/userSelectedImage"
/>
app:layout_constraintTop_toTopOf=
"@+id/userSelectedImage"
/>
<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
app/src/main/res/layout/activity_environment_checker.xml
View file @
56acdc7f
...
@@ -5,21 +5,23 @@
...
@@ -5,21 +5,23 @@
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@color/white"
android:background=
"@color/white"
android:id=
"@+id/main_container"
tools:context=
".activities.CameraView"
>
tools:context=
".activities.CameraView"
>
<org.opencv.android.JavaCameraView
<ImageView
android:background=
"@color/colorPrimary"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:id=
"@+id/
frame_Surface
"
/>
android:id=
"@+id/
preview
"
/>
<androidx.constraintlayout.widget.ConstraintLayout
<!-- <androidx.constraintlayout.widget.ConstraintLayout-->
android:layout_width=
"match_parent"
<!-- android:layout_width="match_parent"-->
android:layout_height=
"match_parent"
<!-- android:layout_height="match_parent"-->
android:alpha=
"0.4"
<!-- android:alpha="0.4"-->
android:background=
"@color/black"
<!-- android:background="@color/black"-->
tools:layout_editor_absoluteX=
"0dp"
<!-- tools:layout_editor_absoluteX="0dp"-->
tools:layout_editor_absoluteY=
"0dp"
/
>
<!-- tools:layout_editor_absoluteY="0dp" />--
>
<TextView
<TextView
android:id=
"@+id/textView"
android:id=
"@+id/textView"
...
@@ -40,64 +42,52 @@
...
@@ -40,64 +42,52 @@
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
app:layout_constraintTop_toTopOf=
"parent"
/>
<ImageView
<de.hdodenhof.circleimageview.CircleImageView
android:id=
"@+id/left"
android:id=
"@+id/frame"
android:layout_width=
"100dp"
android:layout_width=
"130dp"
android:layout_height=
"100dp"
android:layout_height=
"130dp"
android:layout_marginStart=
"60dp"
android:layout_marginTop=
"32dp"
android:rotation=
"180"
android:scaleType=
"centerCrop"
android:src=
"@drawable/arrow"
app:civ_border_color=
"@color/white"
android:visibility=
"invisible"
app:civ_border_width=
"2dp"
app:layout_constraintBottom_toBottomOf=
"@+id/preview"
android:src=
"@drawable/eye"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_to
BottomOf=
"@+id/textView
"
/>
app:layout_constraintTop_to
TopOf=
"parent
"
/>
<TextView
<ImageView
android:id=
"@+id/textView1"
android:id=
"@+id/right"
android:layout_width=
"match_parent"
android:layout_width=
"100dp"
android:layout_height=
"wrap_content"
android:layout_height=
"100dp"
android:layout_marginStart=
"32dp"
android:layout_marginEnd=
"60dp"
android:layout_marginTop=
"12dp"
android:src=
"@drawable/arrow"
android:layout_marginEnd=
"32dp"
android:visibility=
"invisible"
android:gravity=
"center"
app:layout_constraintBottom_toBottomOf=
"parent"
android:letterSpacing=
"0.1"
android:lineSpacingMultiplier=
"1.2"
android:text=
"Place your eye"
android:textAllCaps=
"true"
android:textColor=
"@color/white"
android:textSize=
"16sp"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintHorizontal_bias=
"0.0"
app:layout_constraintTop_toTopOf=
"parent"
/>
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/frame"
/>
<ProgressBar
<ImageView
android:id=
"@+id/progress_bar"
android:id=
"@+id/top"
style=
"?android:attr/progressBarStyleHorizontal"
android:layout_width=
"100dp"
android:layout_width=
"match_parent"
android:layout_height=
"100dp"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"70dp"
android:layout_marginStart=
"60dp"
android:rotation=
"270"
android:layout_marginTop=
"50dp"
android:src=
"@drawable/arrow"
android:layout_marginEnd=
"60dp"
android:visibility=
"invisible"
android:progress=
"0"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/textView1"
/>
app:layout_constraintTop_toBottomOf=
"@+id/textView"
/>
<TextView
<ImageView
android:id=
"@+id/view_point"
android:id=
"@+id/bottom"
android:layout_width=
"match_parent"
android:layout_width=
"100dp"
android:layout_height=
"wrap_content"
android:layout_height=
"100dp"
android:gravity=
"center"
android:layout_marginBottom=
"150dp"
android:text=
"View Point"
android:rotation=
"90"
android:textColor=
"@android:color/white"
android:src=
"@drawable/arrow"
android:textSize=
"20sp"
android:visibility=
"invisible"
app:layout_constraintBottom_toBottomOf=
"@+id/frame_Surface"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/frame"
/>
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
app/src/main/res/layout/activity_splash_screen.xml
View file @
56acdc7f
...
@@ -4,17 +4,18 @@
...
@@ -4,17 +4,18 @@
xmlns:tools=
"http://schemas.android.com/tools"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@color/white"
tools:context=
".activities.SplashScreen"
>
tools:context=
".activities.SplashScreen"
>
<ImageView
<ImageView
android:layout_width=
"0dp"
android:layout_width=
"wrap_content"
android:layout_height=
"0dp"
android:layout_height=
"200dp"
android:scaleType=
"centerCrop"
android:layout_marginStart=
"50dp"
android:src=
"@drawable/logo"
android:layout_marginEnd=
"50dp"
android:src=
"@drawable/icon"
app:layout_constraintBottom_toTopOf=
"@+id/textView"
app:layout_constraintBottom_toTopOf=
"@+id/textView"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
/>
app:layout_constraintTop_toTopOf=
"parent"
/>
<TextView
<TextView
...
@@ -27,7 +28,8 @@
...
@@ -27,7 +28,8 @@
android:text=
"@string/app_name"
android:text=
"@string/app_name"
android:textAllCaps=
"true"
android:textAllCaps=
"true"
android:textColor=
"@color/tools_icon_ash"
android:textColor=
"@color/tools_icon_ash"
android:textSize=
"21sp"
android:textSize=
"20sp"
android:textStyle=
"bold"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"@+id/guideline7"
/>
app:layout_constraintTop_toTopOf=
"@+id/guideline7"
/>
...
@@ -37,6 +39,6 @@
...
@@ -37,6 +39,6 @@
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
android:orientation=
"horizontal"
app:layout_constraintGuide_percent=
"0.5"
/>
app:layout_constraintGuide_percent=
"0.5
1
"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment