Ask Your Question
5

Opencv android : display popup in onCameraFrame when glare is detected on image. [closed]

asked 2018-10-28 23:48:03 -0600

Akhil Patel gravatar image

updated 2019-12-10 01:05:13 -0600

i am new in OpenCV. I am developing an android application for detecting light or glare on image using OpenCV. i have used onCameraFrame for live preview but when live preview was started and glare or light is detect than popup was not displayed.

anyone know about how to display popup on onCameraFrame preview. please guide me.

edit retag flag offensive reopen merge delete

Closed for the following reason spam or advertising by mshabunin
close date 2019-04-04 06:52:51.855798

1 answer

Sort by ยป oldest newest most voted
6

answered 2018-12-04 04:05:58 -0600

droidcv gravatar image

updated 2018-12-04 04:09:14 -0600

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);
  }
edit flag offensive delete link more

Comments

1

can i use the above method in my class directly?

Akhil Patel gravatar imageAkhil Patel ( 2018-12-04 04:08:22 -0600 )edit
1

yes you can use directly in your class.

droidcv gravatar imagedroidcv ( 2018-12-04 04:09:54 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-10-28 23:48:03 -0600

Seen: 1,117 times

Last updated: Apr 02 '19