public static Mat vector_DMatch_to_Mat(List <DMatch> matches) { Mat res; int count = (matches != null) ? matches.Count : 0; if (count > 0) { res = new Mat(count, 1, CvType.CV_64FC4); double[] buff = new double[count * 4]; for (int i = 0; i < count; i++) { DMatch m = matches[i]; buff[4 * i] = m.queryIdx; buff[4 * i + 1] = m.trainIdx; buff[4 * i + 2] = m.imgIdx; buff[4 * i + 3] = m.distance; } res.put(0, 0, buff); } else { res = new Mat(); } return(res); }
public DMatch[] toArray() { int num = (int) total(); DMatch[] a = new DMatch[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 DMatch((int) buff[_channels*i+0], (int) buff[_channels*i+1], (int) buff[_channels*i+2], buff[_channels*i+3]); return a; }
public void fromArray(params DMatch[] 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++) { DMatch m = a[i]; buff[_channels*i+0] = m.queryIdx; buff[_channels*i+1] = m.trainIdx; buff[_channels*i+2] = m.imgIdx; buff[_channels*i+3] = m.distance; } put(0, 0, buff); //TODO: check ret val! }
public bool lessThan(DMatch it) { return(distance < it.distance); }