public LinkedList<CvSurfFeature> computeSurfKeypoints(BufferedImage img) { MatOfKeyPoint keypoints = new MatOfKeyPoint(); List<KeyPoint> myKeys; // Mat img_object = Highgui.imread(image, 0); //0 = CV_LOAD_IMAGE_GRAYSCALE // detector.detect(img_object, keypoints); byte[] data = ((DataBufferByte) img.getRaster().getDataBuffer()).getData(); Mat matRGB = new Mat(img.getHeight(), img.getWidth(), CvType.CV_8UC3); matRGB.put(0, 0, data); Mat matGray = new Mat(img.getHeight(),img.getWidth(),CvType.CV_8UC1); Imgproc.cvtColor(matRGB, matGray, Imgproc.COLOR_BGR2GRAY); //TODO: RGB or BGR? byte[] dataGray = new byte[matGray.rows()*matGray.cols()*(int)(matGray.elemSize())]; matGray.get(0, 0, dataGray); detector.detect(matGray, keypoints); myKeys = keypoints.toList(); LinkedList<CvSurfFeature> myKeypoints = new LinkedList<CvSurfFeature>(); KeyPoint key; CvSurfFeature feat; for (Iterator<KeyPoint> iterator = myKeys.iterator(); iterator.hasNext(); ) { key = iterator.next(); feat = new CvSurfFeature(key.pt.x, key.pt.y, key.size, null); myKeypoints.add(feat); } return myKeypoints; }
protected MatOfKeyPoint(long addr) { super(addr); if( !empty() && checkVector(_channels, _depth) < 0 ) throw new IllegalArgumentException("Incompatible Mat"); //FIXME: do we need release() here? }
public MatOfKeyPoint(KeyPoint...a) { super(); fromArray(a); }
public KeyPoint[] toArray() { int num = (int) total(); KeyPoint[] a = new KeyPoint[num]; if(num == 0) return a; float buff[] = new float[num * _channels]; get(0, 0, buff); //TODO: check ret val! for(int i=0; i<num; i++) a[i] = new KeyPoint( buff[_channels*i+0], buff[_channels*i+1], buff[_channels*i+2], buff[_channels*i+3], buff[_channels*i+4], (int) buff[_channels*i+5], (int) buff[_channels*i+6] ); return a; }
public void fromArray(KeyPoint...a) { if(a==null || a.length==0) return; int num = a.length; alloc(num); float buff[] = new float[num * _channels]; for(int i=0; i<num; i++) { KeyPoint kp = a[i]; buff[_channels*i+0] = (float) kp.pt.x; buff[_channels*i+1] = (float) kp.pt.y; buff[_channels*i+2] = kp.size; buff[_channels*i+3] = kp.angle; buff[_channels*i+4] = kp.response; buff[_channels*i+5] = kp.octave; buff[_channels*i+6] = kp.class_id; } put(0, 0, buff); //TODO: check ret val! }
public List<KeyPoint> toList() { KeyPoint[] akp = toArray(); return Arrays.asList(akp); } }
FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB); DescriptorExtractor descriptor = DescriptorExtractor.create(DescriptorExtractor.ORB);; DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING); //first image Mat img1 = Highgui.imread("<image1 path>"); Mat descriptors1 = new Mat(); MatOfKeyPoint keypoints1 = new MatOfKeyPoint(); detector.detect(img1, keypoints1); descriptor.compute(img1, keypoints1, descriptors1); //second image Mat img2 = Highgui.imread("<image2 path>"); Mat descriptors2 = new Mat(); MatOfKeyPoint keypoints2 = new MatOfKeyPoint(); detector.detect(img2, keypoints2); descriptor.compute(img2, keypoints2, descriptors2); //matcher should include 2 different image's descriptors MatOfDMatch matches = new MatOfDMatch(); matcher.match(descriptors1,descriptors2,matches); //feature and connection colors Scalar RED = new Scalar(255,0,0); Scalar GREEN = new Scalar(0,255,0); //output image Mat outputImg = new Mat(); MatOfByte drawnMatches = new MatOfByte(); //this will draw all matches, works fine Features2d.drawMatches(img1, keypoints1, img2, keypoints2, matches, outputImg, GREEN, RED, drawnMatches, Features2d.NOT_DRAW_SINGLE_POINTS);
public KeyPoint[] toArray() { int num = (int) total(); KeyPoint[] a = new KeyPoint[num]; if(num == 0) return a; float buff[] = new float[num * _channels]; get(0, 0, buff); //TODO: check ret val! for(int i=0; i<num; i++) a[i] = new KeyPoint( buff[_channels*i+0], buff[_channels*i+1], buff[_channels*i+2], buff[_channels*i+3], buff[_channels*i+4], (int) buff[_channels*i+5], (int) buff[_channels*i+6] ); return a; }
public void fromArray(KeyPoint...a) { if(a==null || a.length==0) return; int num = a.length; alloc(num); float buff[] = new float[num * _channels]; for(int i=0; i<num; i++) { KeyPoint kp = a[i]; buff[_channels*i+0] = (float) kp.pt.x; buff[_channels*i+1] = (float) kp.pt.y; buff[_channels*i+2] = kp.size; buff[_channels*i+3] = kp.angle; buff[_channels*i+4] = kp.response; buff[_channels*i+5] = kp.octave; buff[_channels*i+6] = kp.class_id; } put(0, 0, buff); //TODO: check ret val! }
public List<KeyPoint> toList() { KeyPoint[] akp = toArray(); return Arrays.asList(akp); } }
public static void Mat_to_vector_vector_KeyPoint(Mat m, List<MatOfKeyPoint> kps) { if (kps == null) throw new java.lang.IllegalArgumentException("Output List can't be null"); if (m == null) throw new java.lang.IllegalArgumentException("Input Mat can't be null"); List<Mat> mats = new ArrayList<Mat>(m.rows()); Mat_to_vector_Mat(m, mats); for (Mat mi : mats) { MatOfKeyPoint vkp = new MatOfKeyPoint(mi); kps.add(vkp); } }
protected MatOfKeyPoint(long addr) { super(addr); if( !empty() && checkVector(_channels, _depth) < 0 ) throw new IllegalArgumentException("Incompatible Mat"); //FIXME: do we need release() here? }
public KeyPoint[] toArray() { int num = (int) total(); KeyPoint[] a = new KeyPoint[num]; if(num == 0) return a; float buff[] = new float[num * _channels]; get(0, 0, buff); //TODO: check ret val! for(int i=0; i<num; i++) a[i] = new KeyPoint( buff[_channels*i+0], buff[_channels*i+1], buff[_channels*i+2], buff[_channels*i+3], buff[_channels*i+4], (int) buff[_channels*i+5], (int) buff[_channels*i+6] ); return a; }
public void fromArray(KeyPoint...a) { if(a==null || a.length==0) return; int num = a.length; alloc(num); float buff[] = new float[num * _channels]; for(int i=0; i<num; i++) { KeyPoint kp = a[i]; buff[_channels*i+0] = (float) kp.pt.x; buff[_channels*i+1] = (float) kp.pt.y; buff[_channels*i+2] = kp.size; buff[_channels*i+3] = kp.angle; buff[_channels*i+4] = kp.response; buff[_channels*i+5] = kp.octave; buff[_channels*i+6] = kp.class_id; } put(0, 0, buff); //TODO: check ret val! }
public LinkedList<CvSiftFeature> computeSiftKeypoints(BufferedImage img) { MatOfKeyPoint keypoints = new MatOfKeyPoint(); List<KeyPoint> myKeys; // Mat img_object = Highgui.imread(image, 0); //0 = CV_LOAD_IMAGE_GRAYSCALE // detector.detect(img_object, keypoints); byte[] data = ((DataBufferByte) img.getRaster().getDataBuffer()).getData(); Mat matRGB = new Mat(img.getHeight(), img.getWidth(), CvType.CV_8UC3); matRGB.put(0, 0, data); Mat matGray = new Mat(img.getHeight(),img.getWidth(),CvType.CV_8UC1); Imgproc.cvtColor(matRGB, matGray, Imgproc.COLOR_BGR2GRAY); //TODO: RGB or BGR? byte[] dataGray = new byte[matGray.rows()*matGray.cols()*(int)(matGray.elemSize())]; matGray.get(0, 0, dataGray); detector.detect(matGray, keypoints); myKeys = keypoints.toList(); LinkedList<CvSiftFeature> myKeypoints = new LinkedList<CvSiftFeature>(); KeyPoint key; CvSiftFeature feat; for (Iterator<KeyPoint> iterator = myKeys.iterator(); iterator.hasNext(); ) { key = iterator.next(); feat = new CvSiftFeature(key.pt.x, key.pt.y, key.size, null); myKeypoints.add(feat); } return myKeypoints; }
public List<KeyPoint> toList() { KeyPoint[] akp = toArray(); return Arrays.asList(akp); } }
public MatOfKeyPoint(KeyPoint...a) { super(); fromArray(a); }
public static void Mat_to_vector_vector_KeyPoint(Mat m, List<MatOfKeyPoint> kps) { if (kps == null) throw new java.lang.IllegalArgumentException("Output List can't be null"); if (m == null) throw new java.lang.IllegalArgumentException("Input Mat can't be null"); List<Mat> mats = new ArrayList<Mat>(m.rows()); Mat_to_vector_Mat(m, mats); for (Mat mi : mats) { MatOfKeyPoint vkp = new MatOfKeyPoint(mi); kps.add(vkp); } }
protected MatOfKeyPoint(long addr) { super(addr); if( !empty() && checkVector(_channels, _depth) < 0 ) throw new IllegalArgumentException("Incompatible Mat"); //FIXME: do we need release() here? }
public KeyPoint[] toArray() { int num = (int) total(); KeyPoint[] a = new KeyPoint[num]; if(num == 0) return a; float buff[] = new float[num * _channels]; get(0, 0, buff); //TODO: check ret val! for(int i=0; i<num; i++) a[i] = new KeyPoint( buff[_channels*i+0], buff[_channels*i+1], buff[_channels*i+2], buff[_channels*i+3], buff[_channels*i+4], (int) buff[_channels*i+5], (int) buff[_channels*i+6] ); return a; }