001package org.opencv.core; 002 003import java.util.Arrays; 004import java.util.List; 005 006 007public class MatOfRect2d extends Mat { 008 // 64FC4 009 private static final int _depth = CvType.CV_64F; 010 private static final int _channels = 4; 011 012 public MatOfRect2d() { 013 super(); 014 } 015 016 protected MatOfRect2d(long addr) { 017 super(addr); 018 if( !empty() && checkVector(_channels, _depth) < 0 ) 019 throw new IllegalArgumentException("Incompatible Mat"); 020 //FIXME: do we need release() here? 021 } 022 023 public static MatOfRect2d fromNativeAddr(long addr) { 024 return new MatOfRect2d(addr); 025 } 026 027 public MatOfRect2d(Mat m) { 028 super(m, Range.all()); 029 if( !empty() && checkVector(_channels, _depth) < 0 ) 030 throw new IllegalArgumentException("Incompatible Mat"); 031 //FIXME: do we need release() here? 032 } 033 034 public MatOfRect2d(Rect2d...a) { 035 super(); 036 fromArray(a); 037 } 038 039 public void alloc(int elemNumber) { 040 if(elemNumber>0) 041 super.create(elemNumber, 1, CvType.makeType(_depth, _channels)); 042 } 043 044 public void fromArray(Rect2d...a) { 045 if(a==null || a.length==0) 046 return; 047 int num = a.length; 048 alloc(num); 049 double buff[] = new double[num * _channels]; 050 for(int i=0; i<num; i++) { 051 Rect2d r = a[i]; 052 buff[_channels*i+0] = (double) r.x; 053 buff[_channels*i+1] = (double) r.y; 054 buff[_channels*i+2] = (double) r.width; 055 buff[_channels*i+3] = (double) r.height; 056 } 057 put(0, 0, buff); //TODO: check ret val! 058 } 059 060 061 public Rect2d[] toArray() { 062 int num = (int) total(); 063 Rect2d[] a = new Rect2d[num]; 064 if(num == 0) 065 return a; 066 double buff[] = new double[num * _channels]; 067 get(0, 0, buff); //TODO: check ret val! 068 for(int i=0; i<num; i++) 069 a[i] = new Rect2d(buff[i*_channels], buff[i*_channels+1], buff[i*_channels+2], buff[i*_channels+3]); 070 return a; 071 } 072 public void fromList(List<Rect2d> lr) { 073 Rect2d ap[] = lr.toArray(new Rect2d[0]); 074 fromArray(ap); 075 } 076 077 public List<Rect2d> toList() { 078 Rect2d[] ar = toArray(); 079 return Arrays.asList(ar); 080 } 081}