1 package org.opencv.core;
3 import java.util.Arrays;
7 public class MatOfRect extends Mat {
9 private static final int _depth = CvType.CV_32S;
10 private static final int _channels = 4;
16 protected MatOfRect(long addr) {
18 if( !empty() && checkVector(_channels, _depth) < 0 )
19 throw new IllegalArgumentException("Incomatible Mat");
20 //FIXME: do we need release() here?
23 public static MatOfRect fromNativeAddr(long addr) {
24 return new MatOfRect(addr);
27 public MatOfRect(Mat m) {
28 super(m, Range.all());
29 if( !empty() && checkVector(_channels, _depth) < 0 )
30 throw new IllegalArgumentException("Incomatible Mat");
31 //FIXME: do we need release() here?
34 public MatOfRect(Rect...a) {
39 public void alloc(int elemNumber) {
41 super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
44 public void fromArray(Rect...a) {
45 if(a==null || a.length==0)
49 int buff[] = new int[num * _channels];
50 for(int i=0; i<num; 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;
57 put(0, 0, buff); //TODO: check ret val!
61 public Rect[] toArray() {
62 int num = (int) total();
63 Rect[] a = new Rect[num];
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]);
72 public void fromList(List<Rect> lr) {
73 Rect ap[] = lr.toArray(new Rect[0]);
77 public List<Rect> toList() {
78 Rect[] ar = toArray();
79 return Arrays.asList(ar);