Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.graphics.Color;
- import android.nfc.Tag;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.Menu;
- import android.view.View;
- import android.view.MenuItem;
- import android.view.SurfaceView;
- import android.hardware.camera2.CameraCaptureSession;
- import android.widget.EditText;
- import android.widget.TextView;
- import org.opencv.android.BaseLoaderCallback;
- import org.opencv.android.CameraBridgeViewBase;
- import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
- import org.opencv.android.JavaCameraView;
- import org.opencv.android.LoaderCallbackInterface;
- import org.opencv.android.OpenCVLoader;
- import org.opencv.core.CvType;
- import org.opencv.core.Mat;
- import org.opencv.core.MatOfKeyPoint;
- import org.opencv.core.MatOfPoint;
- import org.opencv.imgproc.Imgproc;
- import org.opencv.highgui.Highgui;
- public class testActivity extends AppCompatActivity implements CvCameraViewListener2 {
- private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
- @Override
- public void onManagerConnected(int status){
- switch (status){
- case LoaderCallbackInterface.SUCCESS:
- {
- mOpenCvCameraView.enableView();
- break;
- }
- default:
- {
- super.onManagerConnected(status);
- }
- }
- }
- };
- private JavaCameraView mOpenCvCameraView;
- Mat grayMat;
- int testAmount;
- int grayVal;
- //EditText lagSquare = (EditText) findViewById(R.id.lagSquare);
- //TextView lagRating = (TextView) findViewById(R.id.lagRating);
- //TextView lagTime = (TextView) findViewById(R.id.lagTime);
- double[] timeArray = new double[500]; // set array
- double rating = 0;
- double lagStartTime;
- double lagEndTime;
- double lagTimeResult;
- public void startTest (View view) {
- //test loop
- for (testAmount = 0; testAmount < 500; testAmount++) {//test loop
- lagStartTime = System.nanoTime(); //start lagTimer start
- //lagSquare.setBackgroundColor(Color.rgb(255, 255, 255));
- // lopp to test
- while (grayVal <= 100){
- Log.i("Mat Value", String.valueOf(grayVal));
- }
- //lagSquare.setBackgroundColor(Color.rgb(000,000,000)); //set lagSquare black
- lagEndTime = System.nanoTime(); //start lagTimer end
- lagTimeResult = (lagEndTime - lagStartTime);//stop lag timer
- timeArray[testAmount] = lagTimeResult;
- }
- //min scan
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_test);
- mOpenCvCameraView = (JavaCameraView) findViewById(R.id.testVideoView);
- mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
- mOpenCvCameraView.setCvCameraViewListener(this);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- //getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- getSupportActionBar().hide();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- public void onDestroy() {
- super.onDestroy();
- if (mOpenCvCameraView != null)
- mOpenCvCameraView.disableView();
- }
- public void onResume() {
- super.onResume();
- if (!OpenCVLoader.initDebug()) {
- OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, this, mLoaderCallback);
- } else {
- mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
- }
- }
- @Override
- public void onPause() {
- super.onPause();
- if (mOpenCvCameraView != null)
- mOpenCvCameraView.disableView();
- }
- @Override
- public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
- grayMat = inputFrame.gray();
- double[] grayPixel = grayMat.get(1,1);
- grayVal = (int)grayPixel[0];
- return grayMat;
- }
- @Override
- public void onCameraViewStarted(int width, int height) {
- }
- @Override
- public void onCameraViewStopped() {
- grayMat.release();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement