79 | * This function converts an Android Bitmap image to the OpenCV Mat.
80 | *
'ARGB_8888' and 'RGB_565' input Bitmap formats are supported.
81 | *
The output Mat is always created of the same size as the input Bitmap and of the 'CV_8UC4' type,
82 | * it keeps the image in RGBA format.
83 | *
This function throws an exception if the conversion fails.
84 | * @param bmp is a valid input Bitmap object of the type 'ARGB_8888' or 'RGB_565'.
85 | * @param mat is a valid output Mat object, it will be reallocated if needed, so it may be empty.
86 | * @param unPremultiplyAlpha is a flag, that determines, whether the bitmap needs to be converted from alpha premultiplied format (like Android keeps 'ARGB_8888' ones) to regular one; this flag is ignored for 'RGB_565' bitmaps.
87 | */
88 | public static void bitmapToMat(Bitmap bmp, Mat mat, boolean unPremultiplyAlpha) {
89 | if (bmp == null)
90 | throw new java.lang.IllegalArgumentException("bmp == null");
91 | if (mat == null)
92 | throw new java.lang.IllegalArgumentException("mat == null");
93 | nBitmapToMat2(bmp, mat.nativeObj, unPremultiplyAlpha);
94 | }
95 |
96 | /**
97 | * Short form of the bitmapToMat(bmp, mat, unPremultiplyAlpha=false).
98 | * @param bmp is a valid input Bitmap object of the type 'ARGB_8888' or 'RGB_565'.
99 | * @param mat is a valid output Mat object, it will be reallocated if needed, so Mat may be empty.
100 | */
101 | public static void bitmapToMat(Bitmap bmp, Mat mat) {
102 | bitmapToMat(bmp, mat, false);
103 | }
104 |
105 |
106 | /**
107 | * Converts OpenCV Mat to Android Bitmap.
108 | *
109 | *
This function converts an image in the OpenCV Mat representation to the Android Bitmap.
110 | *
The input Mat object has to be of the types 'CV_8UC1' (gray-scale), 'CV_8UC3' (RGB) or 'CV_8UC4' (RGBA).
111 | *
The output Bitmap object has to be of the same size as the input Mat and of the types 'ARGB_8888' or 'RGB_565'.
112 | *
This function throws an exception if the conversion fails.
113 | *
114 | * @param mat is a valid input Mat object of types 'CV_8UC1', 'CV_8UC3' or 'CV_8UC4'.
115 | * @param bmp is a valid Bitmap object of the same size as the Mat and of type 'ARGB_8888' or 'RGB_565'.
116 | * @param premultiplyAlpha is a flag, that determines, whether the Mat needs to be converted to alpha premultiplied format (like Android keeps 'ARGB_8888' bitmaps); the flag is ignored for 'RGB_565' bitmaps.
117 | */
118 | public static void matToBitmap(Mat mat, Bitmap bmp, boolean premultiplyAlpha) {
119 | if (mat == null)
120 | throw new java.lang.IllegalArgumentException("mat == null");
121 | if (bmp == null)
122 | throw new java.lang.IllegalArgumentException("bmp == null");
123 | nMatToBitmap2(mat.nativeObj, bmp, premultiplyAlpha);
124 | }
125 |
126 | /**
127 | * Short form of the matToBitmap(mat, bmp, premultiplyAlpha=false)
128 | * @param mat is a valid input Mat object of the types 'CV_8UC1', 'CV_8UC3' or 'CV_8UC4'.
129 | * @param bmp is a valid Bitmap object of the same size as the Mat and of type 'ARGB_8888' or 'RGB_565'.
130 | */
131 | public static void matToBitmap(Mat mat, Bitmap bmp) {
132 | matToBitmap(mat, bmp, false);
133 | }
134 |
135 |
136 | private static native void nBitmapToMat2(Bitmap b, long m_addr, boolean unPremultiplyAlpha);
137 |
138 | private static native void nMatToBitmap2(long m_addr, Bitmap b, boolean premultiplyAlpha);
139 | }
140 |
--------------------------------------------------------------------------------
/opencv/src/main/java/org/opencv/core/Algorithm.java:
--------------------------------------------------------------------------------
1 |
2 | //
3 | // This file is auto-generated. Please don't modify it!
4 | //
5 | package org.opencv.core;
6 |
7 | import java.lang.String;
8 |
9 | // C++: class Algorithm
10 | //javadoc: Algorithm
11 | public class Algorithm {
12 |
13 | protected final long nativeObj;
14 | protected Algorithm(long addr) { nativeObj = addr; }
15 |
16 |
17 | //
18 | // C++: String getDefaultName()
19 | //
20 |
21 | //javadoc: Algorithm::getDefaultName()
22 | public String getDefaultName()
23 | {
24 |
25 | String retVal = getDefaultName_0(nativeObj);
26 |
27 | return retVal;
28 | }
29 |
30 |
31 | //
32 | // C++: void clear()
33 | //
34 |
35 | //javadoc: Algorithm::clear()
36 | public void clear()
37 | {
38 |
39 | clear_0(nativeObj);
40 |
41 | return;
42 | }
43 |
44 |
45 | //
46 | // C++: void save(String filename)
47 | //
48 |
49 | //javadoc: Algorithm::save(filename)
50 | public void save(String filename)
51 | {
52 |
53 | save_0(nativeObj, filename);
54 |
55 | return;
56 | }
57 |
58 |
59 | @Override
60 | protected void finalize() throws Throwable {
61 | delete(nativeObj);
62 | }
63 |
64 |
65 |
66 | // C++: String getDefaultName()
67 | private static native String getDefaultName_0(long nativeObj);
68 |
69 | // C++: void clear()
70 | private static native void clear_0(long nativeObj);
71 |
72 | // C++: void save(String filename)
73 | private static native void save_0(long nativeObj, String filename);
74 |
75 | // native support for java finalize()
76 | private static native void delete(long nativeObj);
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/opencv/src/main/java/org/opencv/core/CvException.java:
--------------------------------------------------------------------------------
1 | package org.opencv.core;
2 |
3 | public class CvException extends RuntimeException {
4 |
5 | private static final long serialVersionUID = 1L;
6 |
7 | public CvException(String msg) {
8 | super(msg);
9 | }
10 |
11 | @Override
12 | public String toString() {
13 | return "CvException [" + super.toString() + "]";
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/opencv/src/main/java/org/opencv/core/CvType.java:
--------------------------------------------------------------------------------
1 | package org.opencv.core;
2 |
3 | public final class CvType {
4 |
5 | // type depth constants
6 | public static final int
7 | CV_8U = 0, CV_8S = 1,
8 | CV_16U = 2, CV_16S = 3,
9 | CV_32S = 4,
10 | CV_32F = 5,
11 | CV_64F = 6,
12 | CV_USRTYPE1 = 7;
13 |
14 | // predefined type constants
15 | public static final int
16 | CV_8UC1 = CV_8UC(1), CV_8UC2 = CV_8UC(2), CV_8UC3 = CV_8UC(3), CV_8UC4 = CV_8UC(4),
17 | CV_8SC1 = CV_8SC(1), CV_8SC2 = CV_8SC(2), CV_8SC3 = CV_8SC(3), CV_8SC4 = CV_8SC(4),
18 | CV_16UC1 = CV_16UC(1), CV_16UC2 = CV_16UC(2), CV_16UC3 = CV_16UC(3), CV_16UC4 = CV_16UC(4),
19 | CV_16SC1 = CV_16SC(1), CV_16SC2 = CV_16SC(2), CV_16SC3 = CV_16SC(3), CV_16SC4 = CV_16SC(4),
20 | CV_32SC1 = CV_32SC(1), CV_32SC2 = CV_32SC(2), CV_32SC3 = CV_32SC(3), CV_32SC4 = CV_32SC(4),
21 | CV_32FC1 = CV_32FC(1), CV_32FC2 = CV_32FC(2), CV_32FC3 = CV_32FC(3), CV_32FC4 = CV_32FC(4),
22 | CV_64FC1 = CV_64FC(1), CV_64FC2 = CV_64FC(2), CV_64FC3 = CV_64FC(3), CV_64FC4 = CV_64FC(4);
23 |
24 | private static final int CV_CN_MAX = 512, CV_CN_SHIFT = 3, CV_DEPTH_MAX = (1 << CV_CN_SHIFT);
25 |
26 | public static final int makeType(int depth, int channels) {
27 | if (channels <= 0 || channels >= CV_CN_MAX) {
28 | throw new java.lang.UnsupportedOperationException(
29 | "Channels count should be 1.." + (CV_CN_MAX - 1));
30 | }
31 | if (depth < 0 || depth >= CV_DEPTH_MAX) {
32 | throw new java.lang.UnsupportedOperationException(
33 | "Data type depth should be 0.." + (CV_DEPTH_MAX - 1));
34 | }
35 | return (depth & (CV_DEPTH_MAX - 1)) + ((channels - 1) << CV_CN_SHIFT);
36 | }
37 |
38 | public static final int CV_8UC(int ch) {
39 | return makeType(CV_8U, ch);
40 | }
41 |
42 | public static final int CV_8SC(int ch) {
43 | return makeType(CV_8S, ch);
44 | }
45 |
46 | public static final int CV_16UC(int ch) {
47 | return makeType(CV_16U, ch);
48 | }
49 |
50 | public static final int CV_16SC(int ch) {
51 | return makeType(CV_16S, ch);
52 | }
53 |
54 | public static final int CV_32SC(int ch) {
55 | return makeType(CV_32S, ch);
56 | }
57 |
58 | public static final int CV_32FC(int ch) {
59 | return makeType(CV_32F, ch);
60 | }
61 |
62 | public static final int CV_64FC(int ch) {
63 | return makeType(CV_64F, ch);
64 | }
65 |
66 | public static final int channels(int type) {
67 | return (type >> CV_CN_SHIFT) + 1;
68 | }
69 |
70 | public static final int depth(int type) {
71 | return type & (CV_DEPTH_MAX - 1);
72 | }
73 |
74 | public static final boolean isInteger(int type) {
75 | return depth(type) < CV_32F;
76 | }
77 |
78 | public static final int ELEM_SIZE(int type) {
79 | switch (depth(type)) {
80 | case CV_8U:
81 | case CV_8S:
82 | return channels(type);
83 | case CV_16U:
84 | case CV_16S:
85 | return 2 * channels(type);
86 | case CV_32S:
87 | case CV_32F:
88 | return 4 * channels(type);
89 | case CV_64F:
90 | return 8 * channels(type);
91 | default:
92 | throw new java.lang.UnsupportedOperationException(
93 | "Unsupported CvType value: " + type);
94 | }
95 | }
96 |
97 | public static final String typeToString(int type) {
98 | String s;
99 | switch (depth(type)) {
100 | case CV_8U:
101 | s = "CV_8U";
102 | break;
103 | case CV_8S:
104 | s = "CV_8S";
105 | break;
106 | case CV_16U:
107 | s = "CV_16U";
108 | break;
109 | case CV_16S:
110 | s = "CV_16S";
111 | break;
112 | case CV_32S:
113 | s = "CV_32S";
114 | break;
115 | case CV_32F:
116 | s = "CV_32F";
117 | break;
118 | case CV_64F:
119 | s = "CV_64F";
120 | break;
121 | case CV_USRTYPE1:
122 | s = "CV_USRTYPE1";
123 | break;
124 | default:
125 | throw new java.lang.UnsupportedOperationException(
126 | "Unsupported CvType value: " + type);
127 | }
128 |
129 | int ch = channels(type);
130 | if (ch <= 4)
131 | return s + "C" + ch;
132 | else
133 | return s + "C(" + ch + ")";
134 | }
135 |
136 | }
137 |
--------------------------------------------------------------------------------
/opencv/src/main/java/org/opencv/core/DMatch.java:
--------------------------------------------------------------------------------
1 | package org.opencv.core;
2 |
3 | //C++: class DMatch
4 |
5 | /**
6 | * Structure for matching: query descriptor index, train descriptor index, train
7 | * image index and distance between descriptors.
8 | */
9 | public class DMatch {
10 |
11 | /**
12 | * Query descriptor index.
13 | */
14 | public int queryIdx;
15 | /**
16 | * Train descriptor index.
17 | */
18 | public int trainIdx;
19 | /**
20 | * Train image index.
21 | */
22 | public int imgIdx;
23 |
24 | // javadoc: DMatch::distance
25 | public float distance;
26 |
27 | // javadoc: DMatch::DMatch()
28 | public DMatch() {
29 | this(-1, -1, Float.MAX_VALUE);
30 | }
31 |
32 | // javadoc: DMatch::DMatch(_queryIdx, _trainIdx, _distance)
33 | public DMatch(int _queryIdx, int _trainIdx, float _distance) {
34 | queryIdx = _queryIdx;
35 | trainIdx = _trainIdx;
36 | imgIdx = -1;
37 | distance = _distance;
38 | }
39 |
40 | // javadoc: DMatch::DMatch(_queryIdx, _trainIdx, _imgIdx, _distance)
41 | public DMatch(int _queryIdx, int _trainIdx, int _imgIdx, float _distance) {
42 | queryIdx = _queryIdx;
43 | trainIdx = _trainIdx;
44 | imgIdx = _imgIdx;
45 | distance = _distance;
46 | }
47 |
48 | /**
49 | * Less is better.
50 | */
51 | public boolean lessThan(DMatch it) {
52 | return distance < it.distance;
53 | }
54 |
55 | @Override
56 | public String toString() {
57 | return "DMatch [queryIdx=" + queryIdx + ", trainIdx=" + trainIdx
58 | + ", imgIdx=" + imgIdx + ", distance=" + distance + "]";
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/opencv/src/main/java/org/opencv/core/KeyPoint.java:
--------------------------------------------------------------------------------
1 | package org.opencv.core;
2 |
3 | import org.opencv.core.Point;
4 |
5 | //javadoc: KeyPoint
6 | public class KeyPoint {
7 |
8 | /**
9 | * Coordinates of the keypoint.
10 | */
11 | public Point pt;
12 | /**
13 | * Diameter of the useful keypoint adjacent area.
14 | */
15 | public float size;
16 | /**
17 | * Computed orientation of the keypoint (-1 if not applicable).
18 | */
19 | public float angle;
20 | /**
21 | * The response, by which the strongest keypoints have been selected. Can
22 | * be used for further sorting or subsampling.
23 | */
24 | public float response;
25 | /**
26 | * Octave (pyramid layer), from which the keypoint has been extracted.
27 | */
28 | public int octave;
29 | /**
30 | * Object ID, that can be used to cluster keypoints by an object they
31 | * belong to.
32 | */
33 | public int class_id;
34 |
35 | // javadoc:KeyPoint::KeyPoint(x,y,_size,_angle,_response,_octave,_class_id)
36 | public KeyPoint(float x, float y, float _size, float _angle, float _response, int _octave, int _class_id)
37 | {
38 | pt = new Point(x, y);
39 | size = _size;
40 | angle = _angle;
41 | response = _response;
42 | octave = _octave;
43 | class_id = _class_id;
44 | }
45 |
46 | // javadoc: KeyPoint::KeyPoint()
47 | public KeyPoint()
48 | {
49 | this(0, 0, 0, -1, 0, 0, -1);
50 | }
51 |
52 | // javadoc: KeyPoint::KeyPoint(x, y, _size, _angle, _response, _octave)
53 | public KeyPoint(float x, float y, float _size, float _angle, float _response, int _octave)
54 | {
55 | this(x, y, _size, _angle, _response, _octave, -1);
56 | }
57 |
58 | // javadoc: KeyPoint::KeyPoint(x, y, _size, _angle, _response)
59 | public KeyPoint(float x, float y, float _size, float _angle, float _response)
60 | {
61 | this(x, y, _size, _angle, _response, 0, -1);
62 | }
63 |
64 | // javadoc: KeyPoint::KeyPoint(x, y, _size, _angle)
65 | public KeyPoint(float x, float y, float _size, float _angle)
66 | {
67 | this(x, y, _size, _angle, 0, 0, -1);
68 | }
69 |
70 | // javadoc: KeyPoint::KeyPoint(x, y, _size)
71 | public KeyPoint(float x, float y, float _size)
72 | {
73 | this(x, y, _size, -1, 0, 0, -1);
74 | }
75 |
76 | @Override
77 | public String toString() {
78 | return "KeyPoint [pt=" + pt + ", size=" + size + ", angle=" + angle
79 | + ", response=" + response + ", octave=" + octave
80 | + ", class_id=" + class_id + "]";
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/opencv/src/main/java/org/opencv/core/MatOfByte.java:
--------------------------------------------------------------------------------
1 | package org.opencv.core;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 |
6 | public class MatOfByte extends Mat {
7 | // 8UC(x)
8 | private static final int _depth = CvType.CV_8U;
9 | private static final int _channels = 1;
10 |
11 | public MatOfByte() {
12 | super();
13 | }
14 |
15 | protected MatOfByte(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 MatOfByte fromNativeAddr(long addr) {
23 | return new MatOfByte(addr);
24 | }
25 |
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?
31 | }
32 |
33 | public MatOfByte(byte...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(byte...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 byte[] toArray() {
52 | int num = checkVector(_channels, _depth);
53 | if(num < 0)
54 | throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
55 | byte[] a = new byte[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