1

I use FlannBasedMatcher twice in my project, but it seems like the first FlannBasedMatcher is affecting the results of the second FlannBasedMatcher.

cvtColor(c_image1,hsi1,CV_BGR2HSV);
cvtColor(c_image2,hsi2,CV_BGR2HSV);
split(hsi1,channel_hsi1);
split(hsi2,channel_hsi2);
image1s=channel_hsi1[1];
image2s=channel_hsi2[1];
cvtColor(c_image1,image1,CV_RGB2GRAY);
cvtColor(c_image2,image2,CV_RGB2GRAY); 
SiftFeatureDetector detector(800);
SiftDescriptorExtractor extractor;
FlannBasedMatcher matcher;   

//first match

vector<KeyPoint>keypoint1,keypoint2;
detector.detect(image1,keypoint1);
detector.detect(image2,keypoint2);
Mat des1,des2;
extractor.compute(image1,keypoint1,des1);
extractor.compute(image2,keypoint2,des2);
vector<DMatch>matchpoints_i;
**matcher.match(des1,des2,matchpoints_i);//this line,if I delete it,the result of matchpoints_s will be right.But if I reserve it,the match condition of matchpoints_s will be bad,and even matchpoints_s[i].distance changed a lot.**
sort(matchpoints_i.begin(),matchpoints_i.end());

//second match

vector<KeyPoint>keypoint1s,keypoint2s;
detector.detect(image1s,keypoint1s);
detector.detect(image2s,keypoint2s);
Mat des1s,des2s;
extractor.compute(image1s,keypoint1s,des1s);
extractor.compute(image2s,keypoint2s,des2s);
vector<DMatch>matchpoints_s;
matcher.match(des1s,des2s,matchpoints_s);
sort(matchpoints_s.begin(),matchpoints_s.end());
for(size_t i=0;i<matchpoints_s.size();i++)
    { 
        cout<< matchpoints_s[i].distance<<endl;
   }

reserve the line,bad result

delete the line,good result

Is there a conflict when I use FlannBasedMatcher twice?

Eric Hauenstein
  • 2,557
  • 6
  • 31
  • 41

1 Answers1

0

Sure there should be no conflict. Make sure you check input - particurarly I am concerning that is good idea to pass S-channel of HSV image to detect features:

 image1s=channel_hsi1[1];
 image2s=channel_hsi2[1];

Probably H-channel would be better:

 image1s=channel_hsi1[0];
 image2s=channel_hsi2[0];

P.S. I have double checked my working code - and Yes, you have to call matcher.clear() right before you use it with other set of images.

Eugene Bartosh
  • 324
  • 3
  • 12
  • Thank you for your answer,but my project need to add the result of channel_hsi1[1] into channel_hsi1[0],(keypoints and match included) . I only wonder why if I delete the first match,the result of second match changed.Thank you ,my lord :) – user9148841 Dec 29 '17 at 05:24