adds activitys for loading the image and computing the sift features.

Adds the gson library for json serializing.

bug:
The image can't be opened from the other activity.
parent f4823f59
......@@ -5,6 +5,4 @@
.DS_Store
/build
/captures
*.iml
*.gradle
/.idea
.iml
......@@ -19,9 +19,14 @@ android {
}
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.0'
compile project(':openCVLibrary2411')
compile 'com.parse.bolts:bolts-android:1.2.1'
compile 'com.google.code.gson:gson:2.3'
}
......@@ -32,7 +32,7 @@
</intent-filter>
</activity> -->
<activity
android:name=".IntentCalloutTest"
android:name=".ActivityEarCapture"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
......@@ -48,6 +48,20 @@
</intent-filter>
</activity>
<activity android:name=".SelectUserActivity">
<intent-filter>
<action android:name="com.auriclon.activity_select_user"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".SIFTActivity">
<intent-filter>
<action android:name="com.auriclon.activity_sift"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
......@@ -9,13 +9,16 @@ import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class IntentCalloutTest extends Activity {
public class ActivityEarCapture extends Activity {
Button getImage;
Button returnToCommCare;
......@@ -32,8 +35,26 @@ public class IntentCalloutTest extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_callout);
/*
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);
ActivityEarCapture.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) + "|");
......@@ -47,29 +68,13 @@ public class IntentCalloutTest extends Activity {
System.out.println();
}
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);
IntentCalloutTest.this.startActivity(i);
}
});
getImage = (Button)this.findViewById(R.id.extra_image_value);
getImage.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
try {
location = File.createTempFile("image" + System.currentTimeMillis(), ".jpg");
} catch (IOException e1) {
......@@ -84,14 +89,14 @@ public class IntentCalloutTest extends Activity {
try {
startActivityForResult(i, KEY_REQUEST_IMAGE);
} catch (ActivityNotFoundException e) {
Toast.makeText(IntentCalloutTest.this, "No Camera", Toast.LENGTH_SHORT).show();
Toast.makeText(ActivityEarCapture.this, "No Camera", Toast.LENGTH_SHORT).show();
}
}
});
if(this.getLastNonConfigurationInstance() != null) {
location = ((IntentCalloutTest)this.getLastNonConfigurationInstance()).location;
location = ((ActivityEarCapture)this.getLastNonConfigurationInstance()).location;
}
if(savedInstanceState != null) {
......@@ -108,6 +113,33 @@ public class IntentCalloutTest extends Activity {
//Go grab the image and set it's location
if(location == null || !location.exists()) {
location = null;
} else {
Intent intent = new Intent("com.auriclon.activity_sift");
File file = new File(location.getAbsolutePath() + ".jpg");
InputStream input = null;
OutputStream output = null;
try {
input = new FileInputStream(location);
output = new FileOutputStream(file);
byte[] buf = new byte[1024];
int bytesread;
while ((bytesread = input.read(buf)) > 0) {
output.write(buf, 0, bytesread);
}
} catch(IOException e) {
e.printStackTrace();
} finally {
try {
input.close();
output.close();
} catch(Exception e) {
e.printStackTrace();
}
}
intent.putExtra("image_path", file);
startActivity(intent);
}
}
}
......
package com.aluxoft.earrecognition;
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;
/**
* Created by josejuliomartinez on 06/10/15.
*/
......@@ -24,9 +40,52 @@ public class EarIdentifier {
return null;
}
public String computeFeatures(String imagePath) {
Mat image, descriptors;
MatOfKeyPoint keypoints;
descriptors = new Mat();
keypoints = new MatOfKeyPoint();
image = Highgui.imread(imagePath, Highgui.CV_LOAD_IMAGE_GRAYSCALE);
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>();
for (int i=0;i<descriptors.rows();++i) {
features.add((int)descriptors.get(i, 0)[0]);
}
Gson gson = new Gson();
return gson.toJson(features);
}
static {
System.loadLibrary("opencv_java");
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));
}
}
package com.aluxoft.earrecognition;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import java.io.File;
import java.util.concurrent.Callable;
import bolts.Continuation;
import bolts.Task;
/**
* Created by josejuliomartinez on 07/10/15.
*/
public class SIFTActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sift);
ProgressDialog loading = ProgressDialog.show(SIFTActivity.this,
"Searching matches", "Please wait while we search for matches...");
loading.setCancelable(false);
loading.setProgressStyle(ProgressDialog.STYLE_SPINNER);
Task.callInBackground(new Callable<Object>() {
@Override
public Object call() throws Exception {
synchronized (this) {
// Sift
EarIdentifier identifier = new EarIdentifier(null);
Intent intent = SIFTActivity.this.getIntent();
Bundle extras = intent.getExtras();
File imagePath = (File)extras.get("image_path");
String features = identifier.computeFeatures(imagePath.getAbsolutePath());
System.out.println(features);
}
return null;
}
}).continueWith(new Continuation<Object, Object>() {
@Override
public Object then(Task<Object> task) throws Exception {
Intent intent = new Intent("com.auriclon.activity_select_user");
startActivity(intent);
return null;
}
}, Task.UI_THREAD_EXECUTOR);
}
}
package com.aluxoft.earrecognition;
import android.app.Activity;
import android.os.Bundle;
/**
* Created by josejuliomartinez on 07/10/15.
*/
public class SelectUserActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_user);
}
}
......@@ -9,21 +9,5 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Grab an Image!" />
<TextView
android:id="@+id/image_location"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="No Current Image" />
<Button
android:id="@+id/button_commcare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open CommCare" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView4"
android:layout_gravity="center_horizontal"
android:maxHeight="300dp"
android:maxWidth="300dp"
android:minHeight="100dp"
android:minWidth="100dp"
android:nestedScrollingEnabled="true" />
<ListView
android:layout_width="match_parent"
android:layout_height="453dp"
android:id="@+id/listView"
android:layout_gravity="center_horizontal"
android:choiceMode="singleChoice" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register to Commcare"
android:id="@+id/register_commcare"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</ScrollView>
\ No newline at end of file
<?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">
</LinearLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment