Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Ear recognition
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Boston University
Ear recognition
Commits
1993caeb
Commit
1993caeb
authored
Jan 15, 2016
by
Josejulio Martínez Magaña
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Started building the third gen interaction.
parent
25a16c30
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
104 additions
and
606 deletions
+104
-606
EarCaptureActivity.java
...aluxoft/earrecognition/activities/EarCaptureActivity.java
+1
-134
SelectFollowupActivity.java
...oft/earrecognition/activities/SelectFollowupActivity.java
+6
-13
IntentSearchFeatures.java
.../aluxoft/earrecognition/intents/IntentSearchFeatures.java
+83
-0
EarDataLoaderCommcare.java
.../aluxoft/earrecognition/loader/EarDataLoaderCommcare.java
+2
-0
MainActivity.java
.../java/com/aluxoft/earrecognition/unused/MainActivity.java
+0
-386
activity_main.xml
app/src/main/res/layout/activity_main.xml
+0
-73
open_commcare_layout.xml
app/src/main/res/layout/open_commcare_layout.xml
+12
-0
No files found.
app/src/main/java/com/aluxoft/earrecognition/activities/EarCaptureActivity.java
View file @
1993caeb
...
@@ -26,14 +26,6 @@ import java.io.IOException;
...
@@ -26,14 +26,6 @@ import java.io.IOException;
*/
*/
public
class
EarCaptureActivity
extends
Activity
{
public
class
EarCaptureActivity
extends
Activity
{
Button
getImage
;
Button
returnToCommCare
;
File
location
;
public
static
final
int
KEY_REQUEST_IMAGE
=
1
;
public
static
final
int
KEY_SIFT_ACTIVITY_LOADER
=
2
;
/*
/*
* (non-Javadoc)
* (non-Javadoc)
* @see android.app.Activity#onCreate(android.os.Bundle)
* @see android.app.Activity#onCreate(android.os.Bundle)
...
@@ -42,132 +34,7 @@ public class EarCaptureActivity extends Activity {
...
@@ -42,132 +34,7 @@ public class EarCaptureActivity extends Activity {
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
Fabric
.
with
(
this
,
new
Crashlytics
());
Fabric
.
with
(
this
,
new
Crashlytics
());
setContentView
(
R
.
layout
.
activity_callout
);
setContentView
(
R
.
layout
.
open_commcare_layout
);
/*
returnToCommCare = (Button)this.findViewById(R.id.button_commcare);
returnToCommCare.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent("org.commcare.dalvik.action.CommCareSession");
String sssd = "";
sssd +=
"COMMAND_ID" + " " + "root" + " "
+
"CASE_ID" + " " + "case_id" + " " + "99de08b8-7235-41ba-9dbe-d1e5d70575cf" + " " +
"COMMAND_ID" + " " + "m1-f1";
i.putExtra("ccodk_session_request", sssd);
EarCaptureActivity.this.startActivity(i);
}
});
// Load data from Commcare
Cursor c = this.managedQuery(Uri.parse("content://org.commcare.dalvik.case/casedb/case"), null, null, null, null);
for (int i=0;i<c.getColumnCount();++i) {
System.out.print(c.getColumnName(i) + "|");
}
System.out.println();
while (c.moveToNext()) {
for (int i=0;i<c.getColumnCount();++i) {
System.out.print(c.getString(i) + "|");
}
System.out.println();
}
*/
getImage
=
(
Button
)
this
.
findViewById
(
R
.
id
.
take_picture
);
getImage
.
setOnClickListener
(
new
OnClickListener
()
{
private
Toast
loginInCommCareToast
=
null
;
public
void
onClick
(
View
v
)
{
if
(!
EarDataLoaderCommcare
.
checkConnection
(
EarCaptureActivity
.
this
))
{
if
(
loginInCommCareToast
==
null
||
loginInCommCareToast
.
getView
().
getWindowVisibility
()
!=
View
.
VISIBLE
)
{
loginInCommCareToast
=
Toast
.
makeText
(
EarCaptureActivity
.
this
,
"Please login in CommCare application to proceed."
,
Toast
.
LENGTH_LONG
);
loginInCommCareToast
.
show
();
}
return
;
}
Intent
i
=
new
Intent
(
android
.
provider
.
MediaStore
.
ACTION_IMAGE_CAPTURE
);
try
{
location
=
ImageUtils
.
createTempImageFile
();
}
catch
(
IOException
e1
)
{
// TODO Auto-generated catch block
e1
.
printStackTrace
();
return
;
}
// if this gets modified, the onActivityResult in
// FormEntyActivity will also need to be updated.
i
.
putExtra
(
android
.
provider
.
MediaStore
.
EXTRA_OUTPUT
,
Uri
.
fromFile
(
location
));
try
{
startActivityForResult
(
i
,
KEY_REQUEST_IMAGE
);
}
catch
(
ActivityNotFoundException
e
)
{
Toast
.
makeText
(
EarCaptureActivity
.
this
,
"No Camera"
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
});
if
(
this
.
getLastNonConfigurationInstance
()
!=
null
)
{
location
=
((
EarCaptureActivity
)
this
.
getLastNonConfigurationInstance
()).
location
;
}
if
(
savedInstanceState
!=
null
)
{
location
=
new
File
(
savedInstanceState
.
getString
(
"location"
));
}
}
/* (non-Javadoc)
* @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
*/
@Override
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
if
(
requestCode
==
KEY_REQUEST_IMAGE
)
{
//Go grab the image and set it's location
if
(
location
==
null
||
!
location
.
exists
())
{
location
=
null
;
}
else
{
String
path
=
location
.
getAbsolutePath
();
EarIdentifier
identifier
=
new
EarIdentifier
(
null
);
Intent
intent
=
new
Intent
(
"com.auriclon.activity_sift"
);
intent
.
putExtra
(
"image_path"
,
path
);
startActivityForResult
(
intent
,
KEY_SIFT_ACTIVITY_LOADER
);
}
}
else
if
(
requestCode
==
KEY_SIFT_ACTIVITY_LOADER
)
{
startActivity
(
data
);
}
}
/* (non-Javadoc)
* @see android.app.Activity#onResume()
*/
@Override
protected
void
onResume
()
{
super
.
onResume
();
}
/* (non-Javadoc)
* @see android.app.Activity#onSaveInstanceState(android.os.Bundle)
*/
@Override
protected
void
onSaveInstanceState
(
Bundle
outState
)
{
super
.
onSaveInstanceState
(
outState
);
if
(
location
!=
null
)
{
outState
.
putString
(
"location"
,
location
.
toString
());
}
}
/* (non-Javadoc)
* @see android.app.Activity#onRetainNonConfigurationInstance()
*/
@Override
public
Object
onRetainNonConfigurationInstance
()
{
return
this
;
}
}
}
}
app/src/main/java/com/aluxoft/earrecognition/activities/SelectFollowupActivity.java
View file @
1993caeb
...
@@ -49,25 +49,18 @@ public class SelectFollowupActivity extends Activity {
...
@@ -49,25 +49,18 @@ public class SelectFollowupActivity extends Activity {
topNListView
.
setOnItemClickListener
(
new
AdapterView
.
OnItemClickListener
()
{
topNListView
.
setOnItemClickListener
(
new
AdapterView
.
OnItemClickListener
()
{
@Override
@Override
public
void
onItemClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
public
void
onItemClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
Intent
intent
=
new
Intent
(
"org.commcare.dalvik.action.CommCareSession"
);
Intent
intent
=
new
Intent
();
String
sssd
=
""
;
intent
.
putExtra
(
"case_id"
,
earIdList
.
getTop
().
get
(
position
).
person
.
getCaseId
());
sssd
+=
SelectFollowupActivity
.
this
.
setResult
(
Activity
.
RESULT_OK
,
intent
);
"COMMAND_ID"
+
" "
+
"m1"
+
" "
finish
();
+
"CASE_ID"
+
" "
+
"case_id"
+
" "
+
earIdList
.
getTop
().
get
(
position
).
person
.
getCaseId
()
+
" "
/* + // "99de08b8-7235-41ba-9dbe-d1e5d70575cf" + " " +
"COMMAND_ID" + " " + "m1-f0" */
;
intent
.
putExtra
(
"ccodk_session_request"
,
sssd
);
SelectFollowupActivity
.
this
.
startActivityForResult
(
intent
,
COMMCARE_FOLLOW_UP
);
}
}
});
});
registerButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
registerButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
@Override
public
void
onClick
(
View
v
)
{
public
void
onClick
(
View
v
)
{
Intent
i
=
new
Intent
(
"org.commcare.dalvik.action.CommCareSession"
);
SelectFollowupActivity
.
this
.
setResult
(
Activity
.
RESULT_OK
,
new
Intent
());
String
sssd
=
"COMMAND_ID"
+
" "
+
"root"
+
" "
+
"COMMAND_ID"
+
" "
+
"m0-f0"
;
finish
();
i
.
putExtra
(
"ccodk_session_request"
,
sssd
);
SelectFollowupActivity
.
this
.
startActivityForResult
(
i
,
COMMCARE_REGISTER
);
}
}
});
});
}
}
...
...
app/src/main/java/com/aluxoft/earrecognition/intents/IntentSearchFeatures.java
View file @
1993caeb
package
com
.
aluxoft
.
earrecognition
.
intents
;
package
com
.
aluxoft
.
earrecognition
.
intents
;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.content.ActivityNotFoundException
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.widget.Toast
;
import
com.aluxoft.earrecognition.EarIdentifier
;
import
com.aluxoft.earrecognition.activities.SelectFollowupActivity
;
import
com.aluxoft.earrecognition.activities.SelectFollowupActivity
;
import
com.aluxoft.earrecognition.utils.ImageUtils
;
import
com.crashlytics.android.Crashlytics
;
import
java.io.File
;
import
java.io.IOException
;
import
io.fabric.sdk.android.Fabric
;
/**
/**
* Created by dkor on 11/13/15.
* Created by dkor on 11/13/15.
*/
*/
public
class
IntentSearchFeatures
extends
Activity
{
public
class
IntentSearchFeatures
extends
Activity
{
private
File
location
;
public
static
final
int
KEY_REQUEST_IMAGE
=
1
;
public
static
final
int
KEY_SIFT_ACTIVITY_LOADER
=
2
;
public
static
final
int
KEY_TOP_X
=
3
;
@Override
@Override
protected
void
onCreate
(
Bundle
saveInstanceState
)
{
protected
void
onCreate
(
Bundle
saveInstanceState
)
{
super
.
onCreate
(
saveInstanceState
);
super
.
onCreate
(
saveInstanceState
);
Fabric
.
with
(
this
,
new
Crashlytics
());
this
.
takePhoto
();
// Mostrar la camara
/*
Intent returningIntent = new Intent(getIntent());
Intent returningIntent = new Intent(getIntent());
returningIntent.putExtra(
returningIntent.putExtra(
"ear_search_result",
"ear_search_result",
"Juan");
"Juan");
this.setResult(Activity.RESULT_OK, returningIntent);
this.setResult(Activity.RESULT_OK, returningIntent);
finish();
finish();
*/
}
public
boolean
takePhoto
()
{
Intent
i
=
new
Intent
(
android
.
provider
.
MediaStore
.
ACTION_IMAGE_CAPTURE
);
try
{
location
=
ImageUtils
.
createTempImageFile
();
}
catch
(
IOException
e1
)
{
e1
.
printStackTrace
();
return
false
;
}
// if this gets modified, the onActivityResult in
// FormEntyActivity will also need to be updated.
i
.
putExtra
(
android
.
provider
.
MediaStore
.
EXTRA_OUTPUT
,
Uri
.
fromFile
(
location
));
try
{
startActivityForResult
(
i
,
KEY_REQUEST_IMAGE
);
}
catch
(
ActivityNotFoundException
e
)
{
return
false
;
}
return
true
;
}
@Override
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
if
(
requestCode
==
KEY_REQUEST_IMAGE
)
{
//Go grab the image and set it's location
if
(
location
==
null
||
!
location
.
exists
())
{
location
=
null
;
}
else
{
String
path
=
location
.
getAbsolutePath
();
EarIdentifier
identifier
=
new
EarIdentifier
(
null
);
Intent
intent
=
new
Intent
(
"com.auriclon.activity_sift"
);
intent
.
putExtra
(
"image_path"
,
path
);
startActivityForResult
(
intent
,
KEY_SIFT_ACTIVITY_LOADER
);
}
}
else
if
(
requestCode
==
KEY_SIFT_ACTIVITY_LOADER
)
{
startActivityForResult
(
data
,
KEY_TOP_X
);
}
else
if
(
requestCode
==
KEY_TOP_X
)
{
String
case_id
=
data
.
getStringExtra
(
"case_id"
);
if
(
case_id
==
null
)
{
case_id
=
""
;
}
Intent
returningIntent
=
new
Intent
(
getIntent
());
returningIntent
.
putExtra
(
"ear_search_result"
,
case_id
);
this
.
setResult
(
Activity
.
RESULT_OK
,
returningIntent
);
finish
();
}
}
@Override
protected
void
onSaveInstanceState
(
Bundle
outState
)
{
super
.
onSaveInstanceState
(
outState
);
if
(
location
!=
null
)
{
outState
.
putString
(
"location"
,
location
.
toString
());
}
}
}
}
}
app/src/main/java/com/aluxoft/earrecognition/loader/EarDataLoaderCommcare.java
View file @
1993caeb
...
@@ -52,6 +52,8 @@ public class EarDataLoaderCommcare extends EarDataLoader {
...
@@ -52,6 +52,8 @@ public class EarDataLoaderCommcare extends EarDataLoader {
gender = caseCursor.getString(caseCursor.getColumnIndex("value"));
gender = caseCursor.getString(caseCursor.getColumnIndex("value"));
} else */
if
(
datumId
.
equals
(
"features"
))
{
} else */
if
(
datumId
.
equals
(
"features"
))
{
features
=
caseCursor
.
getString
(
caseCursor
.
getColumnIndex
(
"value"
));
features
=
caseCursor
.
getString
(
caseCursor
.
getColumnIndex
(
"value"
));
}
else
if
(
datumId
.
equals
(
"case_id_internal"
))
{
// ToDo: Remplazarlo con una mejor forma
caseId
=
caseCursor
.
getString
(
caseCursor
.
getColumnIndex
(
"value"
));
}
}
}
}
if
(
/*gender == null || */
features
==
null
)
{
if
(
/*gender == null || */
features
==
null
)
{
...
...
app/src/main/java/com/aluxoft/earrecognition/unused/MainActivity.java
deleted
100644 → 0
View file @
25a16c30
package
com
.
aluxoft
.
earrecognition
.
unused
;
import
android.annotation.SuppressLint
;
import
android.app.AlertDialog
;
import
android.app.ProgressDialog
;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.content.res.Resources
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Environment
;
import
android.provider.MediaStore
;
import
android.support.v7.app.ActionBarActivity
;
import
android.util.DisplayMetrics
;
import
android.util.Log
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.ImageView
;
import
com.aluxoft.earrecognition.R
;
import
org.opencv.android.Utils
;
import
org.opencv.core.Mat
;
import
org.opencv.core.MatOfDMatch
;
import
org.opencv.core.MatOfKeyPoint
;
import
org.opencv.core.Size
;
import
org.opencv.features2d.DMatch
;
import
org.opencv.features2d.DescriptorExtractor
;
import
org.opencv.features2d.DescriptorMatcher
;
import
org.opencv.features2d.FeatureDetector
;
import
org.opencv.features2d.Features2d
;
import
org.opencv.highgui.Highgui
;
import
org.opencv.imgproc.Imgproc
;
import
java.io.File
;
import
java.io.IOException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.concurrent.Callable
;
import
bolts.Continuation
;
import
bolts.Task
;
public
class
MainActivity
extends
ActionBarActivity
{
ProgressDialog
loading
;
private
static
final
int
REQUEST_IMAGE_CAPTURE
=
1
;
private
String
mCurrentPhotoPath
;
private
String
mCurrentPhotoPath1
=
null
;
private
String
mCurrentPhotoPath2
=
null
;
private
String
mCurrentPhotoPath3
=
null
;
private
int
previewWidth
=
150
;
private
int
previewHeight
=
150
;
private
ImageView
previewImage1
;
private
ImageView
previewImage2
;
private
ImageView
previewImage3
;
private
ImageView
previewImage
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
System
.
loadLibrary
(
"opencv_java"
);
System
.
loadLibrary
(
"nonfree"
);
setContentView
(
R
.
layout
.
activity_main
);
previewImage1
=
(
ImageView
)
findViewById
(
R
.
id
.
imageView
);
previewImage2
=
(
ImageView
)
findViewById
(
R
.
id
.
imageView2
);
previewImage3
=
(
ImageView
)
findViewById
(
R
.
id
.
imageView3
);
final
Button
captureFirstEarButton
=
(
Button
)
findViewById
(
R
.
id
.
button
);
captureFirstEarButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
previewImage
=
previewImage1
;
takePhoto
();
mCurrentPhotoPath1
=
mCurrentPhotoPath
;
}
});
final
Button
captureSecondEarButton
=
(
Button
)
findViewById
(
R
.
id
.
button2
);
captureSecondEarButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
previewImage
=
previewImage2
;
takePhoto
();
mCurrentPhotoPath2
=
mCurrentPhotoPath
;
}
});
final
Button
captureEarToIdentifyButton
=
(
Button
)
findViewById
(
R
.
id
.
toidentify
);
captureEarToIdentifyButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
previewImage
=
previewImage3
;
takePhoto
();
mCurrentPhotoPath3
=
mCurrentPhotoPath
;
}
});
final
Button
processButton
=
(
Button
)
findViewById
(
R
.
id
.
button3
);
processButton
.
setOnClickListener
(
new
View
.
OnClickListener
(){
@Override
public
void
onClick
(
View
v
)
{
// do opencv magic here...
if
(
mCurrentPhotoPath1
!=
null
&&
mCurrentPhotoPath2
!=
null
&&
mCurrentPhotoPath3
!=
null
)
{
Task
.
callInBackground
(
new
Callable
<
Void
>()
{
@Override
public
Void
call
()
throws
Exception
{
doOpenCvMagic
();
return
null
;
}
}).
continueWith
(
new
Continuation
<
Void
,
Void
>()
{
@Override
public
Void
then
(
Task
<
Void
>
task
)
throws
Exception
{
return
null
;
}
});
}
}
});
}
public
void
takePhoto
()
{
Intent
takePictureIntent
=
new
Intent
(
MediaStore
.
ACTION_IMAGE_CAPTURE
);
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
FROYO
)
{
if
(
takePictureIntent
.
resolveActivity
(
getPackageManager
())
!=
null
)
{
File
photoFile
=
null
;
try
{
photoFile
=
createImageFile
();
}
catch
(
IOException
ex
)
{
// Error occurred while creating the File
}
// Continue only if the File was successfully created
if
(
photoFile
!=
null
)
{
takePictureIntent
.
putExtra
(
MediaStore
.
EXTRA_OUTPUT
,
Uri
.
fromFile
(
photoFile
));
startActivityForResult
(
takePictureIntent
,
REQUEST_IMAGE_CAPTURE
);
}
}
}
}
@SuppressLint
(
"NewApi"
)
@Override
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
if
(
requestCode
==
REQUEST_IMAGE_CAPTURE
)
{
if
(
resultCode
==
RESULT_OK
)
{
if
(
mCurrentPhotoPath
!=
null
)
{
// adds image to device gallery.
Intent
mediaScanIntent
=
new
Intent
(
Intent
.
ACTION_MEDIA_SCANNER_SCAN_FILE
);
File
f
=
new
File
(
mCurrentPhotoPath
);
Uri
contentUri
=
Uri
.
fromFile
(
f
);
mediaScanIntent
.
setData
(
contentUri
);
this
.
sendBroadcast
(
mediaScanIntent
);
String
path
=
f
.
getAbsolutePath
();
Log
.
e
(
""
,
path
);
Bitmap
galleryImage
=
getBitMapForPreview
(
path
,
previewWidth
,
previewHeight
);
previewImage
.
setImageBitmap
(
galleryImage
);
}
}
}
}
public
void
doOpenCvMagic
()
{
Task
.
forResult
(
""
).
continueWith
(
new
Continuation
<
String
,
Void
>()
{
@Override
public
Void
then
(
Task
<
String
>
task
)
throws
Exception
{
loading
=
ProgressDialog
.
show
(
MainActivity
.
this
,
"Matching"
,
"Wait while identifying the image..."
);
loading
.
setCancelable
(
false
);
loading
.
setProgressStyle
(
ProgressDialog
.
STYLE_SPINNER
);
return
null
;
}
},
Task
.
UI_THREAD_EXECUTOR
);
Mat
img1
=
Highgui
.
imread
(
mCurrentPhotoPath1
,
Highgui
.
CV_LOAD_IMAGE_GRAYSCALE
);
resizeMat
(
img1
);
Mat
img2
=
Highgui
.
imread
(
mCurrentPhotoPath2
,
Highgui
.
CV_LOAD_IMAGE_GRAYSCALE
);
resizeMat
(
img2
);
Mat
img3
=
Highgui
.
imread
(
mCurrentPhotoPath3
,
Highgui
.
CV_LOAD_IMAGE_GRAYSCALE
);
resizeMat
(
img3
);
FeatureDetector
detector
=
FeatureDetector
.
create
(
FeatureDetector
.
SIFT
);
MatOfKeyPoint
keypoints1
=
new
MatOfKeyPoint
();
MatOfKeyPoint
keypoints2
=
new
MatOfKeyPoint
();
MatOfKeyPoint
keypoints3
=
new
MatOfKeyPoint
();
detector
.
detect
(
img1
,
keypoints1
);
detector
.
detect
(
img2
,
keypoints2
);
detector
.
detect
(
img3
,
keypoints3
);
Mat
descriptors1
=
new
Mat
();
Mat
descriptors2
=
new
Mat
();
Mat
descriptors3
=
new
Mat
();
DescriptorExtractor
extractor
=
DescriptorExtractor
.
create
(
DescriptorExtractor
.
SIFT
);
extractor
.
compute
(
img1
,
keypoints1
,
descriptors1
);
extractor
.
compute
(
img2
,
keypoints2
,
descriptors2
);
extractor
.
compute
(
img3
,
keypoints3
,
descriptors3
);
DescriptorMatcher
matcher
=
DescriptorMatcher
.
create
(
DescriptorMatcher
.
BRUTEFORCE
);
final
Mat
outImg1
=
new
Mat
();
final
Mat
outImg2
=
new
Mat
();
final
Mat
outImg3
=
new
Mat
();
double
distance13
=
distanceFromData
(
matcher
,
keypoints3
,
descriptors3
,
keypoints1
,
descriptors1
);
double
distance23
=
distanceFromData
(
matcher
,
keypoints3
,
descriptors3
,
keypoints2
,
descriptors2
);
String
message
=
""
;
System
.
out
.
println
(
distance13
);
System
.
out
.
println
(
distance23
);
if
(
distance13
<
distance23
)
{
message
=
"It's more likely to be the subject 1"
;
}
else
if
(
distance23
<
distance13
)
{
message
=
"It's more likely to be the subject 2"
;
}
else
{
message
=
"Both subjects are equally likely"
;
}
Features2d
.
drawKeypoints
(
img1
,
keypoints1
,
outImg1
);
Features2d
.
drawKeypoints
(
img2
,
keypoints2
,
outImg2
);
Features2d
.
drawKeypoints
(
img3
,
keypoints3
,
outImg3
);
Task
.
forResult
(
message
).
continueWith
(
new
Continuation
<
String
,
Void
>()
{
@Override
public
Void
then
(
Task
<
String
>
task
)
throws
Exception
{
new
AlertDialog
.
Builder
(
MainActivity
.
this
)
.
setTitle
(
"Identification"
)
.
setMessage
(
task
.
getResult
())
.
setPositiveButton
(
android
.
R
.
string
.
ok
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
}
})
.
setIcon
(
android
.
R
.
drawable
.
ic_dialog_info
)
.
show
();
Bitmap
bitmap
=
Bitmap
.
createBitmap
(
outImg1
.
cols
(),
outImg1
.
rows
(),
Bitmap
.
Config
.
ARGB_8888
);
Utils
.
matToBitmap
(
outImg1
,
bitmap
);
previewImage1
.
setImageBitmap
(
bitmap
);
bitmap
=
Bitmap
.
createBitmap
(
outImg2
.
cols
(),
outImg2
.
rows
(),
Bitmap
.
Config
.
ARGB_8888
);
Utils
.
matToBitmap
(
outImg2
,
bitmap
);
previewImage2
.
setImageBitmap
(
bitmap
);
bitmap
=
Bitmap
.
createBitmap
(
outImg3
.
cols
(),
outImg3
.
rows
(),
Bitmap
.
Config
.
ARGB_8888
);
Utils
.
matToBitmap
(
outImg3
,
bitmap
);
previewImage3
.
setImageBitmap
(
bitmap
);
loading
.
dismiss
();
return
null
;
}
},
Task
.
UI_THREAD_EXECUTOR
);
}
// ------- Helper methods -------
public
void
resizeMat
(
Mat
image
)
{
final
double
kMaxWidth
=
160
;
final
double
kMaxHeight
=
120
;
if
(
image
.
width
()
<=
kMaxWidth
&&
image
.
height
()
<=
kMaxHeight
)
{
return
;
}
double
ratio
=
(
double
)
image
.
width
()
/
(
double
)
image
.
height
();
double
width
,
height
;
if
(
ratio
>
1
)
{
width
=
kMaxWidth
;
height
=
kMaxWidth
*
((
double
)
image
.
height
()/(
double
)
image
.
width
());
}
else
{
height
=
kMaxHeight
;
width
=
kMaxHeight
*
ratio
;
}
Imgproc
.
resize
(
image
,
image
,
new
Size
(
width
,
height
));
}
public
double
distanceFromData
(
DescriptorMatcher
matcher
,
MatOfKeyPoint
keypoints1
,
Mat
descriptors1
,
MatOfKeyPoint
keypoints2
,
Mat
descriptors2
)
{
MatOfDMatch
matches
=
new
MatOfDMatch
();
matcher
.
match
(
descriptors1
,
descriptors2
,
matches
);
DMatch
[]
aMatches
=
matches
.
toArray
();
double
distance
=
0
;
for
(
int
i
=
0
;
i
<
aMatches
.
length
;++
i
)
{
distance
+=
aMatches
[
i
].
distance
;
}
return
distance
;
}
private
File
createImageFile
()
throws
IOException
{
// Create an image file name
String
timeStamp
=
new
SimpleDateFormat
(
"yyyyMMdd_HHmmss"
).
format
(
new
Date
());
String
imageFileName
=
"JPEG_"
+
timeStamp
+
"_"
;
File
storageDir
=
Environment
.
getExternalStoragePublicDirectory
(
Environment
.
DIRECTORY_PICTURES
);
File
image
=
File
.
createTempFile
(
imageFileName
,
/* prefix */
".jpg"
,
/* suffix */
storageDir
/* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath
=
image
.
getAbsolutePath
();
return
image
;
}
private
Bitmap
getBitMapForPreview
(
String
path
,
int
width
,
int
height
)
{
BitmapFactory
.
Options
options
=
new
BitmapFactory
.
Options
();
// Just used to compute the sample size.
options
.
inJustDecodeBounds
=
true
;
BitmapFactory
.
decodeFile
(
path
,
options
);
options
.
inSampleSize
=
calculateInSampleSize
(
options
,
(
int
)
convertDpToPixel
((
float
)
width
,
this
),
(
int
)
convertDpToPixel
((
float
)
height
,
this
));
options
.
inJustDecodeBounds
=
false
;
Bitmap
galleryImage
=
BitmapFactory
.
decodeFile
(
path
,
options
);
return
galleryImage
;
}
/**
* This is used to decreases the image memory load, android is inefficient loading images
* and if you don't reduce the size accordingly to the resolution of the widget, it will have
* memory errors, it has to compute the pixels using the dpi of the screen and generate them
* according to the device screen density.
*
* @param options
* @param reqWidth width of the imageView
* @param reqHeight height of the imageView
* @return
*/
private
int
calculateInSampleSize
(
BitmapFactory
.
Options
options
,
int
reqWidth
,
int
reqHeight
)
{
// Raw height and width of image
final
int
height
=
options
.
outHeight
;
final
int
width
=
options
.
outWidth
;
int
inSampleSize
=
1
;
if
(
height
>
reqHeight
||
width
>
reqWidth
)
{
final
int
halfHeight
=
height
/
2
;
final
int
halfWidth
=
width
/
2
;
// Calculate the largest inSampleSize value that is a power of 2 and
// keeps both
// height and width larger than the requested height and width.
while
((
halfHeight
/
inSampleSize
)
>
reqHeight
&&
(
halfWidth
/
inSampleSize
)
>
reqWidth
)
{
inSampleSize
*=
2
;
}
}
return
inSampleSize
;
}
/**
* This method converts dp unit to equivalent pixels, depending on device density.
*
* @param dp A value in dp (density independent pixels) unit. Which we need to convert into pixels
* @param context Context to get resources and device specific display metrics
* @return A float value to represent px equivalent to dp depending on device density
*/
public
static
float
convertDpToPixel
(
float
dp
,
Context
context
){
Resources
resources
=
context
.
getResources
();
DisplayMetrics
metrics
=
resources
.
getDisplayMetrics
();
/**
* android developers equations:
* px = dp * (dpi / 160)
* dp = px / (dpi / 160)
*/
float
px
=
dp
*
(
metrics
.
densityDpi
/
160
f
);
return
px
;
}
}
app/src/main/res/layout/activity_main.xml
View file @
1993caeb
...
@@ -10,79 +10,6 @@
...
@@ -10,79 +10,6 @@
android:paddingBottom=
"@dimen/activity_vertical_margin"
tools:context=
".MainActivity"
android:paddingBottom=
"@dimen/activity_vertical_margin"
tools:context=
".MainActivity"
android:id=
"@+id/MainActivity"
>
android:id=
"@+id/MainActivity"
>
<Button
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Capture First ear"
android:id=
"@+id/button"
android:layout_marginTop=
"47dp"
android:layout_alignParentTop=
"true"
android:layout_alignParentLeft=
"true"
android:layout_alignParentStart=
"true"
android:layout_alignRight=
"@+id/button2"
android:layout_alignEnd=
"@+id/button2"
/>
<Button
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Capture Second ear"
android:id=
"@+id/button2"
android:layout_centerVertical=
"true"
android:layout_alignParentLeft=
"true"
android:layout_alignParentStart=
"true"
android:layout_below=
"@+id/imageView"
/>
<Button
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Capture ear to identify"
android:id=
"@+id/toidentify"
android:layout_centerVertical=
"true"
android:layout_alignParentLeft=
"true"
android:layout_alignParentStart=
"true"
android:layout_below=
"@+id/imageView2"
/>
<ImageView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:id=
"@+id/imageView"
android:layout_below=
"@+id/button"
android:layout_alignParentLeft=
"true"
android:layout_alignParentStart=
"true"
android:layout_alignRight=
"@+id/button"
android:layout_alignEnd=
"@+id/button"
android:maxHeight=
"150dp"
/>
<ImageView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:id=
"@+id/imageView2"
android:layout_below=
"@+id/button2"
android:layout_alignParentLeft=
"true"
android:layout_alignParentStart=
"true"
android:layout_alignRight=
"@+id/button2"
android:layout_alignEnd=
"@+id/button2"
android:maxHeight=
"150dp"
/>
<ImageView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:id=
"@+id/imageView3"
android:layout_below=
"@+id/toidentify"
android:layout_alignParentLeft=
"true"
android:layout_alignParentStart=
"true"
android:layout_alignRight=
"@+id/button2"
android:layout_alignEnd=
"@+id/button2"
android:maxHeight=
"150dp"
/>
<Button
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Identify"
android:id=
"@+id/button3"
android:layout_below=
"@+id/imageView3"
android:layout_alignParentLeft=
"true"
/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</ScrollView>
\ No newline at end of file
app/src/main/res/layout/open_commcare_layout.xml
0 → 100644
View file @
1993caeb
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:orientation=
"vertical"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<TextView
android:layout_width=
"266dp"
android:layout_height=
"wrap_content"
android:textAppearance=
"?android:attr/textAppearanceLarge"
android:text=
"Open Commcare to start"
android:id=
"@+id/textView2"
/>
</LinearLayout>
\ 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