First time here? Check out the FAQ!

Ask Your Question
5

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

asked Oct 29 '18

Akhil Patel gravatar image

updated Dec 10 '19

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.

Preview: (hide)

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 Dec 4 '18

droidcv gravatar image

updated Dec 4 '18

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);
  }
Preview: (hide)

Comments

1

can i use the above method in my class directly?

Akhil Patel gravatar imageAkhil Patel (Dec 4 '18)edit
1

yes you can use directly in your class.

droidcv gravatar imagedroidcv (Dec 4 '18)edit

Question Tools

1 follower

Stats

Asked: Oct 29 '18

Seen: 1,146 times

Last updated: Apr 02 '19