Ask Your Question
0

Java BackgroundSubtractionMOG2: can I set fTau or nShadowDetection?

asked 2014-02-06 07:11:10 -0600

Will Stewart gravatar image

updated 2014-02-10 09:53:01 -0600

Is there a trick to setting fTau or nShadowDetection values in the Java version of BackgroundSubtractionMOG2? The default values are not giving good results (all too often the shadow gives much better contours in findContours() than does the person themselves).

Update: If there is no current means to access fTau or nShadowDetection via the Java binding, is it something I can add manually to the next version via pull request?

Current settings; new BackgroundSubtractorMOG2(2, 40, true);// I've tried lower values, such as (1, 16, true)

BSMOG2.apply(frameToExamine, fore, 0.5) // also tried 0.1

findContours(fore, contours, hierarchyMat, 1, 3)

I also erode and dilate before findContours.

Update: Added images to provide greater clarity of the problem

Contours (from findContours()) image description

Original image

image description

Silhouette

image description

edit retag flag offensive close merge delete

Comments

This is actually NOT solved, after all, see note below.

Will Stewart gravatar imageWill Stewart ( 2014-02-22 13:17:23 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-02-21 11:04:18 -0600

Will Stewart gravatar image

updated 2014-02-21 16:40:02 -0600

EDIT: NOT Solved!

Since BackgroundSubtraction2 inherits from Algorithm, we can get access to parameters via Algorithm's parameter setters and getters. In this case, both of the ones I want access to are double, so the Algorithm methods are;

double getDouble(java.lang.String name) 

void setDouble(java.lang.String name, double value)

So here is how it worked for me;

  BSMOG2 = new BackgroundSubtractorMOG2(2, 16, true);

  double x = BSMOG2.getDouble("fTau");

  System.out.println("BSMOG2.getDouble(fTau) = " + x);

  double yy = BSMOG2.getDouble("nShadowDetection");

  System.out.println("BSMOG2.getDouble(nShadowDetection) = " + yy);

and the output is;

*BSMOG2.getDouble(fTau) = 0.5

BSMOG2.getDouble(nShadowDetection) = 127.0*

to set the values, all it takes is;

BSMOG2.setDouble("fTau", 0.7);

EDIT: This executes without warning or complaint, but never really sets fTau, the value continues to be 0.5

And setDouble for nShadowDetection crashes with the following very odd statement;

OpenCV Error: Bad argument (Argument error: the setter method was called for the parameter 'nShadowDetection' of the algorithm 'BackgroundSubtractor.MOG2', the parameter has unsigned char type, so it should be set by integer, unsigned integer, uint64, unsigned char, boolean, float or double value, but the setter was called with double value) in set, file /home/will/opencv-2.4.8/modules/core/src/algorithm.cpp, line 654

On top of that, I tried other operations to see what they resulted in;

Paramtype for fTau is 7 Paramtype for nShadowDetection is 11

I can't figure out what these mean - does anyone know?

I also tried String paramhelpfTau = BSMOG2.paramHelp("fTau");

But that was null.

<sigh> Now I can't undo my checkmark for solving the problem.

Do I need to ask this question again?

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-02-06 07:11:10 -0600

Seen: 799 times

Last updated: Feb 21 '14