Use cv::saliency::ObjectnessBING

asked 2015-07-15 10:30:48 -0600

Caba gravatar image

Hi all,

I am trying to use the cv::saliency::ObjectnessBING class to detect object in a frame, but I am not able to do it properly. There is an example of code here but with the BING algorithm, it does not display any result.

This is my code:

    String saliency_algorithm = "BING";
    String training_path = "../ObjectnessTrainedModel";
    vector<Vec4i> saliencyMap;

    Ptr<Saliency> saliencyAlgorithm = Saliency::create( saliency_algorithm );
    saliencyAlgorithm.dynamicCast<cv::saliency::ObjectnessBING>()->setTrainingPath( training_path );
    //saliencyAlgorithm.dynamicCast<cv::saliency::ObjectnessBING>()->setBBResDir( training_path + "/Results" );

if( saliencyAlgorithm->computeSaliency( image, saliencyMap ) )
{
       std::cout << "Objectness done" << std::endl;
}

        std::vector<float> values = saliencyAlgorithm.dynamicCast<cv::saliency::ObjectnessBING>()->getobjectnessValues();

for (int i = 0; i < saliencyMap.size(); ++i)
 {
            cv::rectangle(image, Point (saliencyMap[i][0],saliencyMap[i][1]), Point(saliencyMap[i][2],saliencyMap[i][3]) , Scalar(255,0,0),1,8, 0);
}

 cv::namedWindow( "Saliency Map", WINDOW_AUTOSIZE );// Create a window for display.
 cv::imshow( "Saliency Map", image );                   // Show our image inside it.

 cv::waitKey(0);

So, saliencyMap is the vector containing all the rectangle, and my vector values contains the score of each reactangle. How can I use that information for drawing the result? I Tried to draw the rectangle with the highest score but the resutls made no sense. Have I to use some more options? There are more methods to use in the class but I don't understand what they are useful for, also reading the original paper of the algorithm.

edit retag flag offensive close merge delete

Comments

Have you try sample saliency with BING ? I have got an exception because some files are missing.

in ObjectnessBING::matRead at line 442 I think that something is missing like :

  if (!fs2.isOpened())
      return false;

and some files are missing which are in opencv_contrib/modules/saliency/samples/ObjectnessTrainedModel

As I don't know method it's diificult to say

There is some explanation from author here

LBerger gravatar imageLBerger ( 2015-07-15 11:43:53 -0600 )edit

Thanks for the link! I had misunderstood the BING algorithm exatcly as the person of that discussion. I am interesting in detect how many objects (whatever objects) there are in an image; so now I'm not sure I can use BING for that purpose (since the objects are novel obejcts, I should use use more object detection). But in the paper, the author got an image of a person and a ship detecting both, so, how did they do that? Using two different detectors and evaluating all the ROI given by the BING?

About the missing files, I don't know. I didn't try because I don't have a video to work with, so I just copied the interesting part of code to use the BING algorithm. With the code I posted it is working perfectly.

Caba gravatar imageCaba ( 2015-07-16 04:35:29 -0600 )edit

I tried running your code. I got

/home/raman/Work/obj_prop_3D/main.cpp:205: error: undefined reference to `cv::saliency::Saliency::create(cv::String const&)'

any idea why this is happening?

Raman gravatar imageRaman ( 2016-06-20 22:54:43 -0600 )edit