SURF特征点提取

#include "stdafx.h"
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/nonfree/features2d.hpp>

using namespace cv;
using namespace std; 
  
int main(int argc, char *argv[]) 
{ 
  // (1)load Color Image 
  const char *imagename = argc > 1 ? argv[1] : "../image/lena.png"; 
  Mat colorImage = imread(imagename,1); 
  if(colorImage.empty()) 
    return -1; 
  
  // (2)convert Color Image to Grayscale for Feature Extraction 
  Mat grayImage; 
  cvtColor(colorImage, grayImage, CV_BGR2GRAY); 
  
  // (3)initialize SURF class 
  SURF calc_surf = SURF(500,4,2,true); 
  
  // (4)extract SURF 
  vector<KeyPoint> kp_vec; 
  vector<float> desc_vec;      
  calc_surf(grayImage, Mat(), kp_vec, desc_vec); 
  
  // (5)draw keypoints 
  cout << "Image Keypoints: " << kp_vec.size() << endl; 
#if 1 
  vector<KeyPoint>::iterator it = kp_vec.begin(), it_end = kp_vec.end(); 
  for(; it!=it_end; ++it) { 
    circle(colorImage, Point(it->pt.x, it->pt.y),  
       saturate_cast<int>(it->size*0.25), Scalar(255,255,0)); 
  } 
#else 
  for(int i = 0; i < kp_vec.size(); i++) { 
    KeyPoint* point = &(kp_vec[i]); 
    Point center;  // Key Point's Center 
    int radius;      // Radius of Key Point 
    center.x = cvRound(point->pt.x); 
    center.y = cvRound(point->pt.y); 
    radius = cvRound(point->size*0.25); 
    circle(colorImage, center, radius, Scalar(255,255,0), 1, 8, 0); 
  } 
#endif 
  
  namedWindow("SURF",CV_WINDOW_AUTOSIZE); 
  imshow("SURF", colorImage); 
  waitKey(0); 
  
  return 0; 
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值