码迷,mamicode.com
首页 > 编程语言 > 详细

java 在centos6.5+eclipse环境下调用opencv实现sift算法

时间:2015-11-16 19:36:55      阅读:299      评论:0      收藏:0      [点我收藏+]

标签:

java 在centos6.5+eclipse环境下调用opencv实现sift算法,代码如下:

技术分享
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.highgui.Highgui;
import org.opencv.features2d.*;
public class ExtractSIFT{
  public static void main( String[] args ){
       System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
      Mat test_mat = Highgui.imread("/home/Tian/software/meng.jpg");
      Mat desc = new Mat();
       FeatureDetector fd = FeatureDetector.create(FeatureDetector.SIFT);
       MatOfKeyPoint mkp =new MatOfKeyPoint();
       fd.detect(test_mat, mkp);
       DescriptorExtractor de = DescriptorExtractor.create(DescriptorExtractor.SIFT);
       de.compute(test_mat,mkp,desc );//提取sift特征
       System.out.println(desc.cols());
       System.out.println(desc.rows());
   }
   //以下代码实现了对主函数中代码的封装
    /** 
     * 传入一张图片得到sift特征点 
     * @param mat 
     * @return 
     */  
    public MatOfKeyPoint getFeaturePoints(Mat mat){  
        FeatureDetector fd = FeatureDetector.create(FeatureDetector.SIFT);  
        MatOfKeyPoint mkp =new MatOfKeyPoint();  
        fd.detect(mat, mkp);  
        return mkp;  
    }  
      
    /** 
     * 获取sift特征 
     * @param mat 
     * @return 
     */  
    public Mat getFeature(Mat mat){  
        Mat desc = new Mat();  
        MatOfKeyPoint mkp = getFeaturePoints(mat);  
        DescriptorExtractor de = DescriptorExtractor.create(DescriptorExtractor.SIFT);  
        de.compute(mat,mkp,desc );//提取sift特征  
        return desc;  
    }  
}
View Code

 

java 在centos6.5+eclipse环境下调用opencv实现sift算法

标签:

原文地址:http://www.cnblogs.com/tianyalu/p/4969750.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!