1 package org.opencv.core;
3 import java.util.Arrays;
6 import org.opencv.features2d.DMatch;
8 public class MatOfDMatch extends Mat {
10 private static final int _depth = CvType.CV_32F;
11 private static final int _channels = 4;
13 public MatOfDMatch() {
17 protected MatOfDMatch(long addr) {
19 if( !empty() && checkVector(_channels, _depth) < 0 )
20 throw new IllegalArgumentException("Incompatible Mat: " + toString());
21 //FIXME: do we need release() here?
24 public static MatOfDMatch fromNativeAddr(long addr) {
25 return new MatOfDMatch(addr);
28 public MatOfDMatch(Mat m) {
29 super(m, Range.all());
30 if( !empty() && checkVector(_channels, _depth) < 0 )
31 throw new IllegalArgumentException("Incompatible Mat: " + toString());
32 //FIXME: do we need release() here?
35 public MatOfDMatch(DMatch...ap) {
40 public void alloc(int elemNumber) {
42 super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
46 public void fromArray(DMatch...a) {
47 if(a==null || a.length==0)
51 float buff[] = new float[num * _channels];
52 for(int i=0; i<num; i++) {
54 buff[_channels*i+0] = m.queryIdx;
55 buff[_channels*i+1] = m.trainIdx;
56 buff[_channels*i+2] = m.imgIdx;
57 buff[_channels*i+3] = m.distance;
59 put(0, 0, buff); //TODO: check ret val!
62 public DMatch[] toArray() {
63 int num = (int) total();
64 DMatch[] a = new DMatch[num];
67 float buff[] = new float[num * _channels];
68 get(0, 0, buff); //TODO: check ret val!
69 for(int i=0; i<num; i++)
70 a[i] = new DMatch((int) buff[_channels*i+0], (int) buff[_channels*i+1], (int) buff[_channels*i+2], buff[_channels*i+3]);
74 public void fromList(List<DMatch> ldm) {
75 DMatch adm[] = ldm.toArray(new DMatch[0]);
79 public List<DMatch> toList() {
80 DMatch[] adm = toArray();
81 return Arrays.asList(adm);