~paparazzi-uav/paparazzi/v5.0-manual

« back to all changes in this revision

Viewing changes to sw/ext/opencv_bebop/opencv/modules/core/misc/java/src/java/core+MatOfFloat4.java

  • Committer: Paparazzi buildbot
  • Date: 2016-05-18 15:00:29 UTC
  • Revision ID: felix.ruess+docbot@gmail.com-20160518150029-e8lgzi5kvb4p7un9
Manual import commit 4b8bbb730080dac23cf816b98908dacfabe2a8ec from v5.0 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.opencv.core;
 
2
 
 
3
import java.util.Arrays;
 
4
import java.util.List;
 
5
 
 
6
public class MatOfFloat4 extends Mat {
 
7
    // 32FC4
 
8
    private static final int _depth = CvType.CV_32F;
 
9
    private static final int _channels = 4;
 
10
 
 
11
    public MatOfFloat4() {
 
12
        super();
 
13
    }
 
14
 
 
15
    protected MatOfFloat4(long addr) {
 
16
        super(addr);
 
17
        if( !empty() && checkVector(_channels, _depth) < 0 )
 
18
            throw new IllegalArgumentException("Incompatible Mat");
 
19
        //FIXME: do we need release() here?
 
20
    }
 
21
 
 
22
    public static MatOfFloat4 fromNativeAddr(long addr) {
 
23
        return new MatOfFloat4(addr);
 
24
    }
 
25
 
 
26
    public MatOfFloat4(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?
 
31
    }
 
32
 
 
33
    public MatOfFloat4(float...a) {
 
34
        super();
 
35
        fromArray(a);
 
36
    }
 
37
 
 
38
    public void alloc(int elemNumber) {
 
39
        if(elemNumber>0)
 
40
            super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
 
41
    }
 
42
 
 
43
    public void fromArray(float...a) {
 
44
        if(a==null || a.length==0)
 
45
            return;
 
46
        int num = a.length / _channels;
 
47
        alloc(num);
 
48
        put(0, 0, a); //TODO: check ret val!
 
49
    }
 
50
 
 
51
    public float[] toArray() {
 
52
        int num = checkVector(_channels, _depth);
 
53
        if(num < 0)
 
54
            throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
 
55
        float[] a = new float[num * _channels];
 
56
        if(num == 0)
 
57
            return a;
 
58
        get(0, 0, a); //TODO: check ret val!
 
59
        return a;
 
60
    }
 
61
 
 
62
    public void fromList(List<Float> lb) {
 
63
        if(lb==null || lb.size()==0)
 
64
            return;
 
65
        Float ab[] = lb.toArray(new Float[0]);
 
66
        float a[] = new float[ab.length];
 
67
        for(int i=0; i<ab.length; i++)
 
68
            a[i] = ab[i];
 
69
        fromArray(a);
 
70
    }
 
71
 
 
72
    public List<Float> toList() {
 
73
        float[] a = toArray();
 
74
        Float ab[] = new Float[a.length];
 
75
        for(int i=0; i<a.length; i++)
 
76
            ab[i] = a[i];
 
77
        return Arrays.asList(ab);
 
78
    }
 
79
}