OpenCV Feature Detector – 2

Here is another way to use the feature detectors. Instead of using the general FeatureDetector interface, here each feature-detector class is called individually and the associated functions are called.

[code lang=”cpp”]

int main(int argc, char* argv[]){
cv::VideoCapture cam("D:/Pictures/20120811_140513.mp4");
cv::Mat frames;
cv::Mat grayIm;
double FPS=0.;
double FPS_sum = 0.;
int FPS_count = 0;
long prevTick = 0;
int count = 0;
char str[256] ={‘\0’};

std::vector<cv::KeyPoint> keyp;

if(!cam.isOpened())
return -1;

cam>>frames;
grayIm.create(frames.rows,frames.cols,frames.type());

cv::SURF detector;

while(cv::waitKey(1)!=27){
cam>>frames;
cv::resize(frames,frames,cv::Size(),0.5,0.5);
cv::cvtColor(frames,grayIm,CV_RGB2GRAY);

detector.detect(grayIm,keyp);

for(int i=0;i<keyp.size();i++)
cv::circle(frames,cv::Point(keyp[i].pt.x,keyp[i].pt.y),2,cv::Scalar(255,0,0,255));

if(count==0){
int currenttick = cv::getTickCount();
FPS = cv::getTickFrequency()/(currenttick – prevTick)*30;
if(FPS_count!=0) FPS_sum += FPS;
FPS_count++;
prevTick = cv::getTickCount();
}
count = ++count % 30;

sprintf(str,"FPS = %0.2f\0",FPS);
cv::putText(frames,str,cv::Point(20,50),CV_FONT_HERSHEY_SIMPLEX,1,cv::Scalar(255,0,255,0));

cv::imshow("Camera",frames);
cout<<"Average FPS = "<<FPS_sum/(FPS_count-1)<<std::endl;
}
return 0;
}

[/code]

Input and platform: same as the previous one

Results:

Name FPS
FREAK 31.6729 – Does Not Track Anything
GFTTDetector Extremely slow – one frame takes about a minute
MSER 1.299
SIFT (in Nonfree Module) 1.637
SURF (in Nonfree Module) 0.981