1 package org.opencv.core;
3 import java.util.Arrays;
6 import org.opencv.features2d.KeyPoint;
8 public class MatOfKeyPoint extends Mat {
10 private static final int _depth = CvType.CV_32F;
11 private static final int _channels = 7;
13 public MatOfKeyPoint() {
17 protected MatOfKeyPoint(long addr) {
19 if( !empty() && checkVector(_channels, _depth) < 0 )
20 throw new IllegalArgumentException("Incompatible Mat");
21 //FIXME: do we need release() here?
24 public static MatOfKeyPoint fromNativeAddr(long addr) {
25 return new MatOfKeyPoint(addr);
28 public MatOfKeyPoint(Mat m) {
29 super(m, Range.all());
30 if( !empty() && checkVector(_channels, _depth) < 0 )
31 throw new IllegalArgumentException("Incompatible Mat");
32 //FIXME: do we need release() here?
35 public MatOfKeyPoint(KeyPoint...a) {
40 public void alloc(int elemNumber) {
42 super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
45 public void fromArray(KeyPoint...a) {
46 if(a==null || a.length==0)
50 float buff[] = new float[num * _channels];
51 for(int i=0; i<num; i++) {
53 buff[_channels*i+0] = (float) kp.pt.x;
54 buff[_channels*i+1] = (float) kp.pt.y;
55 buff[_channels*i+2] = kp.size;
56 buff[_channels*i+3] = kp.angle;
57 buff[_channels*i+4] = kp.response;
58 buff[_channels*i+5] = kp.octave;
59 buff[_channels*i+6] = kp.class_id;
61 put(0, 0, buff); //TODO: check ret val!
64 public KeyPoint[] toArray() {
65 int num = (int) total();
66 KeyPoint[] a = new KeyPoint[num];
69 float buff[] = new float[num * _channels];
70 get(0, 0, buff); //TODO: check ret val!
71 for(int i=0; i<num; i++)
72 a[i] = new KeyPoint( buff[_channels*i+0], buff[_channels*i+1], buff[_channels*i+2], buff[_channels*i+3],
73 buff[_channels*i+4], (int) buff[_channels*i+5], (int) buff[_channels*i+6] );
77 public void fromList(List<KeyPoint> lkp) {
78 KeyPoint akp[] = lkp.toArray(new KeyPoint[0]);
82 public List<KeyPoint> toList() {
83 KeyPoint[] akp = toArray();
84 return Arrays.asList(akp);