Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenCV: Comparing multiple images using ORB
    primarykey
    data
    text
    <p>I am trying to create a C++ program where there are a lot of images in a list compared to one input image. I got the whole thing working and the program is creating <code>DMatch</code> matches. </p> <p>Now I am trying to determine which of the list of images that is compared to the source image is the best match. I first tried to do this with just comparing how many matches there where between the images, but the problem is that when a generated image has a lot of key-points; they also tend to have a lot of matches, at least in my program.</p> <p>So how can I determine which of the array of images is the best match to the source image? I am using this loop to determine the matches but it doesn't really work:</p> <pre><code>vector&lt; vector&lt;DMatch&gt; &gt; filteredMatches; vector&lt;int&gt; goodIds; Ptr&lt;DescriptorMatcher&gt; matcher(new BFMatcher(NORM_HAMMING, false)); printf("bad matches: "); for(size_t i = 0; i &lt; images.size();i++){ vector&lt;DMatch&gt; matches, good_matches; matcher-&gt;clear(); matcher-&gt;match(images[i], tex_des, matches); if(matches.size() &lt; 8){ printf("F%d,", (int)i + 1); continue; } double min_dist = 100; for(size_t j = 0; j &lt; matches.size(); j++ ){ double dist = matches[j].distance; if( dist &lt; min_dist ) min_dist = dist; } if(min_dist &gt; 50.0){ printf("D%d,", (int)i + 1); continue; } double good_dist = min_dist * 3; for(size_t j = 0; j &lt; matches.size(); j++ ){ if(matches[j].distance &lt; good_dist) good_matches.push_back(matches[j]); } size_t size = good_matches.size(); if(size &lt; 8){ printf("M%d,", (int)i + 1); continue; } vector&lt;Point2f&gt; srcPoints(size); vector&lt;Point2f&gt; dstPoints(size); for(size_t j = 0; j &lt; size; j++){ srcPoints[j] = destination[good_matches[j].trainIdx].pt; dstPoints[j] = keyPoints[i][good_matches[j].queryIdx].pt; } vector&lt;unsigned char&gt; inliersMask(srcPoints.size()); Mat H = findHomography(srcPoints, dstPoints, CV_FM_RANSAC, 3.0, inliersMask); vector&lt;DMatch&gt; inliers; for(size_t j = 0; j &lt; inliersMask.size(); j++){ if(inliersMask[j]){ inliers.push_back(good_matches[j]); } } if(inliers.size() &lt; 4){ printf("S%d,", (int)i + 1); continue; } filteredMatches.push_back(inliers); goodIds.push_back((int)i); H.release(); } printf(" good matches: "); int best = -1; int amount = 0; for(size_t i = 0; i &lt; filteredMatches.size(); i++){ int size = (int)filteredMatches.at(i).size(); if(size &lt; 8) continue; printf("%d,", goodIds[i] + 1); if(amount &lt; size){ amount = size; best = i; } } if(best &gt;= 0) printf(" best match on image: %d, keypoints: %d, ", goodIds[best] + 1, amount); </code></pre> <p>If someone can point me to the functions or the logic I must use I would greatly appreciate it!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload