Life is a game, take it seriously

Archive for May, 2011|Monthly archive page

SURFmex bugs

In Computer Vision, Matlab on May 8, 2011 at 9:46 am

written by Gooly

Continuing the last post, I have to mention some bugs in SURFmex that needed to be noticed.

First, be aware of the orientation the SURFPOINTS function give back. It is in a counter clockwise direction, however if you try to plot on Matlab, the column row axis is in the clockwise direction; it is easy to get confused and have the wrong direction. Actually this is one of the mistakes in the surfplot function given by SURFmex under the common folder. Another bug is the degree to radian problem, be aware that the SURFPOINTS function gives the orientation in degree; the surfplot function uses it assuming it is radian instead. Change the surfplot function as follows to correct the bugs.

function surfplot(points,info)

    colorline= {'r-','b-','c-','g-','m-'};
    phi = linspace(0,2*pi);
    x = cos(pi/2 + phi);
    y = sin(pi/2 + phi);
    bbox = [x 0; y 0];

    for k = 1:size(points,2)
        scale = info(1,k);
        ori   = -info(3,k)*pi/180;

        R = [cos(ori) -sin(ori);sin(ori) cos(ori)];

        pbox = scale*R*bbox + points(:,k)*ones(1,size(bbox,2));
        hold on;
        plot(pbox(1,:),pbox(2,:),colorline{mod(k,5)+1});
    end
end

Another bug is an OpenCV bug, an error would occur if you input a pretty flat image which it couldn’t find any interest points. A work around of this is to check if it’s a flat image before calling SURFPOINTS, since if it’s a flat image, you probably wouldn’t want to match it; or you can do a histogram equalization before calling SURFPOINTS, this would solve the problem.

SURF On Images: continue

In Computer Vision, Matlab on May 7, 2011 at 11:43 pm

written by Gooly


Continuing the last post, I will show how to actually work on SURF points using MATLAB. First download the SURFmex library; this is a second version released in 2008, which is simply a wrapper around the OpenCV dll. The good thing about OpenCV is that it’s open source and actively used, so you won’t get stuck in a dll which couldn’t move to another OS. Note that you have to fix the surfplot function bug in the common folder, see this explanation. Next, put the library in the project folder and remember to right click on it and add to path. Now, put 2 images, in my case img1.png and img2.png, in the same folder. Next step, download a small function I wrote to show the matching result like the image above from here (or search match_plot on Matlab Central); put the function in the same folder. Finally, add the following code and run.

function match_test()

close all;
clear;

% surfnum = 1:30;

left_img  = imread('./img1.png');
right_img = imread('./img2.png');

[spixels_l,descr_l,sign_l,info_l] = SurfPoints(rgb2gray(left_img));

figure;
imshow(left_img);
hold on;
plot(spixels_l(1,:),spixels_l(2,:),'r*'); hold on

[spixels_r,descr_r,sign_r,info_r] = SurfPoints(rgb2gray(right_img));

figure;
imshow(right_img);
hold on;
plot(spixels_r(1,:),spixels_r(2,:),'r*'); hold on

matches = surfmatch(descr_l,descr_r);

surfnum = randi(size(matches,2),1,30);

match_plot(left_img,right_img,spixels_l(:,matches(1,surfnum))',spixels_r(:,matches(2,surfnum))');

figure;
imshow(left_img);
hold on;
surfplot(spixels_l(:,matches(1,surfnum)),info_l(:,matches(1,surfnum)));

figure;
imshow(right_img);
hold on;
surfplot(spixels_r(:,matches(2,surfnum)),info_r(:,matches(2,surfnum)));

end

You will get 2 image which have all of the SURF points marked, and an image like the one above which matches 30 random SURF points, and 2 images showing the orientation and size of the SURF points like the image below.

On the next post, I’ll show how to do simple object recognition using SURF points. By the way, if you work on stereo vision, these images must look familiar; for those who don’t know, search for middlebury