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
aed65324
Commit
aed65324
authored
Oct 08, 2015
by
Josejulio Martínez Magaña
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed the algorithm to convert the features to a json string.
parent
03c4b6bd
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
29 deletions
+11
-29
EarIdentifier.java
...c/main/java/com/aluxoft/earrecognition/EarIdentifier.java
+11
-29
No files found.
app/src/main/java/com/aluxoft/earrecognition/EarIdentifier.java
View file @
aed65324
package
com
.
aluxoft
.
earrecognition
;
import
com.aluxoft.earrecognition.utils.OpenCvUtils
;
import
com.google.gson.Gson
;
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonSerializationContext
;
import
com.google.gson.JsonSerializer
;
import
org.opencv.core.Mat
;
import
org.opencv.core.MatOfKeyPoint
;
import
org.opencv.core.Size
;
import
org.opencv.features2d.DescriptorExtractor
;
import
org.opencv.features2d.FeatureDetector
;
import
org.opencv.highgui.Highgui
;
import
org.opencv.imgproc.Imgproc
;
import
java.lang.reflect.Type
;
import
java.util.Vector
;
import
java.util.ArrayList
;
/**
* Created by josejuliomartinez on 06/10/15.
...
...
@@ -50,14 +45,21 @@ public class EarIdentifier {
keypoints
=
new
MatOfKeyPoint
();
image
=
Highgui
.
imread
(
imagePath
,
Highgui
.
CV_LOAD_IMAGE_GRAYSCALE
);
OpenCvUtils
.
resizeMat
(
image
,
160
,
120
);
FeatureDetector
detector
=
FeatureDetector
.
create
(
FeatureDetector
.
SIFT
);
detector
.
detect
(
image
,
keypoints
);
DescriptorExtractor
extractor
=
DescriptorExtractor
.
create
(
DescriptorExtractor
.
SIFT
);
extractor
.
compute
(
image
,
keypoints
,
descriptors
);
Vector
<
Integer
>
features
=
new
Vector
<
Integer
>();
ArrayList
<
ArrayList
<
Integer
>>
features
=
new
ArrayList
<
>();
for
(
int
i
=
0
;
i
<
descriptors
.
rows
();++
i
)
{
features
.
add
((
int
)
descriptors
.
get
(
i
,
0
)[
0
]);
ArrayList
<
Integer
>
feature
=
new
ArrayList
<>();
for
(
int
j
=
0
;
j
<
descriptors
.
cols
();++
j
)
{
feature
.
add
((
int
)
descriptors
.
get
(
i
,
j
)[
0
]);
}
features
.
add
(
feature
);
}
Gson
gson
=
new
Gson
();
return
gson
.
toJson
(
features
);
...
...
@@ -68,24 +70,4 @@ public class EarIdentifier {
System
.
loadLibrary
(
"nonfree"
);
}
private
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
));
}
}
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