Advertisement
Guest User

Untitled

a guest
Aug 24th, 2015
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. import android.graphics.Color;
  2. import android.nfc.Tag;
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.util.Log;
  6. import android.view.Menu;
  7. import android.view.View;
  8. import android.view.MenuItem;
  9. import android.view.SurfaceView;
  10. import android.hardware.camera2.CameraCaptureSession;
  11. import android.widget.EditText;
  12. import android.widget.TextView;
  13.  
  14. import org.opencv.android.BaseLoaderCallback;
  15. import org.opencv.android.CameraBridgeViewBase;
  16. import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
  17. import org.opencv.android.JavaCameraView;
  18. import org.opencv.android.LoaderCallbackInterface;
  19. import org.opencv.android.OpenCVLoader;
  20. import org.opencv.core.CvType;
  21. import org.opencv.core.Mat;
  22. import org.opencv.core.MatOfKeyPoint;
  23. import org.opencv.core.MatOfPoint;
  24. import org.opencv.imgproc.Imgproc;
  25. import org.opencv.highgui.Highgui;
  26.  
  27.  
  28. public class testActivity extends AppCompatActivity implements CvCameraViewListener2 {
  29.  
  30. private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
  31. @Override
  32. public void onManagerConnected(int status){
  33. switch (status){
  34. case LoaderCallbackInterface.SUCCESS:
  35. {
  36. mOpenCvCameraView.enableView();
  37. break;
  38. }
  39. default:
  40. {
  41. super.onManagerConnected(status);
  42. }
  43. }
  44. }
  45.  
  46. };
  47. private JavaCameraView mOpenCvCameraView;
  48. Mat grayMat;
  49. int testAmount;
  50. int grayVal;
  51. //EditText lagSquare = (EditText) findViewById(R.id.lagSquare);
  52. //TextView lagRating = (TextView) findViewById(R.id.lagRating);
  53. //TextView lagTime = (TextView) findViewById(R.id.lagTime);
  54. double[] timeArray = new double[500]; // set array
  55. double rating = 0;
  56. double lagStartTime;
  57. double lagEndTime;
  58. double lagTimeResult;
  59.  
  60. public void startTest (View view) {
  61. //test loop
  62. for (testAmount = 0; testAmount < 500; testAmount++) {//test loop

  63. lagStartTime = System.nanoTime(); //start lagTimer start
  64. //lagSquare.setBackgroundColor(Color.rgb(255, 255, 255));
  65. // lopp to test
  66. while (grayVal <= 100){
  67. Log.i("Mat Value", String.valueOf(grayVal));
  68. }
  69. //lagSquare.setBackgroundColor(Color.rgb(000,000,000)); //set lagSquare black
  70. lagEndTime = System.nanoTime(); //start lagTimer end
  71. lagTimeResult = (lagEndTime - lagStartTime);//stop lag timer

  72. timeArray[testAmount] = lagTimeResult;
  73. }
  74. //min scan
  75. }
  76.  
  77.  
  78. @Override
  79. protected void onCreate(Bundle savedInstanceState) {
  80. super.onCreate(savedInstanceState);
  81. setContentView(R.layout.activity_test);
  82.  
  83. mOpenCvCameraView = (JavaCameraView) findViewById(R.id.testVideoView);
  84. mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
  85. mOpenCvCameraView.setCvCameraViewListener(this);
  86. }
  87.  
  88. @Override
  89. public boolean onCreateOptionsMenu(Menu menu) {
  90. // Inflate the menu; this adds items to the action bar if it is present.
  91. //getMenuInflater().inflate(R.menu.menu_main, menu);
  92. return true;
  93. }
  94.  
  95. @Override
  96. public boolean onOptionsItemSelected(MenuItem item) {
  97. // Handle action bar item clicks here. The action bar will
  98. // automatically handle clicks on the Home/Up button, so long
  99. // as you specify a parent activity in AndroidManifest.xml.
  100. int id = item.getItemId();
  101. getSupportActionBar().hide();
  102.  
  103. //noinspection SimplifiableIfStatement
  104. if (id == R.id.action_settings) {
  105. return true;
  106. }
  107.  
  108. return super.onOptionsItemSelected(item);
  109. }
  110.  
  111.  
  112.  
  113. public void onDestroy() {
  114. super.onDestroy();
  115. if (mOpenCvCameraView != null)
  116. mOpenCvCameraView.disableView();
  117. }
  118.  
  119. public void onResume() {
  120. super.onResume();
  121. if (!OpenCVLoader.initDebug()) {
  122. OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, this, mLoaderCallback);
  123. } else {
  124. mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
  125. }
  126. }
  127.  
  128.  
  129.  
  130. @Override
  131. public void onPause() {
  132. super.onPause();
  133.  
  134. if (mOpenCvCameraView != null)
  135. mOpenCvCameraView.disableView();
  136. }
  137.  
  138. @Override
  139. public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
  140. grayMat = inputFrame.gray();
  141. double[] grayPixel = grayMat.get(1,1);
  142. grayVal = (int)grayPixel[0];
  143. return grayMat;
  144. }
  145.  
  146.  
  147. @Override
  148. public void onCameraViewStarted(int width, int height) {
  149.  
  150. }
  151. @Override
  152. public void onCameraViewStopped() {
  153. grayMat.release();
  154. }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement