Adding a few settings to the camera driver for android.
This commit is contained in:
parent
f6974df279
commit
a08054126a
@ -1,6 +1,6 @@
|
||||
APP_BUILD_SCRIPT := $(call my-dir)/Android.mk
|
||||
APP_PROJECT_PATH := $(call my-dir)
|
||||
# The ARMv7 is significanly faster due to the use of the hardware FPU
|
||||
APP_ABI := armeabi armeabi-v7a
|
||||
APP_ABI := ${ARM_TARGETS}
|
||||
APP_MODULES := png jpeg jasper zlib opencv_lapack opencv_core opencv_imgproc opencv_ml opencv_highgui opencv_features2d \
|
||||
opencv_legacy opencv_objdetect opencv_calib3d opencv_video opencv_contrib opencv_flann
|
||||
|
@ -40,6 +40,13 @@ foreach(mdir ${module_includes})
|
||||
set(android_module_include_dirs "${android_module_include_dirs} ${n_f}/include")
|
||||
endforeach()
|
||||
|
||||
set(PossibleArmTargets
|
||||
"armeabi armeabi-v7a;armeabi;armeabi-v7a")
|
||||
set(ARM_TARGETS "armeabi armeabi-v7a" CACHE STRING "the arm targets for android, recommend armeabi-v7a for floating point support and neon")
|
||||
set_property(CACHE ARM_TARGETS PROPERTY STRINGS ${PossibleArmTargets} )
|
||||
|
||||
|
||||
|
||||
configure_file("${CMAKE_SOURCE_DIR}/Android.mk.master.in" "${CMAKE_BINARY_DIR}/Android.mk")
|
||||
configure_file("${CMAKE_SOURCE_DIR}/Application.mk.in" "${CMAKE_BINARY_DIR}/Application.mk")
|
||||
configure_file("${CMAKE_SOURCE_DIR}/AndroidManifest.xml.in" "${CMAKE_BINARY_DIR}/AndroidManifest.xml")
|
||||
|
@ -27,5 +27,17 @@
|
||||
android:prompt="@string/camera_mode_prompt" android:entries="@array/camera_mode">
|
||||
</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="@string/whitebalance_prompt" />
|
||||
<Spinner android:id="@+id/whitebalance" android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:saveEnabled="true"
|
||||
android:prompt="@string/whitebalance_prompt" android:entries="@array/whitebalance">
|
||||
</Spinner>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -17,4 +17,15 @@ Image Size:\n(may not be exact)
|
||||
<string name="camera_mode_prompt">
|
||||
Camera Mode:
|
||||
</string>
|
||||
|
||||
<string-array name="whitebalance">
|
||||
<item>auto</item>
|
||||
<item>incandescent</item>
|
||||
<item>fluorescent</item>
|
||||
<item>daylight</item>
|
||||
<item>cloudy-daylight</item>
|
||||
</string-array>
|
||||
<string name="whitebalance_prompt">
|
||||
Whitebalance:
|
||||
</string>
|
||||
</resources>
|
@ -19,6 +19,7 @@ public class CameraConfig extends Activity {
|
||||
public static final String IMAGE_HEIGHT = "IMAGE_HEIGHT";
|
||||
public static final int CAMERA_MODE_BW = 0;
|
||||
public static final int CAMERA_MODE_COLOR = 1;
|
||||
private static final String WHITEBALANCE = "WHITEBALANCE";
|
||||
|
||||
public static int readCameraMode(Context ctx) {
|
||||
// Restore preferences
|
||||
@ -27,6 +28,13 @@ public class CameraConfig extends Activity {
|
||||
int mode = settings.getInt(CAMERA_MODE, CAMERA_MODE_BW);
|
||||
return mode;
|
||||
}
|
||||
|
||||
public static String readWhitebalace(Context ctx) {
|
||||
// Restore preferences
|
||||
SharedPreferences settings = ctx.getSharedPreferences(CAMERA_SETTINGS,
|
||||
0);
|
||||
return settings.getString(WHITEBALANCE, "auto");
|
||||
}
|
||||
|
||||
static public void setCameraMode(Context context, String mode) {
|
||||
int m = 0;
|
||||
@ -92,11 +100,14 @@ public class CameraConfig extends Activity {
|
||||
|
||||
final Spinner size_spinner;
|
||||
final Spinner mode_spinner;
|
||||
final Spinner whitebalance_spinner;
|
||||
size_spinner = (Spinner) findViewById(R.id.image_size);
|
||||
mode_spinner = (Spinner) findViewById(R.id.camera_mode);
|
||||
whitebalance_spinner = (Spinner) findViewById(R.id.whitebalance);
|
||||
|
||||
String strsize = sizeToString(size);
|
||||
String strmode = modeToString(mode);
|
||||
String wbmode = readWhitebalace(getApplicationContext());
|
||||
|
||||
String sizes[] = getResources().getStringArray(R.array.image_sizes);
|
||||
|
||||
@ -118,6 +129,16 @@ public class CameraConfig extends Activity {
|
||||
}
|
||||
if(i <= modes.length)
|
||||
mode_spinner.setSelection(i-1);
|
||||
|
||||
i = 1;
|
||||
String wbmodes[] = getResources().getStringArray(R.array.whitebalance);
|
||||
for (String x :wbmodes) {
|
||||
if (x.equals(wbmode))
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
if(i <= wbmodes.length)
|
||||
whitebalance_spinner.setSelection(i-1);
|
||||
|
||||
size_spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||
|
||||
@ -150,7 +171,34 @@ public class CameraConfig extends Activity {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
whitebalance_spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> arg0, View spinner,
|
||||
int position, long arg3) {
|
||||
Object o = whitebalance_spinner.getItemAtPosition(position);
|
||||
if (o != null)
|
||||
setWhitebalance(spinner.getContext(), (String) o);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> arg0) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public static void setWhitebalance(Context ctx, String o) {
|
||||
SharedPreferences settings = ctx.getSharedPreferences(CAMERA_SETTINGS,
|
||||
0);
|
||||
Editor editor = settings.edit();
|
||||
editor.putString(WHITEBALANCE, o);
|
||||
editor.commit();
|
||||
|
||||
}
|
||||
|
||||
private String modeToString(int mode) {
|
||||
|
@ -23,6 +23,8 @@ import com.opencv.camera.NativeProcessor.PoolCallback;
|
||||
public class NativePreviewer extends SurfaceView implements
|
||||
SurfaceHolder.Callback, Camera.PreviewCallback, NativeProcessorCallback {
|
||||
|
||||
private String whitebalance_mode = "auto";
|
||||
|
||||
/** Constructor useful for defining a NativePreviewer in android layout xml
|
||||
*
|
||||
* @param context
|
||||
@ -94,6 +96,7 @@ public class NativePreviewer extends SurfaceView implements
|
||||
int mode = CameraConfig.readCameraMode(ctx);
|
||||
setPreviewSize(size[0], size[1]);
|
||||
setGrayscale(mode == CameraConfig.CAMERA_MODE_BW ? true : false);
|
||||
whitebalance_mode = CameraConfig.readWhitebalace(ctx);
|
||||
}
|
||||
|
||||
public void surfaceCreated(SurfaceHolder holder) {
|
||||
@ -135,8 +138,20 @@ public class NativePreviewer extends SurfaceView implements
|
||||
|
||||
Log.d("NativePreviewer", "Determined compatible preview size is: (" + preview_width + "," + preview_height+")");
|
||||
|
||||
Log.d("NativePreviewer","Supported params: " + mCamera.getParameters().flatten());
|
||||
|
||||
//this is available in 8+
|
||||
//parameters.setExposureCompensation(0);
|
||||
parameters.setWhiteBalance(whitebalance_mode);
|
||||
parameters.setAntibanding(Camera.Parameters.ANTIBANDING_OFF);
|
||||
|
||||
List<String> fmodes = mCamera.getParameters().getSupportedFocusModes();
|
||||
//for(String x: fmodes){
|
||||
|
||||
//}
|
||||
|
||||
if(parameters.get("meter-mode")!=null)
|
||||
parameters.set("meter-mode","meter-average");
|
||||
int idx = fmodes.indexOf(Camera.Parameters.FOCUS_MODE_INFINITY);
|
||||
if (idx != -1) {
|
||||
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY);
|
||||
@ -151,9 +166,10 @@ public class NativePreviewer extends SurfaceView implements
|
||||
List<String> scenemodes = mCamera.getParameters()
|
||||
.getSupportedSceneModes();
|
||||
if (scenemodes != null)
|
||||
if (scenemodes.indexOf(Camera.Parameters.SCENE_MODE_STEADYPHOTO) != -1) {
|
||||
if (scenemodes.indexOf(Camera.Parameters.SCENE_MODE_ACTION) != -1) {
|
||||
parameters
|
||||
.setSceneMode(Camera.Parameters.SCENE_MODE_STEADYPHOTO);
|
||||
.setSceneMode(Camera.Parameters.SCENE_MODE_ACTION);
|
||||
Log.d("NativePreviewer","set scenemode to action");
|
||||
}
|
||||
|
||||
parameters.setPreviewSize(preview_width, preview_height);
|
||||
|
Loading…
x
Reference in New Issue
Block a user