Ask Your Question

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

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() {
            public void run() {
                try {
                } catch (Exception e) {

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

                public void run() {
                    // 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
    // Closes the popup window when touch outside of it - when looses focus
    // Show anchored to button
    popup.setBackgroundDrawable(new BitmapDrawable());
edit flag offensive delete link more



can i use the above method in my class directly?

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

yes you can use directly in your class.

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

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



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


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

Seen: 78 times

Last updated: Dec 04