PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/VideoEmulation/src/org/siprop/opencv/VideoEmulationConfiguration.java

http://github.com/billmccord/OpenCV-Android
Java | 130 lines | 80 code | 27 blank | 23 comment | 10 complexity | f17db0a46ff2c67ea0946c29c7754db9 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. /*
  2. * OpenCV for Android NDK
  3. * Copyright (c) 2006-2009 SIProp Project http://www.siprop.org/
  4. *
  5. * This software is provided 'as-is', without any express or implied warranty.
  6. * In no event will the authors be held liable for any damages arising from the use of this software.
  7. * Permission is granted to anyone to use this software for any purpose,
  8. * including commercial applications, and to alter it and redistribute it freely,
  9. * subject to the following restrictions:
  10. *
  11. * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  12. * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  13. * 3. This notice may not be removed or altered from any source distribution.
  14. *
  15. */
  16. package org.siprop.opencv;
  17. import android.app.Activity;
  18. import android.content.Intent;
  19. import android.os.Bundle;
  20. import android.util.Log;
  21. import android.view.View;
  22. import android.view.View.OnClickListener;
  23. import android.widget.Button;
  24. import android.widget.CheckBox;
  25. import android.widget.EditText;
  26. import android.widget.RadioButton;
  27. /**
  28. * Simple class for configuring which camera to use.
  29. *
  30. * @author Bill McCord
  31. */
  32. public final class VideoEmulationConfiguration extends Activity {
  33. public static final String EXTRA_IS_REMOTE_CAMERA = "IS_REMOTE_CAMERA";
  34. public static final String EXTRA_REMOTE_CAMERA_ADDRESS = "REMOTE_CAMERA_ADDRESS";
  35. public static final String EXTRA_REMOTE_CAMERA_PORT = "REMOTE_CAMERA_PORT";
  36. public static final String EXTRA_OPENCV_ACTION = "OPENCV_ACTION";
  37. public static final String EXTRA_CAMERA_OPTION = "CAMERA_OPTION";
  38. public static final String FIND_CONTOURS = "FIND_CONTOURS";
  39. public static final String TRACK_ALL_FACES = "TRACK_ALL_FACES";
  40. public static final String TRACK_SINGLE_FACE = "TRACK_SINGLE_FACE";
  41. public static final String C_SOCKET_CAMERA = "C_SOCKET_CAMERA";
  42. public static final String JAVA_SOCKET_CAMERA = "JAVA_SOCKET_CAMERA";
  43. private static final String DEFAULT_REMOTE_CAMERA = "192.168.0.102:9889";
  44. private static final String TAG = "VideoEmulationConfiguration";
  45. public void onCreate(Bundle bundle) {
  46. super.onCreate(bundle);
  47. // init Camera.
  48. setContentView(R.layout.config);
  49. Button restoreDefaultCameraButton = (Button)findViewById(R.id.ResotreDefaultCameraButton);
  50. restoreDefaultCameraButton.setOnClickListener(onRestoreDefaultCameraClick);
  51. Button doneButton = (Button)findViewById(R.id.DoneButton);
  52. doneButton.setOnClickListener(onDoneClick);
  53. }
  54. private OnClickListener onRestoreDefaultCameraClick = new OnClickListener() {
  55. public void onClick(View arg0) {
  56. ((EditText)findViewById(R.id.RemoteSourceEditText)).setText(DEFAULT_REMOTE_CAMERA);
  57. }
  58. };
  59. private OnClickListener onDoneClick = new OnClickListener() {
  60. public void onClick(View arg0) {
  61. boolean skipActivity = false;
  62. String address = null;
  63. String port = null;
  64. String remoteCameraStr = ((EditText)findViewById(R.id.RemoteSourceEditText)).getText()
  65. .toString();
  66. String[] remoteCameraStrArr = remoteCameraStr.split(":");
  67. if (remoteCameraStrArr.length == 2) {
  68. address = remoteCameraStrArr[0];
  69. port = remoteCameraStrArr[1];
  70. } else {
  71. skipActivity = true;
  72. }
  73. if (!skipActivity) {
  74. Intent invoker = new Intent();
  75. invoker.putExtra(EXTRA_REMOTE_CAMERA_ADDRESS, address);
  76. invoker.putExtra(EXTRA_REMOTE_CAMERA_PORT, port);
  77. RadioButton trackAllFacesRadioButton = (RadioButton)findViewById(R.id.TrackAllFacesRadioButton);
  78. RadioButton findContoursRadioButton = (RadioButton)findViewById(R.id.FindContoursRadioButton);
  79. if (trackAllFacesRadioButton.isChecked()) {
  80. Log.v(TAG, "Track All Faces");
  81. invoker.putExtra(EXTRA_OPENCV_ACTION, TRACK_ALL_FACES);
  82. } else if (findContoursRadioButton.isChecked()) {
  83. Log.v(TAG, "Find Contours");
  84. invoker.putExtra(EXTRA_OPENCV_ACTION, FIND_CONTOURS);
  85. } else {
  86. Log.v(TAG, "Track Single Face");
  87. invoker.putExtra(EXTRA_OPENCV_ACTION, TRACK_SINGLE_FACE);
  88. }
  89. CheckBox useCSocketCamera = (CheckBox)findViewById(R.id.UseCSocketCapture);
  90. if (useCSocketCamera.isChecked()) {
  91. invoker.putExtra(EXTRA_CAMERA_OPTION, C_SOCKET_CAMERA);
  92. } else {
  93. invoker.putExtra(EXTRA_CAMERA_OPTION, JAVA_SOCKET_CAMERA);
  94. }
  95. // Invoke the VideoEmulation activity after the camera
  96. // is successfully configured.
  97. invoker.setClass(getBaseContext(), VideoEmulation.class);
  98. startActivity(invoker);
  99. finish();
  100. }
  101. }
  102. };
  103. }