1 package org.opencv.core;
3 import java.util.Arrays;
6 public class MatOfPoint extends Mat {
8 private static final int _depth = CvType.CV_32S;
9 private static final int _channels = 2;
15 protected MatOfPoint(long addr) {
17 if( !empty() && checkVector(_channels, _depth) < 0 )
18 throw new IllegalArgumentException("Incomatible Mat");
19 //FIXME: do we need release() here?
22 public static MatOfPoint fromNativeAddr(long addr) {
23 return new MatOfPoint(addr);
26 public MatOfPoint(Mat m) {
27 super(m, Range.all());
28 if( !empty() && checkVector(_channels, _depth) < 0 )
29 throw new IllegalArgumentException("Incomatible Mat");
30 //FIXME: do we need release() here?
33 public MatOfPoint(Point...a) {
38 public void alloc(int elemNumber) {
40 super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
43 public void fromArray(Point...a) {
44 if(a==null || a.length==0)
48 int buff[] = new int[num * _channels];
49 for(int i=0; i<num; i++) {
51 buff[_channels*i+0] = (int) p.x;
52 buff[_channels*i+1] = (int) p.y;
54 put(0, 0, buff); //TODO: check ret val!
57 public Point[] toArray() {
58 int num = (int) total();
59 Point[] ap = new Point[num];
62 int buff[] = new int[num * _channels];
63 get(0, 0, buff); //TODO: check ret val!
64 for(int i=0; i<num; i++)
65 ap[i] = new Point(buff[i*_channels], buff[i*_channels+1]);
69 public void fromList(List<Point> lp) {
70 Point ap[] = lp.toArray(new Point[0]);
74 public List<Point> toList() {
75 Point[] ap = toArray();
76 return Arrays.asList(ap);