conforming the calibration sample to the new refactor of android-jni
This commit is contained in:
parent
3a932b0f6c
commit
d1d07c9a86
@ -16,14 +16,22 @@
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
<activity android:name=".ChessBoardChooser" android:label="@string/app_name"
|
||||
<!--
|
||||
These activities are defined in the android-jni library, and just reused here
|
||||
-->
|
||||
<activity android:name="com.opencv.calibration.ChessBoardChooser" android:label="@string/app_name"
|
||||
android:screenOrientation="landscape"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard">
|
||||
|
||||
</activity>
|
||||
|
||||
<activity android:name="com.opencv.camera.CameraConfig" android:label="@string/app_name"
|
||||
android:screenOrientation="landscape"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard">
|
||||
</activity>
|
||||
|
||||
<activity android:name="com.opencv.calibration.CalibrationViewer" android:label="@string/app_name"/>
|
||||
|
||||
<service android:name=".services.CalibrationService"></service>
|
||||
<service android:name="com.opencv.calibration.services.CalibrationService"></service>
|
||||
|
||||
</application>
|
||||
|
||||
|
10
android/apps/Calibration/README.txt
Normal file
10
android/apps/Calibration/README.txt
Normal file
@ -0,0 +1,10 @@
|
||||
to build completeley from command line:
|
||||
sh project_create.sh
|
||||
ant debug
|
||||
ant install
|
||||
|
||||
That assumes that you have already build the opencv/android/android-jni project
|
||||
|
||||
If you're in eclipse, try to create a new android project from existing sources.
|
||||
Make sure that you also have the android-jni project open in eclipse is this is the case
|
||||
or the android library dependency will give you errors.
|
@ -1,58 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:background="@drawable/cameraback">
|
||||
<!--<com.opencv.camera.NativePreviewer-->
|
||||
<!-- <SurfaceView -->
|
||||
|
||||
<com.opencv.camera.NativePreviewer
|
||||
|
||||
android:id="@+id/nativepreviewer"
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:opencv="http://schemas.android.com/apk/res/com.opencv"
|
||||
android:layout_width="fill_parent" android:layout_height="fill_parent"
|
||||
android:background="@drawable/cameraback">
|
||||
<!--<com.opencv.camera.NativePreviewer -->
|
||||
<!-- <SurfaceView -->
|
||||
|
||||
android:layout_width="400dip"
|
||||
android:layout_height="300dip"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_margin="20dip"
|
||||
android:gravity="center_horizontal|center_vertical"
|
||||
android:layout_marginRight="20dip"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:id="@+id/glview_layout"
|
||||
<com.opencv.camera.NativePreviewer
|
||||
android:id="@+id/nativepreviewer" android:layout_width="400dip"
|
||||
android:layout_height="300dip" android:layout_alignParentLeft="true"
|
||||
android:layout_margin="20dip" android:gravity="center_horizontal|center_vertical"
|
||||
android:layout_marginRight="20dip"
|
||||
/>
|
||||
<LinearLayout android:id="@+id/glview_layout"
|
||||
|
||||
android:layout_width="400dip"
|
||||
android:layout_height="300dip"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_margin="20dip"
|
||||
android:gravity="center_horizontal|center_vertical"
|
||||
android:layout_marginRight="20dip"
|
||||
>
|
||||
</LinearLayout>
|
||||
<LinearLayout android:layout_width="wrap_content"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
android:layout_margin="20dip"
|
||||
android:gravity="center_horizontal|center_vertical"
|
||||
android:layout_alignParentRight="true">
|
||||
android:layout_width="400dip" android:layout_height="300dip"
|
||||
android:layout_alignParentLeft="true" android:layout_margin="20dip"
|
||||
android:gravity="center_horizontal|center_vertical"
|
||||
android:layout_marginRight="20dip">
|
||||
</LinearLayout>
|
||||
<LinearLayout android:layout_width="wrap_content"
|
||||
android:layout_height="fill_parent" android:orientation="vertical"
|
||||
android:layout_margin="20dip" android:gravity="center_horizontal|center_vertical"
|
||||
android:layout_alignParentRight="true">
|
||||
|
||||
|
||||
<ImageButton android:src="@android:drawable/ic_menu_camera"
|
||||
android:id="@+id/capture" android:layout_width="60dip"
|
||||
android:layout_height="60dip"></ImageButton>
|
||||
<ImageButton android:src="@android:drawable/ic_menu_save"
|
||||
android:id="@+id/calibrate" android:layout_width="60dip"
|
||||
android:layout_height="60dip"></ImageButton>
|
||||
<TextView android:id="@+id/numberpatterns"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dip"
|
||||
android:background="@android:color/white"
|
||||
android:text="0"/>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageButton android:src="@android:drawable/ic_menu_camera"
|
||||
android:id="@+id/capture" android:layout_width="60dip"
|
||||
android:layout_height="60dip"></ImageButton>
|
||||
<ImageButton android:src="@android:drawable/ic_menu_save"
|
||||
android:id="@+id/calibrate" android:layout_width="60dip"
|
||||
android:layout_height="60dip"></ImageButton>
|
||||
<TextView android:id="@+id/numberpatterns"
|
||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||
android:padding="10dip" android:background="@android:color/white"
|
||||
android:text="0" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,40 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center_vertical|center_horizontal">
|
||||
<TextView android:text="@string/patterntext" android:autoLink="web" android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:padding="20dip"/>
|
||||
<LinearLayout android:id="@+id/LinearLayout01"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical">
|
||||
<TextView android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Corners in width direction:"/>
|
||||
<Spinner android:id="@+id/rows"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:saveEnabled="true"
|
||||
android:prompt="@string/chesspromptx"
|
||||
android:entries="@array/chesssizes">
|
||||
</Spinner>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout android:id="@+id/LinearLayout01"
|
||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical">
|
||||
<TextView android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:text="Corners in height direction:"/>
|
||||
<Spinner android:id="@+id/cols"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:saveEnabled="true"
|
||||
android:prompt="@string/chessprompty"
|
||||
android:entries="@array/chesssizes">
|
||||
</Spinner>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -1,17 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/patternsize" android:titleCondensed="Size"
|
||||
android:title="@string/patternsize"
|
||||
android:icon="@drawable/patternicon"
|
||||
></item>
|
||||
<item android:id="@+id/calibrate"
|
||||
android:titleCondensed="Calib"
|
||||
android:title="Calibrate"
|
||||
></item>
|
||||
<item android:id="@+id/help"
|
||||
android:titleCondensed="Help"
|
||||
android:title="Help"
|
||||
android:icon="@android:drawable/ic_menu_help"
|
||||
></item>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/calibrate" android:titleCondensed="Calib"
|
||||
android:title="Calibrate"></item>
|
||||
<item android:id="@+id/patternsize" android:titleCondensed="Size"
|
||||
android:title="@string/patternsize" android:icon="@drawable/patternicon"></item>
|
||||
|
||||
|
||||
<item android:id="@+id/settings" android:title="Settings" android:icon="@android:drawable/ic_menu_preferences"></item>
|
||||
<item android:id="@+id/help" android:title="Help" android:icon="@android:drawable/ic_menu_help"></item>
|
||||
</menu>
|
||||
|
@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="chesssizes">
|
||||
<item>3</item>
|
||||
<item>4</item>
|
||||
<item>5</item>
|
||||
<item>6</item>
|
||||
<item>7</item>
|
||||
<item>8</item>
|
||||
<item>9</item>
|
||||
<item>10</item>
|
||||
<item>11</item>
|
||||
<item>12</item>
|
||||
<item>13</item>
|
||||
</string-array>
|
||||
<string name="chesspromptx">
|
||||
Choose the width:</string>
|
||||
<string name="chessprompty">
|
||||
Choose the height:</string>
|
||||
</resources>
|
@ -1,24 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">Calibration</string>
|
||||
<string name="patternsize">Pattern Size</string>
|
||||
<string name="patterntext">Please choose the width and height (number of inside corners) of the checker
|
||||
board pattern you will be using for calibration. Default is 6 by 8 corners. You may find a checkerboard pattern at
|
||||
http://opencv.willowgarage.com/pattern</string>
|
||||
|
||||
<string name="patternlink">http://opencv.willowgarage.com/pattern</string>
|
||||
|
||||
<string name="calibfile">/opencv/camera.yml</string>
|
||||
<string name="calibfile">/opencv/camera.yml</string>
|
||||
<string name="sdcarddir">/opencv</string>
|
||||
|
||||
<string name="calibration_service_started">Calibration calculations have started...</string>
|
||||
<string name="calibration_service_stopped">Calibration calculations has stopped.</string>
|
||||
<string name="calibration_service_finished">Calibration finished, you camera is calibrated.</string>
|
||||
|
||||
<string name="calibration_service_label">Calibration</string>
|
||||
<string name="calibration_not_enough">Please capture atleast 3 - preferably greater than 10 - images of the pattern!</string>
|
||||
|
||||
|
||||
<string name="calibration_not_enough">Please capture atleast 10 images of the pattern!</string>
|
||||
<string name="sdcard_error_msg"> Please make sure that you\'re sdcard is not mounted to you\'re computer, and that you have an sdcard that is writable on your device.</string>
|
||||
|
||||
|
||||
</resources>
|
||||
|
@ -27,6 +27,7 @@ import android.widget.Toast;
|
||||
|
||||
import com.opencv.calibration.Calibrator.CalibrationCallback;
|
||||
import com.opencv.calibration.services.CalibrationService;
|
||||
import com.opencv.camera.CameraConfig;
|
||||
import com.opencv.camera.NativePreviewer;
|
||||
import com.opencv.camera.NativeProcessor;
|
||||
import com.opencv.misc.SDCardChecker;
|
||||
@ -112,6 +113,11 @@ public class Calibration extends Activity implements CalibrationCallback {
|
||||
case R.id.calibrate:
|
||||
calibrate();
|
||||
break;
|
||||
case R.id.settings:
|
||||
Intent configurer = new Intent(getApplicationContext(),
|
||||
CameraConfig.class);
|
||||
startActivity(configurer);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -152,7 +158,7 @@ public class Calibration extends Activity implements CalibrationCallback {
|
||||
Calibrator tcalib = calibrator;
|
||||
calibrator = new Calibrator(Calibration.this);
|
||||
setCallbackStack();
|
||||
calibservice.startCalibrating(tcalib, calibfile);
|
||||
calibservice.startCalibrating(Calibration.class, R.drawable.icon,tcalib, calibfile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -200,6 +206,8 @@ public class Calibration extends Activity implements CalibrationCallback {
|
||||
disableScreenTurnOff();
|
||||
setContentView(R.layout.camera);
|
||||
mPreview = (NativePreviewer) findViewById(R.id.nativepreviewer);
|
||||
mPreview.setPreviewSize(1000, 500);
|
||||
mPreview.setGrayscale(true);
|
||||
LinearLayout glview_layout = (LinearLayout) findViewById(R.id.glview_layout);
|
||||
glview = new GL2CameraViewer(getApplication(), false, 0, 0);
|
||||
glview_layout.addView(glview);
|
||||
@ -250,6 +258,12 @@ public class Calibration extends Activity implements CalibrationCallback {
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
int size[] ={0,0};
|
||||
CameraConfig.readImageSize(getApplicationContext(), size);
|
||||
int mode = CameraConfig.readCameraMode(getApplicationContext());
|
||||
mPreview.setPreviewSize(size[0], size[1]);
|
||||
mPreview.setGrayscale(mode == CameraConfig.CAMERA_MODE_BW ? true : false);
|
||||
|
||||
glview.onResume();
|
||||
mPreview.onResume();
|
||||
setCallbackStack();
|
||||
|
@ -1,74 +0,0 @@
|
||||
package com.opencv.calibration;
|
||||
|
||||
import com.opencv.jni.Size;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemSelectedListener;
|
||||
import android.widget.Spinner;
|
||||
|
||||
public class ChessBoardChooser extends Activity {
|
||||
public static final String CHESS_SIZE = "chess_size";
|
||||
public static final int DEFAULT_WIDTH = 6;
|
||||
public static final int DEFAULT_HEIGHT = 8;
|
||||
public static final int LOWEST = 3;
|
||||
|
||||
class DimChooser implements OnItemSelectedListener {
|
||||
private String dim;
|
||||
|
||||
public DimChooser(String dim) {
|
||||
this.dim = dim;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> arg0, View arg1, int pos,
|
||||
long arg3) {
|
||||
SharedPreferences settings = getSharedPreferences(CHESS_SIZE, 0);
|
||||
Editor editor = settings.edit();
|
||||
editor.putInt(dim, pos + LOWEST);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> arg0) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
// TODO Auto-generated method stub
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.chesssizer);
|
||||
// Restore preferences
|
||||
SharedPreferences settings = getSharedPreferences(CHESS_SIZE, 0);
|
||||
int width = settings.getInt("width", 6);
|
||||
|
||||
int height = settings.getInt("height", 8);
|
||||
|
||||
Spinner wspin, hspin;
|
||||
wspin = (Spinner) findViewById(R.id.rows);
|
||||
hspin = (Spinner) findViewById(R.id.cols);
|
||||
|
||||
wspin.setSelection(width - LOWEST);
|
||||
hspin.setSelection(height - LOWEST);
|
||||
|
||||
wspin.setOnItemSelectedListener(new DimChooser("width"));
|
||||
hspin.setOnItemSelectedListener(new DimChooser("height"));
|
||||
|
||||
}
|
||||
|
||||
public static Size getPatternSize(Context ctx) {
|
||||
SharedPreferences settings = ctx.getSharedPreferences(CHESS_SIZE, 0);
|
||||
int width = settings.getInt("width", 6);
|
||||
|
||||
int height = settings.getInt("height", 8);
|
||||
|
||||
return new Size(width, height);
|
||||
}
|
||||
|
||||
}
|
@ -1,151 +0,0 @@
|
||||
package com.opencv.calibration.services;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.opencv.calibration.Calibration;
|
||||
import com.opencv.calibration.Calibrator;
|
||||
import com.opencv.calibration.Calibrator.CalibrationCallback;
|
||||
import com.opencv.calibration.R;
|
||||
|
||||
public class CalibrationService extends Service implements CalibrationCallback {
|
||||
|
||||
public void startCalibrating(Calibrator calibrator, File calibration_file)
|
||||
throws IOException {
|
||||
calibrator.setCallback(this);
|
||||
calibrator.calibrate(calibration_file);
|
||||
}
|
||||
|
||||
private NotificationManager mNM;
|
||||
|
||||
/**
|
||||
* Class for clients to access. Because we know this service always runs in
|
||||
* the same process as its clients, we don't need to deal with IPC.
|
||||
*/
|
||||
public class CalibrationServiceBinder extends Binder {
|
||||
public CalibrationService getService() {
|
||||
return CalibrationService.this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.i("LocalService", "Received start id " + startId + ": " + intent);
|
||||
// We want this service to continue running until it is explicitly
|
||||
// stopped, so return sticky.
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
|
||||
// Display a notification about us starting. We put an icon in the
|
||||
// status bar.
|
||||
showNotification();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
// Cancel the persistent notification.
|
||||
// mNM.cancel(R.string.calibration_service_started);
|
||||
|
||||
// Tell the user we stopped.
|
||||
Toast.makeText(this, R.string.calibration_service_finished,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private final IBinder mBinder = new CalibrationServiceBinder();
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return mBinder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a notification while this service is running.
|
||||
*/
|
||||
private void showNotification() {
|
||||
// In this sample, we'll use the same text for the ticker and the
|
||||
// expanded notification
|
||||
CharSequence text = getText(R.string.calibration_service_started);
|
||||
|
||||
// Set the icon, scrolling text and timestamp
|
||||
Notification notification = new Notification(R.drawable.icon, text,
|
||||
System.currentTimeMillis());
|
||||
|
||||
// The PendingIntent to launch our activity if the user selects this
|
||||
// notification
|
||||
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
|
||||
new Intent(this, Calibration.class), 0);
|
||||
|
||||
// Set the info for the views that show in the notification panel.
|
||||
notification.setLatestEventInfo(this,
|
||||
getText(R.string.calibration_service_label), text,
|
||||
contentIntent);
|
||||
|
||||
notification.defaults |= Notification.DEFAULT_SOUND;
|
||||
// Send the notification.
|
||||
// We use a layout id because it is a unique number. We use it later to
|
||||
// cancel.
|
||||
mNM.notify(R.string.calibration_service_started, notification);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a notification while this service is running.
|
||||
*/
|
||||
private void doneNotification() {
|
||||
// In this sample, we'll use the same text for the ticker and the
|
||||
// expanded notification
|
||||
CharSequence text = getText(R.string.calibration_service_finished);
|
||||
|
||||
// Set the icon, scrolling text and timestamp
|
||||
Notification notification = new Notification(R.drawable.icon, text,
|
||||
System.currentTimeMillis());
|
||||
|
||||
// The PendingIntent to launch our activity if the user selects this
|
||||
// notification
|
||||
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
|
||||
new Intent(this, Calibration.class), 0);
|
||||
|
||||
// Set the info for the views that show in the notification panel.
|
||||
notification.setLatestEventInfo(this,
|
||||
getText(R.string.calibration_service_label), text,
|
||||
contentIntent);
|
||||
|
||||
notification.defaults |= Notification.DEFAULT_SOUND;
|
||||
// Send the notification.
|
||||
// We use a layout id because it is a unique number. We use it later to
|
||||
// cancel.
|
||||
mNM.notify(R.string.calibration_service_started, notification);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFoundChessboard(Calibrator calibrator) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDoneCalibration(Calibrator calibration, File calibfile) {
|
||||
doneNotification();
|
||||
stopSelf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailedChessboard(Calibrator calibrator) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user