Search code examples
opencvcomputer-visionobject-detection

filtering out false positives of object detection with opencv


im using opencv's HaarDetectObjects(...) to detect an object in an image. The function returns the coordinates of areas in the image that might contain the object, the problem is i only want to detect a single instance of the object in the image and i have no way of knowing which of the results returned by the function is the "best". is there a way i could get the results sorted by their probability of actually containing the object ? or maybe define some sort of threshold the results must pass ? basically, i need a way of filtering out the false positives.

i am not restricted to using opencv or HaarDetectObjects, if anyone has a suggestion for another library or another object detection method, it is welcome.

thank you.


Solution

  • Is there any domain specific knowledge you can take advantage of?

    If the object is expected to be of a certain size or is most likely to be in certain position, you can define a very simple index that measures how far each detection is from being that size/position, so that would be your probability of a detection actually being the object.

    Is it expected to be of certain color? You can take the color histogram of a sample object. Then, you could compare each detection that HaarDetectObjects has returned to this sample histogram using a distance function (for the distance function, the names "Bhattacharyya distance" and "Mahalanobis distance" pop up in my mind, but I can't claim any expertise on this. OpenCv does have support for histograms, though, including a CompareHist function).

    Is there anything you can say about the object's contours, texture, geometry...? Anything that can be reduced to numbers and compared to a "ground value" can be of help.

    All of this, of course, is subject to processing constraints. Some of these suggestions might or might not be a bit expensive in terms of computation time. And this might or might not affect your application, depending of whether you have hardware or real time constraints.