Ask Your Question
4

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

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

Akhil Patel gravatar image

updated 2018-12-04 03:54:20 -0500

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. please guide me.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
5

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

droidcv gravatar image

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

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 -0500 )edit
1

yes you can use directly in your class.

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

answered 2018-12-04 04:14:11 -0500

Akhil Patel gravatar image

Hello @droidcv i was used above method in my class but it will not work properly i mean sometime popup display when white background detected.

i want to display popup only when glare is detected.

edit flag offensive delete link more

Comments

1

you can change the maxval and minval value as per your need. this two variable values shows the white colored value so change this and check what the output comes.

droidcv gravatar imagedroidcv ( 2018-12-04 04:19:23 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 78 times

Last updated: Dec 04