Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

features2d usage issue (in mexopencv)

hello, i am using opencv in matlab through the library mexopencv. the creator of the library said that my issues should be asked directly to the creators of opencv so here i am and thanks in advance for your help. I am trying different algorithms for keypoints detection, description and matching. My problem is that the results are not satisfying even if i directly use the same procedure shown in your tutorial with the same image (bastoncini di pesce box). So here is the code i am using:

a = imread('scene.pgm');
b = imread('box.pgm');

detector = cv.FeatureDetector('SURF');
k1 = detector.detect(a);
k2 = detector.detect(b);

extractor = cv.DescriptorExtractor('SURF');
d1 = extractor.compute(a, k1);
d2 = extractor.compute(b, k2);

matcher = cv.DescriptorMatcher('FlannBased');
matches = matcher.match(d1, d2);

n = numel(matches);
maxDist = 0; minDist = Inf;
for i = 1:n
  if(matches(i).distance > maxDist) maxDist = matches(i).distance; end
  if(matches(i).distance < minDist) minDist = matches(i).distance; end
end

cont = 1;
i = 1;
while(i < n)
  if(matches(i).distance <= minDist*2)
    goodMatches(cont) = matches(i);
    cont = cont + 1;
  end
  i = i + 1;
end

n = numel(goodMatches);
for i=1:n
  srcPoints(1,i,1) = k1(goodMatches(i).queryIdx + 1).pt(1);
  srcPoints(1,i,2) = k1(goodMatches(i).queryIdx + 1).pt(2);
  dstPoints(1,i,1) = k2(goodMatches(i).trainIdx + 1).pt(1);
  dstPoints(1,i,2) = k2(goodMatches(i).trainIdx + 1).pt(2);
end

[H, ok] = cv.findHomography(srcPoints, dstPoints, 'Method', 'Ransac');

//project corners of image a in b
[h,l] = size(b);
p1 = H * [0; 0; 1];
p2 = H * [l; 0; 1];
p3 = H * [l; h; 1];
p4 = H * [0; h; 1];
x3 = [p1 p2 p3 p4];

inliers = [];
cont = 1;
for i = 1:numel(ok)
  if(ok(i) == 1)
    inliers(cont) = i;
    cont = cont + 1;
  end
end

for j = 1:numel(inliers)
  newMatches(j) = goodMatches(inliers(j));
end

imshow(cv.drawMatches(a, k1, b, k2, newMatches));

Then i plot the corners on b. Here are the results

using minDist*2 as threshold

corner points plotted on b

using minDist*3 as threshold

no threshold

features2d usage issue (in mexopencv)

hello, i am using opencv in matlab through the library mexopencv. the creator of the library said that my issues should be asked directly to the creators of opencv so here i am and thanks in advance for your help. I am trying different algorithms for keypoints detection, description and matching. My problem is that the results are not satisfying even if i directly use the same procedure shown in your tutorial with the same image (bastoncini di pesce box). So here is the code i am using:

a = imread('scene.pgm');
b = imread('box.pgm');

detector = cv.FeatureDetector('SURF');
k1 = detector.detect(a);
k2 = detector.detect(b);

extractor = cv.DescriptorExtractor('SURF');
d1 = extractor.compute(a, k1);
d2 = extractor.compute(b, k2);

matcher = cv.DescriptorMatcher('FlannBased');
matches = matcher.match(d1, d2);

n = numel(matches);
maxDist = 0; minDist = Inf;
for i = 1:n
  if(matches(i).distance > maxDist) maxDist = matches(i).distance; end
  if(matches(i).distance < minDist) minDist = matches(i).distance; end
end

cont = 1;
i = 1;
while(i < n)
  if(matches(i).distance <= minDist*2)
    goodMatches(cont) = matches(i);
    cont = cont + 1;
  end
  i = i + 1;
end

n = numel(goodMatches);
for i=1:n
  srcPoints(1,i,1) = k1(goodMatches(i).queryIdx + 1).pt(1);
  srcPoints(1,i,2) = k1(goodMatches(i).queryIdx + 1).pt(2);
  dstPoints(1,i,1) = k2(goodMatches(i).trainIdx + 1).pt(1);
  dstPoints(1,i,2) = k2(goodMatches(i).trainIdx + 1).pt(2);
