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
5ec8178a
Commit
5ec8178a
authored
Sep 23, 2015
by
Josejulio Martínez Magaña
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Se termina la identificación de dos orejas.
parent
4c43ae5e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
137 additions
and
27 deletions
+137
-27
CameraActivity.java
.../main/java/com/aluxoft/earrecognition/CameraActivity.java
+112
-23
activity_camera.xml
app/src/main/res/layout/activity_camera.xml
+25
-4
No files found.
app/src/main/java/com/aluxoft/earrecognition/CameraActivity.java
View file @
5ec8178a
...
...
@@ -24,17 +24,23 @@ import android.widget.Button;
import
android.widget.ImageView
;
import
org.opencv.android.Utils
;
import
org.opencv.calib3d.Calib3d
;
import
org.opencv.core.Core
;
import
org.opencv.core.Mat
;
import
org.opencv.core.MatOfByte
;
import
org.opencv.core.MatOfDMatch
;
import
org.opencv.core.MatOfKeyPoint
;
import
org.opencv.core.MatOfPoint2f
;
import
org.opencv.core.Point
;
import
org.opencv.core.Scalar
;
import
org.opencv.core.Size
;
import
org.opencv.core.TermCriteria
;
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.features2d.KeyPoint
;
import
org.opencv.highgui.Highgui
;
import
org.opencv.imgproc.Imgproc
;
...
...
@@ -46,20 +52,35 @@ import java.util.Vector;
public
class
CameraActivity
extends
ActionBarActivity
{
String
image1
=
"/storage/emulated/0/DCIM/Camera/000_down_ear.jpg"
;
String
image2
=
"/storage/emulated/0/DCIM/Camera/001_front_ear.jpg"
;
String
image3
=
"/storage/emulated/0/DCIM/Camera/000_front_ear.jpg"
;
String
image4
=
"/storage/emulated/0/DCIM/Camera/test_1.png"
;
String
image5
=
"/storage/emulated/0/DCIM/Camera/test_3.png"
;
String
image6
=
"/storage/emulated/0/DCIM/Camera/test_2.png"
;
String
image_patty_01
=
"/storage/emulated/0/DCIM/Camera/PATTY_01.jpg"
;
String
image_patty_02
=
"/storage/emulated/0/DCIM/Camera/PATTY_02.jpg"
;
String
image_elena_01
=
"/storage/emulated/0/DCIM/Camera/ELENA_01.jpg"
;
String
image_elena_02
=
"/storage/emulated/0/DCIM/Camera/ELENA_02.jpg"
;
private
static
final
int
REQUEST_IMAGE_CAPTURE
=
1
;
private
static
final
int
SELECT_PICTURE
=
0
;
private
String
mCurrentPhotoPath
;
private
String
mCurrentPhotoPath1
;
private
String
mCurrentPhotoPath2
;
private
String
mCurrentPhotoPath1
=
null
;
//image_patty_02;
private
String
mCurrentPhotoPath2
=
null
;
//image_elena_01;
private
String
mCurrentPhotoPath3
=
null
;
//image_elena_02;
private
int
previewWidth
=
150
;
private
int
previewHeight
=
150
;
private
ImageView
previewImage1
;
private
ImageView
previewImage2
;
private
ImageView
previewImage3
;
private
ImageView
previewImage
;
public
void
resizeMat
ToVga
(
Mat
image
)
{
final
double
kMaxWidth
=
64
0
;
final
double
kMaxHeight
=
48
0
;
public
void
resizeMat
(
Mat
image
)
{
final
double
kMaxWidth
=
16
0
;
final
double
kMaxHeight
=
12
0
;
if
(
image
.
width
()
<=
kMaxWidth
&&
image
.
height
()
<=
kMaxHeight
)
{
return
;
...
...
@@ -69,7 +90,7 @@ public class CameraActivity extends ActionBarActivity {
double
width
,
height
;
if
(
ratio
>
1
)
{
width
=
kMaxWidth
;
height
=
kMaxWidth
*
(
image
.
height
()/
image
.
width
());
height
=
kMaxWidth
*
(
(
double
)
image
.
height
()/(
double
)
image
.
width
());
}
else
{
height
=
kMaxHeight
;
width
=
kMaxHeight
*
ratio
;
...
...
@@ -77,43 +98,95 @@ public class CameraActivity extends ActionBarActivity {
Imgproc
.
resize
(
image
,
image
,
new
Size
(
width
,
height
));
}
public
void
doOpenCvMagic
()
{
System
.
loadLibrary
(
"opencv_java"
);
System
.
loadLibrary
(
"nonfree"
);
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
;
}
public
void
doOpenCvMagic
()
{
Mat
img1
=
Highgui
.
imread
(
mCurrentPhotoPath1
,
Highgui
.
CV_LOAD_IMAGE_GRAYSCALE
);
Mat
img2
=
Highgui
.
imread
(
mCurrentPhotoPath2
,
Highgui
.
CV_LOAD_IMAGE_GRAYSCALE
);
resizeMat
(
img1
);
Mat
img2
=
Highgui
.
imread
(
mCurrentPhotoPath2
,
Highgui
.
CV_LOAD_IMAGE_GRAYSCALE
);
resizeMat
(
img2
);
resizeMatToVga
(
img1
);
resizeMat
ToVga
(
img2
);
Mat
img3
=
Highgui
.
imread
(
mCurrentPhotoPath3
,
Highgui
.
CV_LOAD_IMAGE_GRAYSCALE
);
resizeMat
(
img3
);
int
minHessian
=
400
;
FeatureDetector
detector
=
FeatureDetector
.
create
(
FeatureDetector
.
SURF
);
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
.
S
URF
);
DescriptorExtractor
extractor
=
DescriptorExtractor
.
create
(
DescriptorExtractor
.
S
IFT
);
extractor
.
compute
(
img1
,
keypoints1
,
descriptors1
);
extractor
.
compute
(
img2
,
keypoints2
,
descriptors2
);
extractor
.
compute
(
img3
,
keypoints3
,
descriptors3
);
MatOfDMatch
matches
=
new
MatOfDMatch
(
);
DescriptorMatcher
matcher
=
DescriptorMatcher
.
create
(
DescriptorMatcher
.
BRUTEFORCE
);
DescriptorMatcher
matcher
=
DescriptorMatcher
.
create
(
DescriptorMatcher
.
FLANNBASED
);
matcher
.
match
(
descriptors1
,
descriptors2
,
matches
);
Mat
outImg1
=
new
Mat
();
Mat
outImg2
=
new
Mat
();
Mat
outImg3
=
new
Mat
();
double
max_dist
=
0
;
double
min_dist
=
100
;
double
distance13
=
distanceFromData
(
matcher
,
keypoints3
,
descriptors3
,
keypoints1
,
descriptors1
)
;
double
distance23
=
distanceFromData
(
matcher
,
keypoints3
,
descriptors3
,
keypoints2
,
descriptors2
)
;
DMatch
[]
aMatches
=
matches
.
toArray
();
String
message
=
""
;
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"
;
}
new
AlertDialog
.
Builder
(
this
)
.
setTitle
(
"Identification"
)
.
setMessage
(
message
)
.
setPositiveButton
(
android
.
R
.
string
.
ok
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
}
})
.
setIcon
(
android
.
R
.
drawable
.
ic_dialog_info
)
.
show
();
Features2d
.
drawKeypoints
(
img1
,
keypoints1
,
outImg1
);
Features2d
.
drawKeypoints
(
img2
,
keypoints2
,
outImg2
);
Features2d
.
drawKeypoints
(
img3
,
keypoints3
,
outImg3
);
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
);
/*
for (int i=0;i<aMatches.length;++i) {
double dist = aMatches[i].distance;
...
...
@@ -140,16 +213,21 @@ public class CameraActivity extends ActionBarActivity {
Bitmap bitmap = Bitmap.createBitmap(image_matches.cols(), image_matches.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(image_matches, bitmap);
previewImage1
.
setImageBitmap
(
bitmap
);
previewImage1.setImageBitmap(bitmap);
*/
}
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
System
.
loadLibrary
(
"opencv_java"
);
System
.
loadLibrary
(
"nonfree"
);
setContentView
(
R
.
layout
.
activity_camera
);
previewImage1
=
(
ImageView
)
findViewById
(
R
.
id
.
imageView
);
previewImage2
=
(
ImageView
)
findViewById
(
R
.
id
.
imageView2
);
previewImage3
=
(
ImageView
)
findViewById
(
R
.
id
.
imageView3
);
final
Button
takeButton
=
(
Button
)
findViewById
(
R
.
id
.
button
);
takeButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
...
...
@@ -171,12 +249,22 @@ public class CameraActivity extends ActionBarActivity {
}
});
final
Button
toIdentifyButton
=
(
Button
)
findViewById
(
R
.
id
.
toidentify
);
toIdentifyButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
previewImage
=
previewImage3
;
takePhoto
(
takeButton
);
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
)
{
if
(
mCurrentPhotoPath1
!=
null
&&
mCurrentPhotoPath2
!=
null
&&
mCurrentPhotoPath3
!=
null
)
{
doOpenCvMagic
();
}
}
...
...
@@ -271,6 +359,7 @@ public class CameraActivity extends ActionBarActivity {
int
column_index
=
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
MediaColumns
.
DATA
);
if
(
cursor
.
moveToFirst
())
{
IMAGE_FILEPATH
=
cursor
.
getString
(
column_index
);
System
.
out
.
println
(
IMAGE_FILEPATH
);
Bitmap
galleryImage
=
getBitMapForPreview
(
IMAGE_FILEPATH
,
previewWidth
,
previewHeight
);
previewImage
.
setImageBitmap
(
galleryImage
);
}
...
...
app/src/main/res/layout/activity_camera.xml
View file @
5ec8178a
...
...
@@ -13,7 +13,7 @@
<Button
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Ca
rgar primera imagen
"
android:text=
"Ca
pture First ear
"
android:id=
"@+id/button"
android:layout_marginTop=
"47dp"
android:layout_alignParentTop=
"true"
...
...
@@ -25,13 +25,23 @@
<Button
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Ca
rgar segunda imagen
"
android:text=
"Ca
pture 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"
...
...
@@ -54,12 +64,23 @@
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=
"
Procesar
"
android:text=
"
Identify
"
android:id=
"@+id/button3"
android:layout_below=
"@+id/imageView
2
"
android:layout_below=
"@+id/imageView
3
"
android:layout_alignParentLeft=
"true"
/>
...
...
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