0

I am working with OpenCV4Android version 3.0.0 and I am trying to remove background from video stream "non-static background". i want to do so because i have a problem when i try to detect the edges of a "card", the problem of detecting the edges of a "card" is based on its color and the background color as explained in my question here.

after referring to some posts i wrote the below code, but at run time, when i display the "mask" image i get a completely grey image. and when i display the "output" image after applying the "mask" on it i get the same preview being displayed on the camera

is there any way to remove the non-static background from video stream?

code:

    mask = new Mat();
    BackgroundSubtractorMOG2 mog2 = Video.createBackgroundSubtractorMOG2();
    mog2.apply(mInputFrame,mask,.000005);

    output = new Mat();
    mInputFrame.copyTo(output, mask);
    final Bitmap bitmap = Bitmap.createBitmap(mInputFrame.cols(), mInputFrame.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(output, bitmap);
    getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mIVEdges.setImageBitmap(bitmap);
        }
    });
Community
  • 1
  • 1
Amrmsmb
  • 1
  • 27
  • 104
  • 226
  • 1
    In theory yes, but it will be **a lot** of pain. You'd better _detect_ (and eventually _track_) your object of interest – Miki Oct 18 '16 at 09:25
  • Agree with Miki, as alternative you need to train segmentation network like this (like this: http://mi.eng.cam.ac.uk/projects/segnet/ or http://www.robots.ox.ac.uk/~szheng/crfasrnndemo ) which is not a trivial problem. – Andrey Smorodov Oct 18 '16 at 10:05
  • And actually "detecting background" sounds as: "segment all objects". Much more reasonable solution is to detect the only object you need. – Andrey Smorodov Oct 18 '16 at 10:11
  • @AndreySmorodov please have a look at the link posted above in my question, i mean the link that contain my previous question on Stackoverflow.i can detect only the object i need but the problem is the detection of the object varies according to the background color..that's why i wanted to eliminate the background..do u have any solution for that? – Amrmsmb Oct 18 '16 at 10:19
  • @Miki please have a look at my comment to AndreySmorodov – Amrmsmb Oct 18 '16 at 10:20

0 Answers0