end

[H, ok] = cv.findHomography(srcPoints, dstPoints, 'Method', 'Ransac');

//project corners of image a in b
[h,l] = size(b);
p1 = H * [0; 0; 1];
p2 = H * [l; 0; 1];
p3 = H * [l; h; 1];
p4 = H * [0; h; 1];
x3 = [p1 p2 p3 p4];

inliers = [];
cont = 1;
for i = 1:numel(ok)
  if(ok(i) == 1)
    inliers(cont) = i;
    cont = cont + 1;
  end
end

for j = 1:numel(inliers)
  newMatches(j) = goodMatches(inliers(j));
end

imshow(cv.drawMatches(a, k1, b, k2, newMatches));

Then i plot the corners on b. Here are the results

using minDist*2 as threshold

using minDist2 as threshold using minDist</em>2 as threshold

corner points plotted on b corner points plotted on b

using minDist*3 as threshold

using minDist3 as threshold using minDist</em>3 as threshold

no threshold no threshold

click to hide/show revision 3
No.3 Revision

features2d usage issue (in mexopencv)

hello, Hello, i am using opencv in matlab through the library mexopencv. the The creator of the library said that my issues should be asked directly to the creators of opencv so here i am and thanks in advance for your help.

I am trying different algorithms for keypoints detection, description and matching. My problem is that the results are not satisfying even if i directly use the same procedure shown in your tutorial with the same image (bastoncini di pesce box). So here is the code i am using:

a = imread('scene.pgm');
b = imread('box.pgm');

detector = cv.FeatureDetector('SURF');
k1 = detector.detect(a);
k2 = detector.detect(b);

extractor = cv.DescriptorExtractor('SURF');
d1 = extractor.compute(a, k1);
d2 = extractor.compute(b, k2);

matcher = cv.DescriptorMatcher('FlannBased');
matches = matcher.match(d1, d2);

n = numel(matches);
maxDist = 0; minDist = Inf;
for i = 1:n
  if(matches(i).distance > maxDist) maxDist = matches(i).distance; end
  if(matches(i).distance < minDist) minDist = matches(i).distance; end
end

cont = 1;
i = 1;
while(i < n)
  if(matches(i).distance <= minDist*2)
    goodMatches(cont) = matches(i);
    cont = cont + 1;
  end
  i = i + 1;
end

n = numel(goodMatches);
for i=1:n
  srcPoints(1,i,1) = k1(goodMatches(i).queryIdx + 1).pt(1);
  srcPoints(1,i,2) = k1(goodMatches(i).queryIdx + 1).pt(2);
  dstPoints(1,i,1) = k2(goodMatches(i).trainIdx + 1).pt(1);
  dstPoints(1,i,2) = k2(goodMatches(i).trainIdx + 1).pt(2);
end

[H, ok] = cv.findHomography(srcPoints, dstPoints, 'Method', 'Ransac');

//project corners of image a in b
[h,l] = size(b);
p1 = H * [0; 0; 1];
p2 = H * [l; 0; 1];
p3 = H * [l; h; 1];
p4 = H * [0; h; 1];
x3 = [p1 p2 p3 p4];

inliers = [];
cont = 1;
for i = 1:numel(ok)
  if(ok(i) == 1)
    inliers(cont) = i;
    cont = cont + 1;
  end
end

for j = 1:numel(inliers)
  newMatches(j) = goodMatches(inliers(j));
end

imshow(cv.drawMatches(a, k1, b, k2, newMatches));

Then i plot the corners on b. Here are the results

using minDist2 results:

  • Using minDist*2 as threshold using minDist</em>2 as threshold

    corner threshold:

using minDist*2 as threshold

  • Corner points plotted on b b:

corner points plotted on b

using minDist3

  • Using minDist*3 as threshold using minDist</em>3 as threshold

    no threshold threshold:

using minDist*3 as threshold

  • No threshold:

no threshold