Merge pull request #1263 from abidrahmank:pyCLAHE_24
[profile/ivi/opencv.git] / modules / java / generator / src / java / core+MatOfKeyPoint.java
1 package org.opencv.core;
2
3 import java.util.Arrays;
4 import java.util.List;
5
6 import org.opencv.features2d.KeyPoint;
7
8 public class MatOfKeyPoint extends Mat {
9     // 32FC7
10     private static final int _depth = CvType.CV_32F;
11     private static final int _channels = 7;
12
13     public MatOfKeyPoint() {
14         super();
15     }
16
17     protected MatOfKeyPoint(long addr) {
18         super(addr);
19         if( !empty() && checkVector(_channels, _depth) < 0 )
20             throw new IllegalArgumentException("Incompatible Mat");
21         //FIXME: do we need release() here?
22     }
23
24     public static MatOfKeyPoint fromNativeAddr(long addr) {
25         return new MatOfKeyPoint(addr);
26     }
27
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?
33     }
34
35     public MatOfKeyPoint(KeyPoint...a) {
36         super();
37         fromArray(a);
38     }
39
40     public void alloc(int elemNumber) {
41         if(elemNumber>0)
42             super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
43     }
44
45     public void fromArray(KeyPoint...a) {
46         if(a==null || a.length==0)
47             return;
48         int num = a.length;
49         alloc(num);
50         float buff[] = new float[num * _channels];
51         for(int i=0; i<num; i++) {
52             KeyPoint kp = a[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;
60         }
61         put(0, 0, buff); //TODO: check ret val!
62     }
63
64     public KeyPoint[] toArray() {
65         int num = (int) total();
66         KeyPoint[] a = new KeyPoint[num];
67         if(num == 0)
68             return a;
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] );
74         return a;
75     }
76
77     public void fromList(List<KeyPoint> lkp) {
78         KeyPoint akp[] = lkp.toArray(new KeyPoint[0]);
79         fromArray(akp);
80     }
81
82     public List<KeyPoint> toList() {
83         KeyPoint[] akp = toArray();
84         return Arrays.asList(akp);
85     }
86 }