Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

try this. it will display popup on onCameraFrame.

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame)
{
    Mat imgSource = inputFrame.rgba();
    final Mat rgba = inputFrame.rgba();

    final Bitmap bitmap = Bitmap.createBitmap(rgba.cols(), rgba.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(rgba, bitmap, true);

    Mat grayScaleGaussianBlur = new Mat();
    Imgproc.cvtColor(rgba, grayScaleGaussianBlur, Imgproc.COLOR_BGR2GRAY);
    Imgproc.GaussianBlur(grayScaleGaussianBlur, grayScaleGaussianBlur, new Size(9, 9), 0);

    Core.MinMaxLocResult minMaxLocResultBlur = Core.minMaxLoc(grayScaleGaussianBlur);

    final double maxval = minMaxLocResultBlur.maxVal;
    final double minval = minMaxLocResultBlur.minVal;

    Log.i("min val", String.valueOf(minval));
    Log.i("max val", String.valueOf(maxval));


    if (maxval >= 253.0 && minval > 0.0 && minval < 20.0) 
    {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                try {
                    onShowPopupWindow(yourview);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

    } else {
        if (popup.isShowing())
        {
            runOnUiThread(new Runnable()
            {

                @Override
                public void run() {
                    popup.dismiss();
                    // Stuff that updates the UI
                }
            });

        }
     }
  }

 public void onShowPopupWindow(View v) {

    View layout = getLayoutInflater().inflate(R.layout.popup_window, null);
    PopupWindow popup=popup.setContentView(layout);
    // Set content width and height
    popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
    popup.setWidth(WindowManager.LayoutParams.MATCH_PARENT);
    // Closes the popup window when touch outside of it - when looses focus
    popup.setOutsideTouchable(true);
    popup.setFocusable(true);
    // Show anchored to button
    popup.setBackgroundDrawable(new BitmapDrawable());
    popup.showAsDropDown(v);
  }

try this. it will display popup on onCameraFrame.

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame)
{
    Mat imgSource = inputFrame.rgba();
    final Mat rgba = inputFrame.rgba();

    final Bitmap bitmap = Bitmap.createBitmap(rgba.cols(), rgba.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(rgba, bitmap, true);

    Mat grayScaleGaussianBlur = new Mat();
    Imgproc.cvtColor(rgba, grayScaleGaussianBlur, Imgproc.COLOR_BGR2GRAY);
    Imgproc.GaussianBlur(grayScaleGaussianBlur, grayScaleGaussianBlur, new Size(9, 9), 0);

    Core.MinMaxLocResult minMaxLocResultBlur = Core.minMaxLoc(grayScaleGaussianBlur);

    final double maxval = minMaxLocResultBlur.maxVal;
    final double minval = minMaxLocResultBlur.minVal;

    Log.i("min val", String.valueOf(minval));
    Log.i("max val", String.valueOf(maxval));


    if (maxval >= 253.0 && minval > 0.0 && minval < 20.0) 
    {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                try {
                    onShowPopupWindow(yourview);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

    } else {
        if (popup.isShowing())
        {
            runOnUiThread(new Runnable()
            {

                @Override
                public void run() {
                    popup.dismiss();
                    // Stuff that updates the UI
                }
            });

        }
     }
  }

 public void onShowPopupWindow(View v) {

    View layout = getLayoutInflater().inflate(R.layout.popup_window, null);
    PopupWindow popup=popup.setContentView(layout);
    // Set content width and height
    popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
    popup.setWidth(WindowManager.LayoutParams.MATCH_PARENT);
    // Closes the popup window when touch outside of it - when looses focus
    popup.setOutsideTouchable(true);
    popup.setFocusable(true);
    // Show anchored to button
    popup.setBackgroundDrawable(new BitmapDrawable());
    popup.showAsDropDown(v);
  }