Merge pull request #1263 from abidrahmank:pyCLAHE_24
[profile/ivi/opencv.git] / modules / java / generator / src / java / core+MatOfRect.java
1 package org.opencv.core;
2
3 import java.util.Arrays;
4 import java.util.List;
5
6
7 public class MatOfRect extends Mat {
8     // 32SC4
9     private static final int _depth = CvType.CV_32S;
10     private static final int _channels = 4;
11
12     public MatOfRect() {
13         super();
14     }
15
16     protected MatOfRect(long addr) {
17         super(addr);
18         if( !empty() && checkVector(_channels, _depth) < 0 )
19             throw new IllegalArgumentException("Incompatible Mat");
20         //FIXME: do we need release() here?
21     }
22
23     public static MatOfRect fromNativeAddr(long addr) {
24         return new MatOfRect(addr);
25     }
26
27     public MatOfRect(Mat m) {
28         super(m, Range.all());
29         if( !empty() && checkVector(_channels, _depth) < 0 )
30             throw new IllegalArgumentException("Incompatible Mat");
31         //FIXME: do we need release() here?
32     }
33
34     public MatOfRect(Rect...a) {
35         super();
36         fromArray(a);
37     }
38
39     public void alloc(int elemNumber) {
40         if(elemNumber>0)
41             super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
42     }
43
44     public void fromArray(Rect...a) {
45         if(a==null || a.length==0)
46             return;
47         int num = a.length;
48         alloc(num);
49         int buff[] = new int[num * _channels];
50         for(int i=0; i<num; i++) {
51             Rect r = a[i];
52             buff[_channels*i+0] = (int) r.x;
53             buff[_channels*i+1] = (int) r.y;
54             buff[_channels*i+2] = (int) r.width;
55             buff[_channels*i+3] = (int) r.height;
56         }
57         put(0, 0, buff); //TODO: check ret val!
58     }
59
60
61     public Rect[] toArray() {
62         int num = (int) total();
63         Rect[] a = new Rect[num];
64         if(num == 0)
65             return a;
66         int buff[] = new int[num * _channels];
67         get(0, 0, buff); //TODO: check ret val!
68         for(int i=0; i<num; i++)
69             a[i] = new Rect(buff[i*_channels], buff[i*_channels+1], buff[i*_channels+2], buff[i*_channels+3]);
70         return a;
71     }
72     public void fromList(List<Rect> lr) {
73         Rect ap[] = lr.toArray(new Rect[0]);
74         fromArray(ap);
75     }
76
77     public List<Rect> toList() {
78         Rect[] ar = toArray();
79         return Arrays.asList(ar);
80     }
81 }