1 package org.opencv.core;
3 import java.util.Arrays;
6 public class MatOfByte extends Mat {
8 private static final int _depth = CvType.CV_8U;
9 private static final int _channels = 1;
15 protected MatOfByte(long addr) {
17 if( !empty() && checkVector(_channels, _depth) < 0 )
18 throw new IllegalArgumentException("Incompatible Mat");
19 //FIXME: do we need release() here?
22 public static MatOfByte fromNativeAddr(long addr) {
23 return new MatOfByte(addr);
26 public MatOfByte(Mat m) {
27 super(m, Range.all());
28 if( !empty() && checkVector(_channels, _depth) < 0 )
29 throw new IllegalArgumentException("Incompatible Mat");
30 //FIXME: do we need release() here?
33 public MatOfByte(byte...a) {
38 public void alloc(int elemNumber) {
40 super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
43 public void fromArray(byte...a) {
44 if(a==null || a.length==0)
46 int num = a.length / _channels;
48 put(0, 0, a); //TODO: check ret val!
51 public byte[] toArray() {
52 int num = checkVector(_channels, _depth);
54 throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
55 byte[] a = new byte[num * _channels];
58 get(0, 0, a); //TODO: check ret val!
62 public void fromList(List<Byte> lb) {
63 if(lb==null || lb.size()==0)
65 Byte ab[] = lb.toArray(new Byte[0]);
66 byte a[] = new byte[ab.length];
67 for(int i=0; i<ab.length; i++)
72 public List<Byte> toList() {
74 Byte ab[] = new Byte[a.length];
75 for(int i=0; i<a.length; i++)
77 return Arrays.asList(ab);