OpenCV Feature Detectors

Feature detectors and describers are interesting topics in computer vision. People have found that detecting edges and corners in an image is useful for many different application, for instance, image matching, stitching, tracking etc. I was playing with the OpenCV image detectors today. This post is the outcome. Here I give the code and the performance of several feature detectors in my machine.

[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::Ptr<cv::FeatureDetector> detector = cv::FeatureDetector::create("FAST");

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]

Platform: Dimension of Input Video: 1920×1080, Windows 7, OpenCV 2.4.3, Lenovo Y650

Result:

Name FPS
FAST 12.4
STAR 7.00
ORB 7.58
MSER 1.125

Other features are not working correctly using this code.