Ask Your Question

nbun's profile - activity

2020-08-22 15:43:00 -0600 received badge  Student (source)
2015-09-06 00:53:44 -0600 received badge  Enthusiast
2015-09-05 16:10:39 -0600 commented question RGB Mat always over 100

Its the other way around, when my camera is far from screen the rgb are correct, but when its right up to it its more than 100 even if the screen is black.

2015-09-05 14:35:33 -0600 asked a question RGB Mat always over 100

I'm writing a program that test for display lag. I have a variables that tell me the rgb values of a pixel so I use System.nanotime with and an empty while loop that ends when the rgb variables reaches 100, combined with the subtraction of another System.nanotimeafter the loop to get the amount of time for a color to show up (second System.nanotime - first System.nanotime). I get the time in nanoseconds and divide it by 1,000,000 so I can get the time in milliseconds, the issue is that rgb is alway over 100 when i have it right up to the display, even when a white square is on the display. When I back the camera about a foot away the rgb seem normal. Is there a way to make the rgb values normal when it is close up to the display?

2015-08-31 09:50:18 -0600 asked a question param_id is not supported in this module using OpenCV

I am getting an error saying param_id is not supported in this module. The log makes me think that this relates to the native android camera function, but I am using the camera function built in opencv.

edit: my formatting looks correct on the preview screen, but not the final page. sorry if its looks wonky.

import android.graphics.Color;
import android.os.AsyncTask;
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.widget.TextView;
import android.hardware.camera2.CameraCaptureSession;

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.Mat;
import org.opencv.video.Video;

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;
    volatile double grayValGlobal;
    TextView lagSquare;
    TextView lagRating;
    TextView lagTime;
    public void startTest(View view) {
        new startTestAsync().execute(grayValGlobal);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        lagSquare = (TextView) findViewById(R.id.lagSquare);
        lagRating = (TextView) findViewById(R.id.lagRating);
        lagTime = (TextView) findViewById(R.id.lagTime);
        lagSquare.bringToFront();
        lagSquare.invalidate();
        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(100, 100);
        grayValGlobal = grayPixel[0];
        Log.i("Mat Value", String.valueOf(grayValGlobal));
        return grayMat;
    }


    @Override
    public void onCameraViewStarted(int width, int height) {

    }

    @Override
    public void onCameraViewStopped() {
        grayMat.release();
    }


    public class startTestAsync extends AsyncTask<Double, Void, Void> {
        long [] timeArray = new long[500]; // set array
        long rating;
        long lagStartTime;
        long lagEndTime;
        long lagTimeResult;

        long [] offsetTimeArray = new long[30];
        long offsetLagTimeResult;
        int testAmount;
        int cnt;
        int offSetAmount;

        long finalResult;

        @Override
        protected Void doInBackground(Double... grayVal) {
            runOnUiThread(new Runnable() {
                public void run() {
                    lagSquare.setBackgroundColor(Color.rgb(255, 255, 255));
                }
            });

            for (offSetAmount = 0; offSetAmount < 30; offSetAmount++);{
                lagStartTime = System.nanoTime(); //start lagTimer start
                while (grayValGlobal >= 100){
                    lagEndTime = System.nanoTime(); //start lagTimer end
                    offsetLagTimeResult = (lagEndTime - lagStartTime)/1000000;
                    offsetTimeArray[offSetAmount] = offsetLagTimeResult;
                }
                try {
                    Thread.sleep(50);
                } catch ...
(more)
2015-08-24 07:32:06 -0600 received badge  Editor (source)
2015-08-24 02:42:44 -0600 asked a question Sample and resample value for a loop

I need to sample a 1x1 Mat that is converted to an int. When I make a loop like this

while (grayVal <= 100){
            Log.i("Mat Value", String.valueOf(grayVal));                
        }

grayVal never changes, I know that I need to resample grayVal and pass it back into the loop. How would I go about doing this.

edit: here is my code http://pastebin.com/4HA9H39f

2015-08-22 16:27:10 -0600 commented question Compare value of a 1x1 Mat to an int

I want the loop run until grayVal get hits the right value

2015-08-22 04:41:07 -0600 commented question Compare value of a 1x1 Mat to an int

How would I take grayVal and sample it over and over again till it reaches the right int?

2015-08-21 23:44:12 -0600 received badge  Organizer (source)
2015-08-21 22:35:05 -0600 asked a question Compare value of a 1x1 Mat to an int

I want to compare a 1x1 Mat to an int to see if it passes a threshold. I do not know how to do this on android.

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    rgbMat = inputFrame.rgba();
    bgrPixel= rgbMat.submat(1,2,1,2).clone();
    grayPixel = new Mat();
    Imgproc.cvtColor(bgrPixel, grayPixel, Imgproc.COLOR_RGBA2GRAY, 1);
    return rgbMat;
}
2015-08-21 03:47:44 -0600 commented question Color recognition with OpenCV for Android

I got it to work thank you so much!!

2015-08-21 03:43:31 -0600 commented question Color recognition with OpenCV for Android

I got rid of if(rgbMat == null){ but am not getting the value of grayPixel.

2015-08-21 02:59:52 -0600 commented question Color recognition with OpenCV for Android

how would you suggest I fix this?

2015-08-20 22:53:54 -0600 asked a question Color recognition with OpenCV for Android

I am trying the make an app that recognizes it white is on screen. I have written code that take an RGBA mat and converts it to a one pixel gray mat. I am trying to see the value of the grayPixel so I know what to use when I make my loop. Everytime I put

Log.i("Mat Value", grayPixel.dump());

I get 90 no matter what I point the camera at. When I do

Log.i("Mat Value", grayPixel..toString());

I get the mat size of 1*1, which is correct, and the address of the camera.

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.MenuItem;
import android.view.SurfaceView;
import android.hardware.camera2.CameraCaptureSession;

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 bgrPixel;
Mat grayPixel;
Mat rgbMat;


@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) {
    if(rgbMat == null){
        rgbMat = inputFrame.rgba();
        bgrPixel= rgbMat.submat(1,2,1,2).clone();
        grayPixel = new Mat();
        Imgproc.cvtColor(bgrPixel, grayPixel, Imgproc.COLOR_RGBA2GRAY, 1);
    }

    rgbMat= inputFrame.rgba();

    Log.i("Mat Value", grayPixel.toString());
    return rgbMat;
}


@Override
public void onCameraViewStarted(int width, int height) {

}
@Override
public void onCameraViewStopped() {
    bgrPixel.release();
    grayPixel.release();
    rgbMat.release();
}


}