| 24 | import pkgBean.ImgSeekBean; |
| 25 | |
| 26 | public class ImgSeek { |
| 27 | |
| 28 | private static float nndrRatio = 0.8f;//�������üȶ�ֵΪ0.7����ֵ�����е��� |
| 29 | |
| 30 | |
| 31 | |
| 32 | public float getNndrRatio() { |
| 33 | return nndrRatio; |
| 34 | } |
| 35 | |
| 36 | public void setNndrRatio(float nndrRatio) { |
| 37 | ImgSeek.nndrRatio = nndrRatio; |
| 38 | } |
| 39 | |
| 40 | |
| 41 | /** |
| 42 | * Ѱͼ���� |
| 43 | * @param templateFilePath ģ��ͼ�ļ�·�� |
| 44 | * @param originalFilePath ԭͼ�ļ�·�� |
| 45 | * @param isTest �Ƿ�Ϊ����ģʽ����������Ѱͼ�������ͼƬ |
| 46 | * @return ����ImgSeekBean������ͼ��ƥ�����������Ϣ |
| 47 | */ |
| 48 | public static ImgSeekBean findImg(String templateFilePath,String originalFilePath,boolean isTest){ |
| 49 | ImgSeekBean isb = new ImgSeekBean(); |
| 50 | try{ |
| 51 | System.loadLibrary(Core.NATIVE_LIBRARY_NAME); |
| 52 | //������ʱ�ļ��в���ͼƬ�洢·�� |
| 53 | String tempPath = "./res/pics/pic_temp/"; |
| 54 | //��ȡͼƬת��Ϊ���� |
| 55 | Mat templateImage = Highgui.imread(templateFilePath, Highgui.CV_LOAD_IMAGE_COLOR); |
| 56 | Mat originalImage = Highgui.imread(originalFilePath, Highgui.CV_LOAD_IMAGE_COLOR); |
| 57 | MatOfKeyPoint templateKeyPoints = new MatOfKeyPoint(); |
| 58 | //ָ���������㷨SURF |
| 59 | FeatureDetector featureDetector = FeatureDetector.create(FeatureDetector.SIFT); |
| 60 | //��ȡģ��ͼ�������� |
| 61 | featureDetector.detect(templateImage, templateKeyPoints); |
| 62 | //��ȡģ��ͼ�������� |
| 63 | MatOfKeyPoint templateDescriptors = new MatOfKeyPoint(); |
| 64 | DescriptorExtractor descriptorExtractor = DescriptorExtractor.create(DescriptorExtractor.SIFT); |
| 65 | descriptorExtractor.compute(templateImage, templateKeyPoints, templateDescriptors); |
| 66 | isb.setTempKeyPointsNum((int)templateKeyPoints.size().height); |
| 67 | |
| 68 | //��ȡԭͼ�������� |
| 69 | MatOfKeyPoint originalKeyPoints = new MatOfKeyPoint(); |
| 70 | MatOfKeyPoint originalDescriptors = new MatOfKeyPoint(); |
| 71 | featureDetector.detect(originalImage, originalKeyPoints); |
| 72 | descriptorExtractor.compute(originalImage, originalKeyPoints, originalDescriptors); |
| 73 | |
| 74 | List<MatOfDMatch> matches = new LinkedList<MatOfDMatch>(); |
| 75 | DescriptorMatcher descriptorMatcher = DescriptorMatcher.create(DescriptorMatcher.FLANNBASED); |
| 76 | //Ѱ�����ƥ�� |
| 77 | /** |
| 78 | * knnMatch���������þ����ڸ�����������������Ѱ�����ƥ�� |
| 79 | * ʹ��KNN-matching�㷨����K=2����ÿ��match�õ�������ӽ���descriptor��Ȼ�������ӽ�����ʹνӽ�����֮��ı�ֵ������ֵ���ڼȶ�ֵʱ������Ϊ����match�� |
| 80 | */ |
| 81 | descriptorMatcher.knnMatch(templateDescriptors, originalDescriptors, matches, 2); |
| 82 | |
| 83 | //��ƥ��������ɸѡ������distance����ɸѡ |
nothing calls this directly
no outgoing calls
no test coverage detected