1 package org.opencv.core; 2 3 import java.util.Arrays; 4 import java.util.List; 5 6 7 public class MatOfInt extends Mat { 8 // 32SC1 9 private static final int _depth = CvType.CV_32S; 10 private static final int _channels = 1; 11 12 public MatOfInt() { 13 super(); 14 } 15 16 protected MatOfInt(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 MatOfInt fromNativeAddr(long addr) { 24 return new MatOfInt(addr); 25 } 26 27 public MatOfInt(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 MatOfInt(int...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(int...a) { 45 if(a==null || a.length==0) 46 return; 47 int num = a.length / _channels; 48 alloc(num); 49 put(0, 0, a); //TODO: check ret val! 50 } 51 52 public int[] toArray() { 53 int num = checkVector(_channels, _depth); 54 if(num < 0) 55 throw new RuntimeException("Native Mat has unexpected type or size: " + toString()); 56 int[] a = new int[num * _channels]; 57 if(num == 0) 58 return a; 59 get(0, 0, a); //TODO: check ret val! 60 return a; 61 } 62 63 public void fromList(List<Integer> lb) { 64 if(lb==null || lb.size()==0) 65 return; 66 Integer ab[] = lb.toArray(new Integer[0]); 67 int a[] = new int[ab.length]; 68 for(int i=0; i<ab.length; i++) 69 a[i] = ab[i]; 70 fromArray(a); 71 } 72 73 public List<Integer> toList() { 74 int[] a = toArray(); 75 Integer ab[] = new Integer[a.length]; 76 for(int i=0; i<a.length; i++) 77 ab[i] = a[i]; 78 return Arrays.asList(ab); 79 } 80 } 81