Java API:
* fixed manually ported classes; * added vector<vector<Point>> support; * changed argument types for 3 functions; * finished tests for org.opencv.core.Core class.
This commit is contained in:
@@ -416,9 +416,9 @@ JNIEXPORT jstring JNICALL Java_org_opencv_highgui_VideoCapture_n_1getSupportedPr
|
||||
LOGD("highgui::VideoCapture_n_1set()");
|
||||
#endif // DEBUG
|
||||
VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
|
||||
double addr = me->get(CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING);
|
||||
char* result = *((char**)&addr);
|
||||
return env->NewStringUTF(result);
|
||||
union {double prop; const char* name;} u;
|
||||
u.prop = me->get(CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING);
|
||||
return env->NewStringUTF(u.name);
|
||||
} catch(cv::Exception e) {
|
||||
#ifdef DEBUG
|
||||
LOGD("highgui::VideoCapture_n_1getSupportedPreviewSizes() catched cv::Exception: %s", e.what());
|
||||
|
@@ -264,6 +264,19 @@ void vector_DMatch_to_Mat(vector<DMatch>& v_dm, Mat& mat)
|
||||
}
|
||||
}
|
||||
|
||||
void Mat_to_vector_vector_Point(Mat& mat, vector< vector< Point > >& vv_pt)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( mat.rows );
|
||||
Mat_to_vector_Mat(mat, vm);
|
||||
for(size_t i=0; i<vm.size(); i++)
|
||||
{
|
||||
vector<Point> vpt;
|
||||
Mat_to_vector_Point(vm[i], vpt);
|
||||
vv_pt.push_back(vpt);
|
||||
}
|
||||
}
|
||||
|
||||
void Mat_to_vector_vector_KeyPoint(Mat& mat, vector< vector< KeyPoint > >& vv_kp)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
|
@@ -55,3 +55,5 @@ void vector_vector_DMatch_to_Mat(std::vector< std::vector< cv::DMatch > >& vv_dm
|
||||
|
||||
void Mat_to_vector_vector_char(cv::Mat& mat, std::vector< std::vector< char > >& vv_ch);
|
||||
void vector_vector_char_to_Mat(std::vector< std::vector< char > >& vv_ch, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_vector_Point(cv::Mat& mat, std::vector< std::vector< cv::Point > >& vv_pt);
|
||||
|
@@ -1,15 +1,15 @@
|
||||
package org.opencv.core;
|
||||
|
||||
public class CvException extends RuntimeException {
|
||||
public class CvException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CvException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
public CvException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CvException [" + super.toString() + "]";
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CvException [" + super.toString() + "]";
|
||||
}
|
||||
}
|
||||
|
@@ -1,111 +1,136 @@
|
||||
package org.opencv.core;
|
||||
|
||||
|
||||
public final class CvType {
|
||||
|
||||
// type depth constants
|
||||
public static final int CV_8U = 0, CV_8S = 1,
|
||||
CV_16U = 2, CV_16S = 3,
|
||||
CV_32S = 4,
|
||||
CV_32F = 5,
|
||||
CV_64F = 6,
|
||||
CV_USRTYPE1=7;
|
||||
public static final int
|
||||
CV_8U = 0, CV_8S = 1,
|
||||
CV_16U = 2, CV_16S = 3,
|
||||
CV_32S = 4,
|
||||
CV_32F = 5,
|
||||
CV_64F = 6,
|
||||
CV_USRTYPE1 = 7;
|
||||
|
||||
// predefined type constants
|
||||
public static final int
|
||||
CV_8UC1 = CV_8UC(1), CV_8UC2 = CV_8UC(2), CV_8UC3 = CV_8UC(3), CV_8UC4 = CV_8UC(4),
|
||||
CV_8SC1 = CV_8SC(1), CV_8SC2 = CV_8SC(2), CV_8SC3 = CV_8SC(3), CV_8SC4 = CV_8SC(4),
|
||||
CV_16UC1 = CV_16UC(1), CV_16UC2 = CV_16UC(2), CV_16UC3 = CV_16UC(3), CV_16UC4 = CV_16UC(4),
|
||||
CV_16SC1 = CV_16SC(1), CV_16SC2 = CV_16SC(2), CV_16SC3 = CV_16SC(3), CV_16SC4 = CV_16SC(4),
|
||||
CV_32SC1 = CV_32SC(1), CV_32SC2 = CV_32SC(2), CV_32SC3 = CV_32SC(3), CV_32SC4 = CV_32SC(4),
|
||||
CV_32FC1 = CV_32FC(1), CV_32FC2 = CV_32FC(2), CV_32FC3 = CV_32FC(3), CV_32FC4 = CV_32FC(4),
|
||||
CV_64FC1 = CV_64FC(1), CV_64FC2 = CV_64FC(2), CV_64FC3 = CV_64FC(3), CV_64FC4 = CV_64FC(4);
|
||||
CV_8UC1 = CV_8UC(1), CV_8UC2 = CV_8UC(2), CV_8UC3 = CV_8UC(3), CV_8UC4 = CV_8UC(4),
|
||||
CV_8SC1 = CV_8SC(1), CV_8SC2 = CV_8SC(2), CV_8SC3 = CV_8SC(3), CV_8SC4 = CV_8SC(4),
|
||||
CV_16UC1 = CV_16UC(1), CV_16UC2 = CV_16UC(2), CV_16UC3 = CV_16UC(3), CV_16UC4 = CV_16UC(4),
|
||||
CV_16SC1 = CV_16SC(1), CV_16SC2 = CV_16SC(2), CV_16SC3 = CV_16SC(3), CV_16SC4 = CV_16SC(4),
|
||||
CV_32SC1 = CV_32SC(1), CV_32SC2 = CV_32SC(2), CV_32SC3 = CV_32SC(3), CV_32SC4 = CV_32SC(4),
|
||||
CV_32FC1 = CV_32FC(1), CV_32FC2 = CV_32FC(2), CV_32FC3 = CV_32FC(3), CV_32FC4 = CV_32FC(4),
|
||||
CV_64FC1 = CV_64FC(1), CV_64FC2 = CV_64FC(2), CV_64FC3 = CV_64FC(3), CV_64FC4 = CV_64FC(4);
|
||||
|
||||
private static final int CV_CN_MAX = 512, CV_CN_SHIFT = 3, CV_DEPTH_MAX = (1 << CV_CN_SHIFT);
|
||||
|
||||
public static final int makeType(int depth, int channels) {
|
||||
if(channels<=0 || channels>=CV_CN_MAX) {
|
||||
if (channels <= 0 || channels >= CV_CN_MAX) {
|
||||
throw new java.lang.UnsupportedOperationException(
|
||||
"Channels count should be 1.." + (CV_CN_MAX-1) );
|
||||
"Channels count should be 1.." + (CV_CN_MAX - 1));
|
||||
}
|
||||
if(depth<0 || depth>=CV_DEPTH_MAX) {
|
||||
if (depth < 0 || depth >= CV_DEPTH_MAX) {
|
||||
throw new java.lang.UnsupportedOperationException(
|
||||
"Data type depth should be 0.." + (CV_DEPTH_MAX-1) );
|
||||
"Data type depth should be 0.." + (CV_DEPTH_MAX - 1));
|
||||
}
|
||||
return (depth & (CV_DEPTH_MAX-1)) + ((channels-1) << CV_CN_SHIFT);
|
||||
return (depth & (CV_DEPTH_MAX - 1)) + ((channels - 1) << CV_CN_SHIFT);
|
||||
}
|
||||
|
||||
public static final int CV_8UC(int ch) {
|
||||
return makeType(CV_8U, ch);
|
||||
}
|
||||
|
||||
public static final int CV_8UC(int ch) { return makeType(CV_8U, ch); }
|
||||
public static final int CV_8SC(int ch) {
|
||||
return makeType(CV_8S, ch);
|
||||
}
|
||||
|
||||
public static final int CV_8SC(int ch) { return makeType(CV_8S, ch); }
|
||||
public static final int CV_16UC(int ch) {
|
||||
return makeType(CV_16U, ch);
|
||||
}
|
||||
|
||||
public static final int CV_16UC(int ch) { return makeType(CV_16U, ch); }
|
||||
public static final int CV_16SC(int ch) {
|
||||
return makeType(CV_16S, ch);
|
||||
}
|
||||
|
||||
public static final int CV_16SC(int ch) { return makeType(CV_16S, ch); }
|
||||
public static final int CV_32SC(int ch) {
|
||||
return makeType(CV_32S, ch);
|
||||
}
|
||||
|
||||
public static final int CV_32SC(int ch) { return makeType(CV_32S, ch); }
|
||||
public static final int CV_32FC(int ch) {
|
||||
return makeType(CV_32F, ch);
|
||||
}
|
||||
|
||||
public static final int CV_32FC(int ch) { return makeType(CV_32F, ch); }
|
||||
public static final int CV_64FC(int ch) {
|
||||
return makeType(CV_64F, ch);
|
||||
}
|
||||
|
||||
public static final int CV_64FC(int ch) { return makeType(CV_64F, ch); }
|
||||
public static final int channels(int type) {
|
||||
return (type >> CV_CN_SHIFT) + 1;
|
||||
}
|
||||
|
||||
public static final int channels(int type) { return (type >> CV_CN_SHIFT) + 1; }
|
||||
public static final int depth(int type) {
|
||||
return type & (CV_DEPTH_MAX - 1);
|
||||
}
|
||||
|
||||
public static final int depth(int type) { return type & (CV_DEPTH_MAX-1); }
|
||||
|
||||
public static final boolean isInteger(int type) { return depth(type) < CV_32F; }
|
||||
public static final boolean isInteger(int type) {
|
||||
return depth(type) < CV_32F;
|
||||
}
|
||||
|
||||
public static final int ELEM_SIZE(int type) {
|
||||
switch (depth(type)) {
|
||||
case CV_8U:
|
||||
case CV_8S:
|
||||
return channels(type);
|
||||
case CV_16U:
|
||||
case CV_16S:
|
||||
return 2 * channels(type);
|
||||
case CV_32S:
|
||||
case CV_32F:
|
||||
return 4 * channels(type);
|
||||
case CV_64F:
|
||||
return 8 * channels(type);
|
||||
default:
|
||||
throw new java.lang.UnsupportedOperationException(
|
||||
"Unsupported CvType value: " + type );
|
||||
case CV_8U:
|
||||
case CV_8S:
|
||||
return channels(type);
|
||||
case CV_16U:
|
||||
case CV_16S:
|
||||
return 2 * channels(type);
|
||||
case CV_32S:
|
||||
case CV_32F:
|
||||
return 4 * channels(type);
|
||||
case CV_64F:
|
||||
return 8 * channels(type);
|
||||
default:
|
||||
throw new java.lang.UnsupportedOperationException(
|
||||
"Unsupported CvType value: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
public static final String typeToString(int type) {
|
||||
String s;
|
||||
switch (depth(type)) {
|
||||
case CV_8U:
|
||||
s = "CV_8U";
|
||||
break;
|
||||
case CV_8S:
|
||||
s = "CV_8S";
|
||||
break;
|
||||
case CV_16U:
|
||||
s = "CV_16U";
|
||||
break;
|
||||
case CV_16S:
|
||||
s = "CV_16S";
|
||||
break;
|
||||
case CV_32S:
|
||||
s = "CV_32S";
|
||||
break;
|
||||
case CV_32F:
|
||||
s = "CV_32F";
|
||||
break;
|
||||
case CV_64F:
|
||||
s = "CV_64F";
|
||||
break;
|
||||
default:
|
||||
s = "CV_USRTYPE1";
|
||||
case CV_8U:
|
||||
s = "CV_8U";
|
||||
break;
|
||||
case CV_8S:
|
||||
s = "CV_8S";
|
||||
break;
|
||||
case CV_16U:
|
||||
s = "CV_16U";
|
||||
break;
|
||||
case CV_16S:
|
||||
s = "CV_16S";
|
||||
break;
|
||||
case CV_32S:
|
||||
s = "CV_32S";
|
||||
break;
|
||||
case CV_32F:
|
||||
s = "CV_32F";
|
||||
break;
|
||||
case CV_64F:
|
||||
s = "CV_64F";
|
||||
break;
|
||||
case CV_USRTYPE1:
|
||||
s = "CV_USRTYPE1";
|
||||
break;
|
||||
default:
|
||||
throw new java.lang.UnsupportedOperationException(
|
||||
"Unsupported CvType value: " + type);
|
||||
}
|
||||
|
||||
int ch = channels(type);
|
||||
if(ch<=4) return s + "C" + ch;
|
||||
else return s + "C(" + ch + ")";
|
||||
if (ch <= 4)
|
||||
return s + "C" + ch;
|
||||
else
|
||||
return s + "C(" + ch + ")";
|
||||
}
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -18,17 +18,17 @@ public class Point {
|
||||
this();
|
||||
set(vals);
|
||||
}
|
||||
|
||||
public void set(double[] vals) {
|
||||
if(vals!=null) {
|
||||
x = vals.length>0 ? vals[0] : 0;
|
||||
y = vals.length>1 ? vals[1] : 0;
|
||||
if (vals != null) {
|
||||
x = vals.length > 0 ? vals[0] : 0;
|
||||
y = vals.length > 1 ? vals[1] : 0;
|
||||
} else {
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Point clone() {
|
||||
return new Point(x, y);
|
||||
}
|
||||
@@ -52,7 +52,7 @@ public class Point {
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if ( ! (obj instanceof Point) ) return false;
|
||||
if (!(obj instanceof Point)) return false;
|
||||
Point it = (Point) obj;
|
||||
return x == it.x && y == it.y;
|
||||
}
|
||||
@@ -61,10 +61,8 @@ public class Point {
|
||||
return r.contains(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this == null) return "null";
|
||||
return "{" + x + ", " + y + "}";
|
||||
}
|
||||
}
|
||||
|
@@ -25,16 +25,17 @@ public class Point3 {
|
||||
this();
|
||||
set(vals);
|
||||
}
|
||||
|
||||
public void set(double[] vals) {
|
||||
if(vals!=null) {
|
||||
x = vals.length>0 ? vals[0] : 0;
|
||||
y = vals.length>1 ? vals[1] : 0;
|
||||
z = vals.length>2 ? vals[2] : 0;
|
||||
if (vals != null) {
|
||||
x = vals.length > 0 ? vals[0] : 0;
|
||||
y = vals.length > 1 ? vals[1] : 0;
|
||||
z = vals.length > 2 ? vals[2] : 0;
|
||||
} else {
|
||||
x = 0;
|
||||
y = 0;
|
||||
z = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Point3 clone() {
|
||||
@@ -70,4 +71,9 @@ public class Point3 {
|
||||
Point3 it = (Point3) obj;
|
||||
return x == it.x && y == it.y && z == it.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{" + x + ", " + y + ", " + z + "}";
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@ package org.opencv.core;
|
||||
|
||||
//javadoc:Range
|
||||
public class Range {
|
||||
|
||||
|
||||
public int start, end;
|
||||
|
||||
public Range(int s, int e) {
|
||||
@@ -13,31 +13,32 @@ public class Range {
|
||||
public Range() {
|
||||
this(0, 0);
|
||||
}
|
||||
|
||||
public Range(double[] vals) {
|
||||
this();
|
||||
set(vals);
|
||||
}
|
||||
|
||||
public void set(double[] vals) {
|
||||
if(vals!=null) {
|
||||
start = vals.length>0 ? (int)vals[0] : 0;
|
||||
end = vals.length>1 ? (int)vals[1] : 0;
|
||||
if (vals != null) {
|
||||
start = vals.length > 0 ? (int) vals[0] : 0;
|
||||
end = vals.length > 1 ? (int) vals[1] : 0;
|
||||
} else {
|
||||
start = 0;
|
||||
end = 0;
|
||||
}
|
||||
end = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return end-start;
|
||||
return empty() ? 0 : end - start;
|
||||
}
|
||||
|
||||
public boolean empty() {
|
||||
return start==end;
|
||||
return end <= start;
|
||||
}
|
||||
|
||||
public static Range all() {
|
||||
return new Range(Integer.MIN_VALUE , Integer.MAX_VALUE);
|
||||
return new Range(Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public Range intersection(Range r1) {
|
||||
@@ -45,15 +46,15 @@ public class Range {
|
||||
r.end = Math.max(r.end, r.start);
|
||||
return r;
|
||||
}
|
||||
|
||||
public Range shift(int delta) {
|
||||
return new Range(start+delta, end+delta);
|
||||
return new Range(start + delta, end + delta);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Range clone() {
|
||||
return new Range(start, end);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
@@ -76,7 +77,6 @@ public class Range {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this == null) return "null";
|
||||
return "[" + start + ", " + end + ")";
|
||||
}
|
||||
}
|
||||
|
@@ -24,25 +24,25 @@ public class Rect {
|
||||
}
|
||||
|
||||
public Rect(Point p, Size s) {
|
||||
this((int)p.x, (int)p.y, (int)s.width, (int)s.height);
|
||||
this((int) p.x, (int) p.y, (int) s.width, (int) s.height);
|
||||
}
|
||||
|
||||
public Rect(double[] vals) {
|
||||
this();
|
||||
set(vals);
|
||||
}
|
||||
|
||||
public void set(double[] vals) {
|
||||
if(vals!=null) {
|
||||
x = vals.length>0 ? (int)vals[0] : 0;
|
||||
y = vals.length>1 ? (int)vals[1] : 0;
|
||||
width = vals.length>2 ? (int)vals[2] : 0;
|
||||
height = vals.length>3 ? (int)vals[3] : 0;
|
||||
if (vals != null) {
|
||||
x = vals.length > 0 ? (int) vals[0] : 0;
|
||||
y = vals.length > 1 ? (int) vals[1] : 0;
|
||||
width = vals.length > 2 ? (int) vals[2] : 0;
|
||||
height = vals.length > 3 ? (int) vals[3] : 0;
|
||||
} else {
|
||||
x = 0;
|
||||
y = 0;
|
||||
width = 0;
|
||||
x = 0;
|
||||
y = 0;
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Rect clone() {
|
||||
@@ -95,7 +95,6 @@ public class Rect {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this == null) return "null";
|
||||
return "{" + x + ", " + y + ", " + width + "x" + height+"}";
|
||||
return "{" + x + ", " + y + ", " + width + "x" + height + "}";
|
||||
}
|
||||
}
|
||||
|
@@ -23,54 +23,54 @@ public class RotatedRect {
|
||||
this();
|
||||
set(vals);
|
||||
}
|
||||
|
||||
|
||||
public void set(double[] vals) {
|
||||
if(vals!=null) {
|
||||
center.x = vals.length>0 ? (double)vals[0] : 0;
|
||||
center.y = vals.length>1 ? (double)vals[1] : 0;
|
||||
size.width = vals.length>2 ? (double)vals[2] : 0;
|
||||
size.height = vals.length>3 ? (double)vals[3] : 0;
|
||||
angle = vals.length>4 ? (double)vals[4] : 0;
|
||||
if (vals != null) {
|
||||
center.x = vals.length > 0 ? (double) vals[0] : 0;
|
||||
center.y = vals.length > 1 ? (double) vals[1] : 0;
|
||||
size.width = vals.length > 2 ? (double) vals[2] : 0;
|
||||
size.height = vals.length > 3 ? (double) vals[3] : 0;
|
||||
angle = vals.length > 4 ? (double) vals[4] : 0;
|
||||
} else {
|
||||
center.x = 0;
|
||||
center.x = 0;
|
||||
size.width = 0;
|
||||
center.x = 0;
|
||||
center.x = 0;
|
||||
size.width = 0;
|
||||
size.height = 0;
|
||||
angle = 0;
|
||||
angle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void points(Point pt[])
|
||||
{
|
||||
double _angle = angle*Math.PI/180.0;
|
||||
double b = (double)Math.cos(_angle)*0.5f;
|
||||
double a = (double)Math.sin(_angle)*0.5f;
|
||||
double _angle = angle * Math.PI / 180.0;
|
||||
double b = (double) Math.cos(_angle) * 0.5f;
|
||||
double a = (double) Math.sin(_angle) * 0.5f;
|
||||
|
||||
pt[0] = new Point(
|
||||
center.x - a*size.height - b*size.width,
|
||||
center.y + b*size.height - a*size.width);
|
||||
center.x - a * size.height - b * size.width,
|
||||
center.y + b * size.height - a * size.width);
|
||||
|
||||
pt[1] = new Point(
|
||||
center.x + a*size.height - b*size.width,
|
||||
center.y - b*size.height - a*size.width);
|
||||
center.x + a * size.height - b * size.width,
|
||||
center.y - b * size.height - a * size.width);
|
||||
|
||||
pt[2] = new Point(
|
||||
2*center.x - pt[0].x,
|
||||
2*center.y - pt[0].y);
|
||||
2 * center.x - pt[0].x,
|
||||
2 * center.y - pt[0].y);
|
||||
|
||||
pt[3] = new Point(
|
||||
2*center.x - pt[1].x,
|
||||
2*center.y - pt[1].y);
|
||||
2 * center.x - pt[1].x,
|
||||
2 * center.y - pt[1].y);
|
||||
}
|
||||
|
||||
public Rect boundingRect()
|
||||
{
|
||||
Point pt[] = new Point[4];
|
||||
points(pt);
|
||||
Rect r=new Rect((int)Math.floor(Math.min(Math.min(Math.min(pt[0].x, pt[1].x), pt[2].x), pt[3].x)),
|
||||
(int)Math.floor(Math.min(Math.min(Math.min(pt[0].y, pt[1].y), pt[2].y), pt[3].y)),
|
||||
(int)Math.ceil(Math.max(Math.max(Math.max(pt[0].x, pt[1].x), pt[2].x), pt[3].x)),
|
||||
(int)Math.ceil(Math.max(Math.max(Math.max(pt[0].y, pt[1].y), pt[2].y), pt[3].y)));
|
||||
Rect r = new Rect((int) Math.floor(Math.min(Math.min(Math.min(pt[0].x, pt[1].x), pt[2].x), pt[3].x)),
|
||||
(int) Math.floor(Math.min(Math.min(Math.min(pt[0].y, pt[1].y), pt[2].y), pt[3].y)),
|
||||
(int) Math.ceil(Math.max(Math.max(Math.max(pt[0].x, pt[1].x), pt[2].x), pt[3].x)),
|
||||
(int) Math.ceil(Math.max(Math.max(Math.max(pt[0].y, pt[1].y), pt[2].y), pt[3].y)));
|
||||
r.width -= r.x - 1;
|
||||
r.height -= r.y - 1;
|
||||
return r;
|
||||
@@ -105,4 +105,9 @@ public class RotatedRect {
|
||||
RotatedRect it = (RotatedRect) obj;
|
||||
return center.equals(it.center) && size.equals(it.size) && angle == it.angle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{ " + center + " " + size + " * " + angle + " }";
|
||||
}
|
||||
}
|
||||
|
@@ -6,34 +6,40 @@ public class Scalar {
|
||||
public double val[];
|
||||
|
||||
public Scalar(double v0, double v1, double v2, double v3) {
|
||||
this.val = new double[] {v0, v1, v2, v3};
|
||||
val = new double[] { v0, v1, v2, v3 };
|
||||
}
|
||||
|
||||
public Scalar(double v0, double v1, double v2) {
|
||||
this.val = new double[] {v0, v1, v2, 0};
|
||||
val = new double[] { v0, v1, v2, 0 };
|
||||
}
|
||||
|
||||
public Scalar(double v0, double v1) {
|
||||
this.val = new double[] {v0, v1, 0, 0};
|
||||
val = new double[] { v0, v1, 0, 0 };
|
||||
}
|
||||
|
||||
public Scalar(double v0) {
|
||||
this.val = new double[] {v0, 0, 0, 0};
|
||||
val = new double[] { v0, 0, 0, 0 };
|
||||
}
|
||||
|
||||
public Scalar(double[] vals) {
|
||||
this.val = new double[4];
|
||||
set(vals);
|
||||
}
|
||||
public void set(double[] vals) {
|
||||
if(vals!=null) {
|
||||
this.val[0] = vals.length>0 ? vals[0] : 0;
|
||||
this.val[1] = vals.length>1 ? vals[1] : 0;
|
||||
this.val[2] = vals.length>2 ? vals[2] : 0;
|
||||
this.val[3] = vals.length>3 ? vals[3] : 0;
|
||||
if (vals != null && vals.length == 4)
|
||||
val = vals.clone();
|
||||
else {
|
||||
val = new double[4];
|
||||
set(vals);
|
||||
}
|
||||
}
|
||||
|
||||
public void set(double[] vals) {
|
||||
if (vals != null) {
|
||||
val[0] = vals.length > 0 ? vals[0] : 0;
|
||||
val[1] = vals.length > 1 ? vals[1] : 0;
|
||||
val[2] = vals.length > 2 ? vals[2] : 0;
|
||||
val[3] = vals.length > 3 ? vals[3] : 0;
|
||||
} else
|
||||
val[0] = val[1] = val[2] = val[3] = 0;
|
||||
}
|
||||
|
||||
public static Scalar all(double v) {
|
||||
return new Scalar(v, v, v, v);
|
||||
}
|
||||
@@ -43,13 +49,14 @@ public class Scalar {
|
||||
}
|
||||
|
||||
public Scalar mul(Scalar it, double scale) {
|
||||
return new Scalar( val[0] * it.val[0] * scale, val[1] * it.val[1] * scale,
|
||||
val[2] * it.val[2] * scale, val[3] * it.val[3] * scale );
|
||||
return new Scalar(val[0] * it.val[0] * scale, val[1] * it.val[1] * scale,
|
||||
val[2] * it.val[2] * scale, val[3] * it.val[3] * scale);
|
||||
}
|
||||
|
||||
public Scalar mul(Scalar it) {
|
||||
return mul(it, 1);
|
||||
}
|
||||
|
||||
public Scalar conj() {
|
||||
return new Scalar(val[0], -val[1], -val[2], -val[3]);
|
||||
}
|
||||
@@ -58,22 +65,26 @@ public class Scalar {
|
||||
return val[1] == 0 && val[2] == 0 && val[3] == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + java.util.Arrays.hashCode(val);
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + java.util.Arrays.hashCode(val);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Scalar)) return false;
|
||||
Scalar it = (Scalar) obj;
|
||||
if (!java.util.Arrays.equals(val, it.val)) return false;
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Scalar)) return false;
|
||||
Scalar it = (Scalar) obj;
|
||||
if (!java.util.Arrays.equals(val, it.val)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[" + val[0] + ", " + val[1] + ", " + val[2] + ", " + val[3] + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -15,20 +15,20 @@ public class Size {
|
||||
}
|
||||
|
||||
public Size(Point p) {
|
||||
width = (double) p.x;
|
||||
height = (double) p.y;
|
||||
width = p.x;
|
||||
height = p.y;
|
||||
}
|
||||
|
||||
public Size(double[] vals) {
|
||||
this();
|
||||
set(vals);
|
||||
}
|
||||
|
||||
public void set(double[] vals) {
|
||||
if(vals!=null) {
|
||||
width = vals.length>0 ? vals[0] : 0;
|
||||
height = vals.length>1 ? vals[1] : 0;
|
||||
if (vals != null) {
|
||||
width = vals.length > 0 ? vals[0] : 0;
|
||||
height = vals.length > 1 ? vals[1] : 0;
|
||||
} else {
|
||||
width = 0;
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
}
|
||||
@@ -61,4 +61,9 @@ public class Size {
|
||||
return width == it.width && height == it.height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return (int)width + "x" + (int)height;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -3,33 +3,59 @@ package org.opencv.core;
|
||||
//javadoc:TermCriteria
|
||||
public class TermCriteria {
|
||||
|
||||
/**
|
||||
* the maximum number of iterations or elements to compute
|
||||
*/
|
||||
public static final int COUNT = 1;
|
||||
/**
|
||||
* the maximum number of iterations or elements to compute
|
||||
*/
|
||||
public static final int MAX_ITER = COUNT;
|
||||
/**
|
||||
* the desired accuracy or change in parameters at which the iterative algorithm stops
|
||||
*/
|
||||
public static final int EPS = 2;
|
||||
|
||||
public int type;
|
||||
public int maxCount;
|
||||
public double epsilon;
|
||||
|
||||
public TermCriteria(int t, int c, double e) {
|
||||
this.type = t;
|
||||
this.maxCount = c;
|
||||
this.epsilon = e;
|
||||
/**
|
||||
* Termination criteria in iterative algorithms
|
||||
*
|
||||
* @param type
|
||||
* the type of termination criteria: COUNT, EPS or COUNT + EPS
|
||||
* @param maxCount
|
||||
* the maximum number of iterations/elements
|
||||
* @param epsilon
|
||||
* the desired accuracy
|
||||
*/
|
||||
public TermCriteria(int type, int maxCount, double epsilon) {
|
||||
this.type = type;
|
||||
this.maxCount = maxCount;
|
||||
this.epsilon = epsilon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Termination criteria in iterative algorithms
|
||||
*/
|
||||
public TermCriteria() {
|
||||
this(0, 0, 0.0);
|
||||
}
|
||||
|
||||
public TermCriteria(double[] vals) {
|
||||
this();
|
||||
set(vals);
|
||||
}
|
||||
|
||||
public void set(double[] vals) {
|
||||
if(vals!=null) {
|
||||
type = vals.length>0 ? (int)vals[0] : 0;
|
||||
maxCount = vals.length>1 ? (int)vals[1] : 0;
|
||||
epsilon = vals.length>2 ? (double)vals[2] : 0;
|
||||
if (vals != null) {
|
||||
type = vals.length > 0 ? (int) vals[0] : 0;
|
||||
maxCount = vals.length > 1 ? (int) vals[1] : 0;
|
||||
epsilon = vals.length > 2 ? (double) vals[2] : 0;
|
||||
} else {
|
||||
type = 0;
|
||||
maxCount = 0;
|
||||
epsilon = 0;
|
||||
type = 0;
|
||||
maxCount = 0;
|
||||
epsilon = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +82,7 @@ public class TermCriteria {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof TermCriteria)) return false;
|
||||
TermCriteria it = (TermCriteria) obj;
|
||||
return type == it.type && maxCount == it.maxCount && epsilon== it.epsilon;
|
||||
return type == it.type && maxCount == it.maxCount && epsilon == it.epsilon;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,50 +1,61 @@
|
||||
package org.opencv.features2d;
|
||||
|
||||
//C++: class DMatch
|
||||
//javadoc: DMatch
|
||||
|
||||
/**
|
||||
* Struct for matching: query descriptor index, train descriptor index, train
|
||||
* image index and distance between descriptors.
|
||||
*/
|
||||
public class DMatch {
|
||||
|
||||
//javadoc: DMatch::queryIdx
|
||||
public int queryIdx;
|
||||
//javadoc: DMatch::trainIdx
|
||||
public int trainIdx;
|
||||
//javadoc: DMatch::imgIdx
|
||||
public int imgIdx;
|
||||
//javadoc: DMatch::distance
|
||||
public float distance;
|
||||
|
||||
|
||||
//javadoc: DMatch::DMatch()
|
||||
|
||||
/**
|
||||
* query descriptor index
|
||||
*/
|
||||
public int queryIdx;
|
||||
/**
|
||||
* train descriptor index
|
||||
*/
|
||||
public int trainIdx;
|
||||
/**
|
||||
* train image index
|
||||
*/
|
||||
public int imgIdx;
|
||||
|
||||
// javadoc: DMatch::distance
|
||||
public float distance;
|
||||
|
||||
// javadoc: DMatch::DMatch()
|
||||
public DMatch() {
|
||||
this(-1, -1, Float.MAX_VALUE);
|
||||
}
|
||||
|
||||
|
||||
public DMatch( int _queryIdx, int _trainIdx, float _distance ) {
|
||||
queryIdx = _queryIdx;
|
||||
trainIdx = _trainIdx;
|
||||
imgIdx = -1;
|
||||
distance = _distance;
|
||||
}
|
||||
|
||||
|
||||
public DMatch( int _queryIdx, int _trainIdx, int _imgIdx, float _distance ) {
|
||||
queryIdx = _queryIdx;
|
||||
trainIdx = _trainIdx;
|
||||
imgIdx = _imgIdx;
|
||||
distance = _distance;
|
||||
this(-1, -1, Float.MAX_VALUE);
|
||||
}
|
||||
|
||||
// less is better
|
||||
// javadoc: DMatch::DMatch(_queryIdx, _trainIdx, _distance)
|
||||
public DMatch(int _queryIdx, int _trainIdx, float _distance) {
|
||||
queryIdx = _queryIdx;
|
||||
trainIdx = _trainIdx;
|
||||
imgIdx = -1;
|
||||
distance = _distance;
|
||||
}
|
||||
|
||||
// javadoc: DMatch::DMatch(_queryIdx, _trainIdx, _imgIdx, _distance)
|
||||
public DMatch(int _queryIdx, int _trainIdx, int _imgIdx, float _distance) {
|
||||
queryIdx = _queryIdx;
|
||||
trainIdx = _trainIdx;
|
||||
imgIdx = _imgIdx;
|
||||
distance = _distance;
|
||||
}
|
||||
|
||||
/**
|
||||
* less is better
|
||||
*/
|
||||
boolean lessThan(DMatch it) {
|
||||
return distance < it.distance;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DMatch [queryIdx=" + queryIdx + ", trainIdx=" + trainIdx
|
||||
+ ", imgIdx=" + imgIdx + ", distance=" + distance + "]";
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DMatch [queryIdx=" + queryIdx + ", trainIdx=" + trainIdx
|
||||
+ ", imgIdx=" + imgIdx + ", distance=" + distance + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -4,66 +4,80 @@ import org.opencv.core.Point;
|
||||
|
||||
//javadoc: KeyPoint
|
||||
public class KeyPoint {
|
||||
|
||||
//javadoc: KeyPoint::pt
|
||||
public Point pt;
|
||||
//javadoc: KeyPoint::size
|
||||
public float size;
|
||||
//javadoc: KeyPoint::angle
|
||||
public float angle;
|
||||
//javadoc: KeyPoint::response
|
||||
public float response;
|
||||
//javadoc: KeyPoint::octave
|
||||
public int octave;
|
||||
//javadoc: KeyPoint::class_id
|
||||
public int class_id;
|
||||
|
||||
//javadoc: KeyPoint::KeyPoint(x, y, _size, _angle, _response, _octave, _class_id)
|
||||
/**
|
||||
* coordinates of the keypoint
|
||||
*/
|
||||
public Point pt;
|
||||
/**
|
||||
* diameter of the meaningful keypoint neighborhood
|
||||
*/
|
||||
public float size;
|
||||
/**
|
||||
* computed orientation of the keypoint (-1 if not applicable)
|
||||
*/
|
||||
public float angle;
|
||||
/**
|
||||
* the response by which the most strong keypoints have been selected. Can
|
||||
* be used for further sorting or subsampling
|
||||
*/
|
||||
public float response;
|
||||
/**
|
||||
* octave (pyramid layer) from which the keypoint has been extracted
|
||||
*/
|
||||
public int octave;
|
||||
/**
|
||||
* object id that can be used to clustered keypoints by an object they
|
||||
* belong to
|
||||
*/
|
||||
public int class_id;
|
||||
|
||||
// javadoc:KeyPoint::KeyPoint(x,y,_size,_angle,_response,_octave,_class_id)
|
||||
public KeyPoint(float x, float y, float _size, float _angle, float _response, int _octave, int _class_id)
|
||||
{
|
||||
pt = new Point(x, y);
|
||||
size = _size;
|
||||
angle = _angle;
|
||||
response = _response;
|
||||
octave = _octave;
|
||||
class_id = _class_id;
|
||||
pt = new Point(x, y);
|
||||
size = _size;
|
||||
angle = _angle;
|
||||
response = _response;
|
||||
octave = _octave;
|
||||
class_id = _class_id;
|
||||
}
|
||||
|
||||
//javadoc: KeyPoint::KeyPoint()
|
||||
// javadoc: KeyPoint::KeyPoint()
|
||||
public KeyPoint()
|
||||
{
|
||||
this(0, 0, 0, -1, 0, 0, -1);
|
||||
this(0, 0, 0, -1, 0, 0, -1);
|
||||
}
|
||||
|
||||
//javadoc: KeyPoint::KeyPoint(x, y, _size, _angle, _response, _octave)
|
||||
// javadoc: KeyPoint::KeyPoint(x, y, _size, _angle, _response, _octave)
|
||||
public KeyPoint(float x, float y, float _size, float _angle, float _response, int _octave)
|
||||
{
|
||||
this(x, y, _size, _angle, _response, _octave, -1);
|
||||
this(x, y, _size, _angle, _response, _octave, -1);
|
||||
}
|
||||
|
||||
//javadoc: KeyPoint::KeyPoint(x, y, _size, _angle, _response)
|
||||
// javadoc: KeyPoint::KeyPoint(x, y, _size, _angle, _response)
|
||||
public KeyPoint(float x, float y, float _size, float _angle, float _response)
|
||||
{
|
||||
this(x, y, _size, _angle, _response, 0, -1);
|
||||
this(x, y, _size, _angle, _response, 0, -1);
|
||||
}
|
||||
|
||||
//javadoc: KeyPoint::KeyPoint(x, y, _size, _angle)
|
||||
// javadoc: KeyPoint::KeyPoint(x, y, _size, _angle)
|
||||
public KeyPoint(float x, float y, float _size, float _angle)
|
||||
{
|
||||
this(x, y, _size, _angle, 0, 0, -1);
|
||||
this(x, y, _size, _angle, 0, 0, -1);
|
||||
}
|
||||
|
||||
//javadoc: KeyPoint::KeyPoint(x, y, _size)
|
||||
// javadoc: KeyPoint::KeyPoint(x, y, _size)
|
||||
public KeyPoint(float x, float y, float _size)
|
||||
{
|
||||
this(x, y, _size, -1, 0, 0, -1);
|
||||
this(x, y, _size, -1, 0, 0, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "KeyPoint [pt=" + pt + ", size=" + size + ", angle=" + angle
|
||||
+ ", response=" + response + ", octave=" + octave
|
||||
+ ", class_id=" + class_id + "]";
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "KeyPoint [pt=" + pt + ", size=" + size + ", angle=" + angle
|
||||
+ ", response=" + response + ", octave=" + octave
|
||||
+ ", class_id=" + class_id + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -11,172 +11,183 @@ import org.opencv.core.Size;
|
||||
public class VideoCapture {
|
||||
|
||||
protected final long nativeObj;
|
||||
protected VideoCapture(long addr) { nativeObj = addr; }
|
||||
|
||||
protected VideoCapture(long addr) {
|
||||
nativeObj = addr;
|
||||
}
|
||||
|
||||
//
|
||||
// C++: VideoCapture::VideoCapture()
|
||||
// C++: VideoCapture::VideoCapture()
|
||||
//
|
||||
|
||||
//javadoc: VideoCapture::VideoCapture()
|
||||
public VideoCapture()
|
||||
// javadoc: VideoCapture::VideoCapture()
|
||||
public VideoCapture()
|
||||
{
|
||||
|
||||
|
||||
nativeObj = n_VideoCapture();
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// C++: VideoCapture::VideoCapture(int device)
|
||||
// C++: VideoCapture::VideoCapture(int device)
|
||||
//
|
||||
|
||||
//javadoc: VideoCapture::VideoCapture(device)
|
||||
public VideoCapture(int device)
|
||||
// javadoc: VideoCapture::VideoCapture(device)
|
||||
public VideoCapture(int device)
|
||||
{
|
||||
|
||||
|
||||
nativeObj = n_VideoCapture(device);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// C++: double VideoCapture::get(int propId)
|
||||
// C++: double VideoCapture::get(int propId)
|
||||
//
|
||||
|
||||
//javadoc: VideoCapture::get(propId)
|
||||
public double get(int propId)
|
||||
/**
|
||||
* Returns the specified "VideoCapture" property
|
||||
*
|
||||
* Note: When querying a property that is not supported by the backend used by
|
||||
* the "VideoCapture" class, value 0 is returned.
|
||||
*
|
||||
* @param propId Property identifier. It can be one of the following:
|
||||
* * CV_CAP_PROP_FRAME_WIDTH Width of the frames in the video stream.
|
||||
* * CV_CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream.
|
||||
*
|
||||
* @see <a href="http://opencv.itseez.com/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-get">org.opencv.highgui.VideoCapture.get</a>
|
||||
*/
|
||||
public double get(int propId)
|
||||
{
|
||||
|
||||
|
||||
double retVal = n_get(nativeObj, propId);
|
||||
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public List<Size> getSupportedPreviewSizes()
|
||||
public List<Size> getSupportedPreviewSizes()
|
||||
{
|
||||
String[] sizes_str = n_getSupportedPreviewSizes(nativeObj).split(",");
|
||||
List<Size> sizes = new LinkedList<Size>();
|
||||
|
||||
for(String str : sizes_str){
|
||||
for (String str : sizes_str) {
|
||||
String[] wh = str.split("x");
|
||||
sizes.add(new Size(Double.parseDouble(wh[0]), Double.parseDouble(wh[1])));
|
||||
}
|
||||
|
||||
|
||||
return sizes;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// C++: bool VideoCapture::grab()
|
||||
// C++: bool VideoCapture::grab()
|
||||
//
|
||||
|
||||
//javadoc: VideoCapture::grab()
|
||||
public boolean grab()
|
||||
// javadoc: VideoCapture::grab()
|
||||
public boolean grab()
|
||||
{
|
||||
|
||||
|
||||
boolean retVal = n_grab(nativeObj);
|
||||
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// C++: bool VideoCapture::isOpened()
|
||||
// C++: bool VideoCapture::isOpened()
|
||||
//
|
||||
|
||||
//javadoc: VideoCapture::isOpened()
|
||||
public boolean isOpened()
|
||||
// javadoc: VideoCapture::isOpened()
|
||||
public boolean isOpened()
|
||||
{
|
||||
|
||||
|
||||
boolean retVal = n_isOpened(nativeObj);
|
||||
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// C++: bool VideoCapture::open(int device)
|
||||
// C++: bool VideoCapture::open(int device)
|
||||
//
|
||||
|
||||
//javadoc: VideoCapture::open(device)
|
||||
public boolean open(int device)
|
||||
// javadoc: VideoCapture::open(device)
|
||||
public boolean open(int device)
|
||||
{
|
||||
|
||||
|
||||
boolean retVal = n_open(nativeObj, device);
|
||||
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// C++: bool VideoCapture::read(Mat image)
|
||||
// C++: bool VideoCapture::read(Mat image)
|
||||
//
|
||||
|
||||
//javadoc: VideoCapture::read(image)
|
||||
public boolean read(Mat image)
|
||||
// javadoc: VideoCapture::read(image)
|
||||
public boolean read(Mat image)
|
||||
{
|
||||
|
||||
|
||||
boolean retVal = n_read(nativeObj, image.nativeObj);
|
||||
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// C++: void VideoCapture::release()
|
||||
// C++: void VideoCapture::release()
|
||||
//
|
||||
|
||||
//javadoc: VideoCapture::release()
|
||||
public void release()
|
||||
// javadoc: VideoCapture::release()
|
||||
public void release()
|
||||
{
|
||||
|
||||
|
||||
n_release(nativeObj);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// C++: bool VideoCapture::retrieve(Mat image, int channel = 0)
|
||||
// C++: bool VideoCapture::retrieve(Mat image, int channel = 0)
|
||||
//
|
||||
|
||||
//javadoc: VideoCapture::retrieve(image, channel)
|
||||
public boolean retrieve(Mat image, int channel)
|
||||
// javadoc: VideoCapture::retrieve(image, channel)
|
||||
public boolean retrieve(Mat image, int channel)
|
||||
{
|
||||
|
||||
|
||||
boolean retVal = n_retrieve(nativeObj, image.nativeObj, channel);
|
||||
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
//javadoc: VideoCapture::retrieve(image)
|
||||
public boolean retrieve(Mat image)
|
||||
// javadoc: VideoCapture::retrieve(image)
|
||||
public boolean retrieve(Mat image)
|
||||
{
|
||||
|
||||
|
||||
boolean retVal = n_retrieve(nativeObj, image.nativeObj);
|
||||
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// C++: bool VideoCapture::set(int propId, double value)
|
||||
// C++: bool VideoCapture::set(int propId, double value)
|
||||
//
|
||||
|
||||
//javadoc: VideoCapture::set(propId, value)
|
||||
public boolean set(int propId, double value)
|
||||
/**
|
||||
* Sets a property in the "VideoCapture".
|
||||
*
|
||||
* @param propId Property identifier. It can be one of the following:
|
||||
* * CV_CAP_PROP_FRAME_WIDTH Width of the frames in the video stream.
|
||||
* * CV_CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream.
|
||||
* @param value Value of the property.
|
||||
*
|
||||
* @see <a href="http://opencv.itseez.com/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-set">org.opencv.highgui.VideoCapture.set</a>
|
||||
*/
|
||||
public boolean set(int propId, double value)
|
||||
{
|
||||
|
||||
|
||||
boolean retVal = n_set(nativeObj, propId, value);
|
||||
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
n_delete(nativeObj);
|
||||
@@ -185,43 +196,46 @@ public class VideoCapture {
|
||||
|
||||
// native stuff
|
||||
|
||||
static { System.loadLibrary("opencv_java"); }
|
||||
static {
|
||||
System.loadLibrary("opencv_java");
|
||||
}
|
||||
|
||||
// C++: VideoCapture::VideoCapture()
|
||||
// C++: VideoCapture::VideoCapture()
|
||||
private static native long n_VideoCapture();
|
||||
|
||||
// C++: VideoCapture::VideoCapture(string filename)
|
||||
// C++: VideoCapture::VideoCapture(string filename)
|
||||
private static native long n_VideoCapture(java.lang.String filename);
|
||||
|
||||
// C++: VideoCapture::VideoCapture(int device)
|
||||
// C++: VideoCapture::VideoCapture(int device)
|
||||
private static native long n_VideoCapture(int device);
|
||||
|
||||
// C++: double VideoCapture::get(int propId)
|
||||
// C++: double VideoCapture::get(int propId)
|
||||
private static native double n_get(long nativeObj, int propId);
|
||||
|
||||
// C++: bool VideoCapture::grab()
|
||||
// C++: bool VideoCapture::grab()
|
||||
private static native boolean n_grab(long nativeObj);
|
||||
|
||||
// C++: bool VideoCapture::isOpened()
|
||||
// C++: bool VideoCapture::isOpened()
|
||||
private static native boolean n_isOpened(long nativeObj);
|
||||
|
||||
// C++: bool VideoCapture::open(string filename)
|
||||
// C++: bool VideoCapture::open(string filename)
|
||||
private static native boolean n_open(long nativeObj, java.lang.String filename);
|
||||
|
||||
// C++: bool VideoCapture::open(int device)
|
||||
// C++: bool VideoCapture::open(int device)
|
||||
private static native boolean n_open(long nativeObj, int device);
|
||||
|
||||
// C++: bool VideoCapture::read(Mat image)
|
||||
// C++: bool VideoCapture::read(Mat image)
|
||||
private static native boolean n_read(long nativeObj, long image_nativeObj);
|
||||
|
||||
// C++: void VideoCapture::release()
|
||||
// C++: void VideoCapture::release()
|
||||
private static native void n_release(long nativeObj);
|
||||
|
||||
// C++: bool VideoCapture::retrieve(Mat image, int channel = 0)
|
||||
// C++: bool VideoCapture::retrieve(Mat image, int channel = 0)
|
||||
private static native boolean n_retrieve(long nativeObj, long image_nativeObj, int channel);
|
||||
|
||||
private static native boolean n_retrieve(long nativeObj, long image_nativeObj);
|
||||
|
||||
// C++: bool VideoCapture::set(int propId, double value)
|
||||
// C++: bool VideoCapture::set(int propId, double value)
|
||||
private static native boolean n_set(long nativeObj, int propId, double value);
|
||||
|
||||
private static native String n_getSupportedPreviewSizes(long nativeObj);
|
||||
|
@@ -27,50 +27,47 @@ public class Converters {
|
||||
|
||||
public static Mat vector_Point_to_Mat(List<Point> pts, int typeDepth) {
|
||||
Mat res;
|
||||
int count = (pts!=null) ? pts.size() : 0;
|
||||
if(count>0){
|
||||
int count = (pts != null) ? pts.size() : 0;
|
||||
if (count > 0) {
|
||||
switch (typeDepth) {
|
||||
case CvType.CV_32S:
|
||||
{
|
||||
res = new Mat(count, 1, CvType.CV_32SC2);
|
||||
int[] buff = new int[count*2];
|
||||
for(int i=0; i<count; i++) {
|
||||
Point p = pts.get(i);
|
||||
buff[i*2] = (int)p.x;
|
||||
buff[i*2+1] = (int)p.y;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
case CvType.CV_32S: {
|
||||
res = new Mat(count, 1, CvType.CV_32SC2);
|
||||
int[] buff = new int[count * 2];
|
||||
for (int i = 0; i < count; i++) {
|
||||
Point p = pts.get(i);
|
||||
buff[i * 2] = (int) p.x;
|
||||
buff[i * 2 + 1] = (int) p.y;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
}
|
||||
break;
|
||||
|
||||
case CvType.CV_32F:
|
||||
{
|
||||
res = new Mat(count, 1, CvType.CV_32FC2);
|
||||
float[] buff = new float[count*2];
|
||||
for(int i=0; i<count; i++) {
|
||||
Point p = pts.get(i);
|
||||
buff[i*2] = (float)p.x;
|
||||
buff[i*2+1] = (float)p.y;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
case CvType.CV_32F: {
|
||||
res = new Mat(count, 1, CvType.CV_32FC2);
|
||||
float[] buff = new float[count * 2];
|
||||
for (int i = 0; i < count; i++) {
|
||||
Point p = pts.get(i);
|
||||
buff[i * 2] = (float) p.x;
|
||||
buff[i * 2 + 1] = (float) p.y;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
}
|
||||
break;
|
||||
|
||||
case CvType.CV_64F:
|
||||
{
|
||||
res = new Mat(count, 1, CvType.CV_64FC2);
|
||||
double[] buff = new double[count*2];
|
||||
for(int i=0; i<count; i++) {
|
||||
Point p = pts.get(i);
|
||||
buff[i*2] = p.x;
|
||||
buff[i*2+1] = p.y;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
case CvType.CV_64F: {
|
||||
res = new Mat(count, 1, CvType.CV_64FC2);
|
||||
double[] buff = new double[count * 2];
|
||||
for (int i = 0; i < count; i++) {
|
||||
Point p = pts.get(i);
|
||||
buff[i * 2] = p.x;
|
||||
buff[i * 2 + 1] = p.y;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("'typeDepth' can be CV_32S, CV_32F or CV_64F");
|
||||
default:
|
||||
throw new IllegalArgumentException("'typeDepth' can be CV_32S, CV_32F or CV_64F");
|
||||
}
|
||||
} else {
|
||||
res = new Mat();
|
||||
@@ -78,7 +75,6 @@ public class Converters {
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public static Mat vector_Point3i_to_Mat(List<Point3> pts) {
|
||||
return vector_Point3_to_Mat(pts, CvType.CV_32S);
|
||||
}
|
||||
@@ -93,53 +89,50 @@ public class Converters {
|
||||
|
||||
public static Mat vector_Point3_to_Mat(List<Point3> pts, int typeDepth) {
|
||||
Mat res;
|
||||
int count = (pts!=null) ? pts.size() : 0;
|
||||
if(count>0){
|
||||
switch (typeDepth){
|
||||
case CvType.CV_32S:
|
||||
{
|
||||
res = new Mat(count, 1, CvType.CV_32SC3);
|
||||
int[] buff = new int[count*3];
|
||||
for(int i=0; i<count; i++) {
|
||||
Point3 p = pts.get(i);
|
||||
buff[i*3] = (int)p.x;
|
||||
buff[i*3+1] = (int)p.y;
|
||||
buff[i*3+2] = (int)p.z;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
int count = (pts != null) ? pts.size() : 0;
|
||||
if (count > 0) {
|
||||
switch (typeDepth) {
|
||||
case CvType.CV_32S: {
|
||||
res = new Mat(count, 1, CvType.CV_32SC3);
|
||||
int[] buff = new int[count * 3];
|
||||
for (int i = 0; i < count; i++) {
|
||||
Point3 p = pts.get(i);
|
||||
buff[i * 3] = (int) p.x;
|
||||
buff[i * 3 + 1] = (int) p.y;
|
||||
buff[i * 3 + 2] = (int) p.z;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
}
|
||||
break;
|
||||
|
||||
case CvType.CV_32F:
|
||||
{
|
||||
res = new Mat(count, 1, CvType.CV_32FC3);
|
||||
float[] buff = new float[count*3];
|
||||
for(int i=0; i<count; i++) {
|
||||
Point3 p = pts.get(i);
|
||||
buff[i*3] = (float)p.x;
|
||||
buff[i*3+1] = (float)p.y;
|
||||
buff[i*3+2] = (float)p.z;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
case CvType.CV_32F: {
|
||||
res = new Mat(count, 1, CvType.CV_32FC3);
|
||||
float[] buff = new float[count * 3];
|
||||
for (int i = 0; i < count; i++) {
|
||||
Point3 p = pts.get(i);
|
||||
buff[i * 3] = (float) p.x;
|
||||
buff[i * 3 + 1] = (float) p.y;
|
||||
buff[i * 3 + 2] = (float) p.z;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
}
|
||||
break;
|
||||
|
||||
case CvType.CV_64F:
|
||||
{
|
||||
res = new Mat(count, 1, CvType.CV_64FC3);
|
||||
double[] buff = new double[count*3];
|
||||
for(int i=0; i<count; i++) {
|
||||
Point3 p = pts.get(i);
|
||||
buff[i*3] = p.x;
|
||||
buff[i*3+1] = p.y;
|
||||
buff[i*3+2] = p.z;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
case CvType.CV_64F: {
|
||||
res = new Mat(count, 1, CvType.CV_64FC3);
|
||||
double[] buff = new double[count * 3];
|
||||
for (int i = 0; i < count; i++) {
|
||||
Point3 p = pts.get(i);
|
||||
buff[i * 3] = p.x;
|
||||
buff[i * 3 + 1] = p.y;
|
||||
buff[i * 3 + 2] = p.z;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("'typeDepth' can be CV_32S, CV_32F or CV_64F");
|
||||
default:
|
||||
throw new IllegalArgumentException("'typeDepth' can be CV_32S, CV_32F or CV_64F");
|
||||
}
|
||||
} else {
|
||||
res = new Mat();
|
||||
@@ -154,42 +147,44 @@ public class Converters {
|
||||
public static void Mat_to_vector_Point2d(Mat m, List<Point> pts) {
|
||||
Mat_to_vector_Point(m, pts);
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_Point(Mat m, List<Point> pts) {
|
||||
if(pts == null)
|
||||
if (pts == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
int count = m.rows();
|
||||
int type = m.type();
|
||||
if(m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException( "Input Mat should have one column\n" + m );
|
||||
if (m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException("Input Mat should have one column\n" + m);
|
||||
|
||||
pts.clear();
|
||||
if(type == CvType.CV_32SC2) {
|
||||
int[] buff = new int[2*count];
|
||||
if (type == CvType.CV_32SC2) {
|
||||
int[] buff = new int[2 * count];
|
||||
m.get(0, 0, buff);
|
||||
for(int i=0; i<count; i++) {
|
||||
pts.add( new Point(buff[i*2], buff[i*2+1]) );
|
||||
for (int i = 0; i < count; i++) {
|
||||
pts.add(new Point(buff[i * 2], buff[i * 2 + 1]));
|
||||
}
|
||||
} else if(type == CvType.CV_32FC2){
|
||||
float[] buff = new float[2*count];
|
||||
} else if (type == CvType.CV_32FC2) {
|
||||
float[] buff = new float[2 * count];
|
||||
m.get(0, 0, buff);
|
||||
for(int i=0; i<count; i++) {
|
||||
pts.add( new Point(buff[i*2], buff[i*2+1]) );
|
||||
for (int i = 0; i < count; i++) {
|
||||
pts.add(new Point(buff[i * 2], buff[i * 2 + 1]));
|
||||
}
|
||||
} else if(type == CvType.CV_64FC2){
|
||||
double[] buff = new double[2*count];
|
||||
} else if (type == CvType.CV_64FC2) {
|
||||
double[] buff = new double[2 * count];
|
||||
m.get(0, 0, buff);
|
||||
for(int i=0; i<count; i++) {
|
||||
pts.add( new Point(buff[i*2], buff[i*2+1]) );
|
||||
for (int i = 0; i < count; i++) {
|
||||
pts.add(new Point(buff[i * 2], buff[i * 2 + 1]));
|
||||
}
|
||||
} else {
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"Input Mat should be of CV_32SC2, CV_32FC2 or CV_64FC2 type\n" + m );
|
||||
"Input Mat should be of CV_32SC2, CV_32FC2 or CV_64FC2 type\n" + m);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_Point3i(Mat m, List<Point3> pts) {
|
||||
Mat_to_vector_Point3(m, pts);
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_Point3f(Mat m, List<Point3> pts) {
|
||||
Mat_to_vector_Point3(m, pts);
|
||||
}
|
||||
@@ -197,49 +192,50 @@ public class Converters {
|
||||
public static void Mat_to_vector_Point3d(Mat m, List<Point3> pts) {
|
||||
Mat_to_vector_Point3(m, pts);
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_Point3(Mat m, List<Point3> pts) {
|
||||
if(pts == null)
|
||||
if (pts == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
int count = m.rows();
|
||||
int type = m.type();
|
||||
if(m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException( "Input Mat should have one column\n" + m );
|
||||
if (m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException("Input Mat should have one column\n" + m);
|
||||
|
||||
pts.clear();
|
||||
if(type == CvType.CV_32SC3) {
|
||||
int[] buff = new int[3*count];
|
||||
if (type == CvType.CV_32SC3) {
|
||||
int[] buff = new int[3 * count];
|
||||
m.get(0, 0, buff);
|
||||
for(int i=0; i<count; i++) {
|
||||
pts.add( new Point3(buff[i*3], buff[i*3+1], buff[i*3+2]) );
|
||||
for (int i = 0; i < count; i++) {
|
||||
pts.add(new Point3(buff[i * 3], buff[i * 3 + 1], buff[i * 3 + 2]));
|
||||
}
|
||||
} else if(type == CvType.CV_32FC3){
|
||||
float[] buff = new float[3*count];
|
||||
} else if (type == CvType.CV_32FC3) {
|
||||
float[] buff = new float[3 * count];
|
||||
m.get(0, 0, buff);
|
||||
for(int i=0; i<count; i++) {
|
||||
pts.add( new Point3(buff[i*3], buff[i*3+1], buff[i*3+2]) );
|
||||
for (int i = 0; i < count; i++) {
|
||||
pts.add(new Point3(buff[i * 3], buff[i * 3 + 1], buff[i * 3 + 2]));
|
||||
}
|
||||
} else if(type == CvType.CV_64FC3){
|
||||
double[] buff = new double[3*count];
|
||||
} else if (type == CvType.CV_64FC3) {
|
||||
double[] buff = new double[3 * count];
|
||||
m.get(0, 0, buff);
|
||||
for(int i=0; i<count; i++) {
|
||||
pts.add( new Point3(buff[i*3], buff[i*3+1], buff[i*3+2]) );
|
||||
for (int i = 0; i < count; i++) {
|
||||
pts.add(new Point3(buff[i * 3], buff[i * 3 + 1], buff[i * 3 + 2]));
|
||||
}
|
||||
} else {
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"Input Mat should be of CV_32SC3, CV_32FC3 or CV_64FC3 type\n" + m );
|
||||
"Input Mat should be of CV_32SC3, CV_32FC3 or CV_64FC3 type\n" + m);
|
||||
}
|
||||
}
|
||||
|
||||
public static Mat vector_Mat_to_Mat(List<Mat> mats) {
|
||||
Mat res;
|
||||
int count = (mats!=null) ? mats.size() : 0;
|
||||
if(count>0){
|
||||
int count = (mats != null) ? mats.size() : 0;
|
||||
if (count > 0) {
|
||||
res = new Mat(count, 1, CvType.CV_32SC2);
|
||||
int[] buff = new int[count*2];
|
||||
for(int i=0; i<count; i++) {
|
||||
int[] buff = new int[count * 2];
|
||||
for (int i = 0; i < count; i++) {
|
||||
long addr = mats.get(i).nativeObj;
|
||||
buff[i*2] = (int)(addr >> 32);
|
||||
buff[i*2+1] = (int)(addr & 0xffffffff);
|
||||
buff[i * 2] = (int) (addr >> 32);
|
||||
buff[i * 2 + 1] = (int) (addr & 0xffffffff);
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
@@ -249,31 +245,31 @@ public class Converters {
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_Mat(Mat m, List<Mat> mats) {
|
||||
if(mats == null)
|
||||
if (mats == null)
|
||||
throw new java.lang.IllegalArgumentException("mats == null");
|
||||
int count = m.rows();
|
||||
if( CvType.CV_32SC2 != m.type() || m.cols()!=1 )
|
||||
if (CvType.CV_32SC2 != m.type() || m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"CvType.CV_32SC2 != m.type() || m.cols()!=1\n" + m);
|
||||
|
||||
mats.clear();
|
||||
int[] buff = new int[count*2];
|
||||
int[] buff = new int[count * 2];
|
||||
m.get(0, 0, buff);
|
||||
for(int i=0; i<count; i++) {
|
||||
long addr = (((long)buff[i*2])<<32) | ((long)buff[i*2+1]);
|
||||
mats.add( new Mat(addr) );
|
||||
for (int i = 0; i < count; i++) {
|
||||
long addr = (((long) buff[i * 2]) << 32) | ((long) buff[i * 2 + 1]);
|
||||
mats.add(new Mat(addr));
|
||||
}
|
||||
}
|
||||
|
||||
public static Mat vector_float_to_Mat(List<Float> fs) {
|
||||
Mat res;
|
||||
int count = (fs!=null) ? fs.size() : 0;
|
||||
if(count>0){
|
||||
int count = (fs != null) ? fs.size() : 0;
|
||||
if (count > 0) {
|
||||
res = new Mat(count, 1, CvType.CV_32FC1);
|
||||
float[] buff = new float[count];
|
||||
for(int i=0; i<count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
float f = fs.get(i);
|
||||
buff[i] = f;
|
||||
buff[i] = f;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
@@ -283,30 +279,30 @@ public class Converters {
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_float(Mat m, List<Float> fs) {
|
||||
if(fs == null)
|
||||
if (fs == null)
|
||||
throw new java.lang.IllegalArgumentException("fs == null");
|
||||
int count = m.rows();
|
||||
if( CvType.CV_32FC1 != m.type() || m.cols()!=1 )
|
||||
if (CvType.CV_32FC1 != m.type() || m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"CvType.CV_32FC1 != m.type() || m.cols()!=1\n" + m);
|
||||
|
||||
fs.clear();
|
||||
float[] buff = new float[count];
|
||||
m.get(0, 0, buff);
|
||||
for(int i=0; i<count; i++) {
|
||||
fs.add( buff[i] );
|
||||
for (int i = 0; i < count; i++) {
|
||||
fs.add(buff[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static Mat vector_uchar_to_Mat(List<Byte> bs) {
|
||||
Mat res;
|
||||
int count = (bs!=null) ? bs.size() : 0;
|
||||
if(count>0){
|
||||
int count = (bs != null) ? bs.size() : 0;
|
||||
if (count > 0) {
|
||||
res = new Mat(count, 1, CvType.CV_8UC1);
|
||||
byte[] buff = new byte[count];
|
||||
for(int i=0; i<count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
byte b = bs.get(i);
|
||||
buff[i] = b;
|
||||
buff[i] = b;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
@@ -316,31 +312,30 @@ public class Converters {
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_uchar(Mat m, List<Byte> us) {
|
||||
if(us == null)
|
||||
if (us == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
int count = m.rows();
|
||||
if( CvType.CV_8UC1 != m.type() || m.cols()!=1 )
|
||||
if (CvType.CV_8UC1 != m.type() || m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"CvType.CV_8UC1 != m.type() || m.cols()!=1\n" + m);
|
||||
|
||||
us.clear();
|
||||
byte[] buff = new byte[count];
|
||||
m.get(0, 0, buff);
|
||||
for(int i=0; i<count; i++) {
|
||||
us.add( buff[i] );
|
||||
for (int i = 0; i < count; i++) {
|
||||
us.add(buff[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Mat vector_char_to_Mat(List<Byte> bs) {
|
||||
Mat res;
|
||||
int count = (bs!=null) ? bs.size() : 0;
|
||||
if(count>0){
|
||||
int count = (bs != null) ? bs.size() : 0;
|
||||
if (count > 0) {
|
||||
res = new Mat(count, 1, CvType.CV_8SC1);
|
||||
byte[] buff = new byte[count];
|
||||
for(int i=0; i<count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
byte b = bs.get(i);
|
||||
buff[i] = b;
|
||||
buff[i] = b;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
@@ -351,13 +346,13 @@ public class Converters {
|
||||
|
||||
public static Mat vector_int_to_Mat(List<Integer> is) {
|
||||
Mat res;
|
||||
int count = (is!=null) ? is.size() : 0;
|
||||
if(count>0){
|
||||
int count = (is != null) ? is.size() : 0;
|
||||
if (count > 0) {
|
||||
res = new Mat(count, 1, CvType.CV_32SC1);
|
||||
int[] buff = new int[count];
|
||||
for(int i=0; i<count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
int v = is.get(i);
|
||||
buff[i] = v;
|
||||
buff[i] = v;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
@@ -367,49 +362,49 @@ public class Converters {
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_int(Mat m, List<Integer> is) {
|
||||
if(is == null)
|
||||
if (is == null)
|
||||
throw new java.lang.IllegalArgumentException("is == null");
|
||||
int count = m.rows();
|
||||
if( CvType.CV_32SC1 != m.type() || m.cols()!=1 )
|
||||
if (CvType.CV_32SC1 != m.type() || m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"CvType.CV_32SC1 != m.type() || m.cols()!=1\n" + m);
|
||||
|
||||
is.clear();
|
||||
int[] buff = new int[count];
|
||||
m.get(0, 0, buff);
|
||||
for(int i=0; i<count; i++) {
|
||||
is.add( buff[i] );
|
||||
for (int i = 0; i < count; i++) {
|
||||
is.add(buff[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_char(Mat m, List<Byte> bs) {
|
||||
if(bs == null)
|
||||
if (bs == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
int count = m.rows();
|
||||
if( CvType.CV_8SC1 != m.type() || m.cols()!=1 )
|
||||
if (CvType.CV_8SC1 != m.type() || m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"CvType.CV_8SC1 != m.type() || m.cols()!=1\n" + m);
|
||||
|
||||
bs.clear();
|
||||
byte[] buff = new byte[count];
|
||||
m.get(0, 0, buff);
|
||||
for(int i=0; i<count; i++) {
|
||||
bs.add( buff[i] );
|
||||
for (int i = 0; i < count; i++) {
|
||||
bs.add(buff[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static Mat vector_Rect_to_Mat(List<Rect> rs) {
|
||||
Mat res;
|
||||
int count = (rs!=null) ? rs.size() : 0;
|
||||
if(count>0){
|
||||
int count = (rs != null) ? rs.size() : 0;
|
||||
if (count > 0) {
|
||||
res = new Mat(count, 1, CvType.CV_32SC4);
|
||||
int[] buff = new int[4*count];
|
||||
for(int i=0; i<count; i++) {
|
||||
int[] buff = new int[4 * count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
Rect r = rs.get(i);
|
||||
buff[4*i ] = r.x;
|
||||
buff[4*i+1] = r.y;
|
||||
buff[4*i+2] = r.width;
|
||||
buff[4*i+3] = r.height;
|
||||
buff[4 * i] = r.x;
|
||||
buff[4 * i + 1] = r.y;
|
||||
buff[4 * i + 2] = r.width;
|
||||
buff[4 * i + 3] = r.height;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
@@ -419,37 +414,36 @@ public class Converters {
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_Rect(Mat m, List<Rect> rs) {
|
||||
if(rs == null)
|
||||
if (rs == null)
|
||||
throw new java.lang.IllegalArgumentException("rs == null");
|
||||
int count = m.rows();
|
||||
if(CvType.CV_32SC4 != m.type() || m.cols()!=1 )
|
||||
if (CvType.CV_32SC4 != m.type() || m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"CvType.CV_32SC4 != m.type() || m.rows()!=1\n" + m);
|
||||
|
||||
rs.clear();
|
||||
int[] buff = new int[4*count];
|
||||
int[] buff = new int[4 * count];
|
||||
m.get(0, 0, buff);
|
||||
for(int i=0; i<count; i++) {
|
||||
rs.add( new Rect(buff[4*i], buff[4*i+1], buff[4*i+2], buff[4*i+3]) );
|
||||
for (int i = 0; i < count; i++) {
|
||||
rs.add(new Rect(buff[4 * i], buff[4 * i + 1], buff[4 * i + 2], buff[4 * i + 3]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Mat vector_KeyPoint_to_Mat(List<KeyPoint> kps) {
|
||||
Mat res;
|
||||
int count = (kps!=null) ? kps.size() : 0;
|
||||
if(count>0){
|
||||
int count = (kps != null) ? kps.size() : 0;
|
||||
if (count > 0) {
|
||||
res = new Mat(count, 1, CvType.CV_64FC(7));
|
||||
double[] buff = new double[count * 7];
|
||||
for(int i=0; i<count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
KeyPoint kp = kps.get(i);
|
||||
buff[7*i ] = kp.pt.x;
|
||||
buff[7*i+1] = kp.pt.y;
|
||||
buff[7*i+2] = kp.size;
|
||||
buff[7*i+3] = kp.angle;
|
||||
buff[7*i+4] = kp.response;
|
||||
buff[7*i+5] = kp.octave;
|
||||
buff[7*i+6] = kp.class_id;
|
||||
buff[7 * i] = kp.pt.x;
|
||||
buff[7 * i + 1] = kp.pt.y;
|
||||
buff[7 * i + 2] = kp.size;
|
||||
buff[7 * i + 3] = kp.angle;
|
||||
buff[7 * i + 4] = kp.response;
|
||||
buff[7 * i + 5] = kp.octave;
|
||||
buff[7 * i + 6] = kp.class_id;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
@@ -459,29 +453,45 @@ public class Converters {
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_KeyPoint(Mat m, List<KeyPoint> kps) {
|
||||
if(kps == null)
|
||||
if (kps == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
int count = m.rows();
|
||||
if( CvType.CV_64FC(7) != m.type() || m.cols()!=1 )
|
||||
if (CvType.CV_64FC(7) != m.type() || m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"CvType.CV_64FC(7) != m.type() || m.cols()!=1\n" + m);
|
||||
|
||||
kps.clear();
|
||||
double[] buff = new double[7*count];
|
||||
double[] buff = new double[7 * count];
|
||||
m.get(0, 0, buff);
|
||||
for(int i=0; i<count; i++) {
|
||||
kps.add( new KeyPoint( (float)buff[7*i], (float)buff[7*i+1], (float)buff[7*i+2], (float)buff[7*i+3],
|
||||
(float)buff[7*i+4], (int)buff[7*i+5], (int)buff[7*i+6] ) );
|
||||
for (int i = 0; i < count; i++) {
|
||||
kps.add(new KeyPoint((float) buff[7 * i], (float) buff[7 * i + 1], (float) buff[7 * i + 2], (float) buff[7 * i + 3],
|
||||
(float) buff[7 * i + 4], (int) buff[7 * i + 5], (int) buff[7 * i + 6]));
|
||||
}
|
||||
}
|
||||
|
||||
// vector_vector_Point
|
||||
public static Mat vector_vector_Point_to_Mat(List<List<Point>> pts) {
|
||||
Mat res;
|
||||
int lCount = (pts != null) ? pts.size() : 0;
|
||||
if (lCount > 0) {
|
||||
List<Mat> mats = new ArrayList<Mat>(lCount);
|
||||
for (List<Point> lpt : pts)
|
||||
mats.add(vector_Point_to_Mat(lpt));
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// vector_vector_KeyPoint
|
||||
public static Mat vector_vector_KeyPoint_to_Mat(List<List<KeyPoint>> kps) {
|
||||
Mat res;
|
||||
int lCount = (kps!=null) ? kps.size() : 0;
|
||||
if(lCount>0){
|
||||
int lCount = (kps != null) ? kps.size() : 0;
|
||||
if (lCount > 0) {
|
||||
List<Mat> mats = new ArrayList<Mat>(lCount);
|
||||
for(List<KeyPoint> lkp: kps) mats.add( vector_KeyPoint_to_Mat(lkp) );
|
||||
for (List<KeyPoint> lkp : kps)
|
||||
mats.add(vector_KeyPoint_to_Mat(lkp));
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
@@ -490,31 +500,30 @@ public class Converters {
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_vector_KeyPoint(Mat m, List<List<KeyPoint>> kps) {
|
||||
if(kps == null)
|
||||
if (kps == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
|
||||
if(m == null)
|
||||
if (m == null)
|
||||
throw new java.lang.IllegalArgumentException("Input Mat can't be null");
|
||||
|
||||
List<Mat> mats = new ArrayList<Mat>(m.rows());
|
||||
Mat_to_vector_Mat(m, mats);
|
||||
List<KeyPoint> lkp = new ArrayList<KeyPoint>();
|
||||
for(Mat mi : mats) {
|
||||
for (Mat mi : mats) {
|
||||
Mat_to_vector_KeyPoint(mi, lkp);
|
||||
kps.add(lkp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Mat vector_double_to_Mat(List<Double> ds) {
|
||||
Mat res;
|
||||
int count = (ds!=null) ? ds.size() : 0;
|
||||
if(count>0){
|
||||
int count = (ds != null) ? ds.size() : 0;
|
||||
if (count > 0) {
|
||||
res = new Mat(count, 1, CvType.CV_64FC1);
|
||||
double[] buff = new double[count];
|
||||
for(int i=0; i<count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
double v = ds.get(i);
|
||||
buff[i] = v;
|
||||
buff[i] = v;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
@@ -525,16 +534,16 @@ public class Converters {
|
||||
|
||||
public static Mat vector_DMatch_to_Mat(List<DMatch> matches) {
|
||||
Mat res;
|
||||
int count = (matches!=null) ? matches.size() : 0;
|
||||
if(count>0){
|
||||
int count = (matches != null) ? matches.size() : 0;
|
||||
if (count > 0) {
|
||||
res = new Mat(count, 1, CvType.CV_64FC4);
|
||||
double[] buff = new double[count * 4];
|
||||
for(int i=0; i<count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
DMatch m = matches.get(i);
|
||||
buff[4*i ] = m.queryIdx;
|
||||
buff[4*i+1] = m.trainIdx;
|
||||
buff[4*i+2] = m.imgIdx;
|
||||
buff[4*i+3] = m.distance;
|
||||
buff[4 * i] = m.queryIdx;
|
||||
buff[4 * i + 1] = m.trainIdx;
|
||||
buff[4 * i + 2] = m.imgIdx;
|
||||
buff[4 * i + 3] = m.distance;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
@@ -544,80 +553,81 @@ public class Converters {
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_DMatch(Mat m, List<DMatch> matches) {
|
||||
if(matches == null)
|
||||
if (matches == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
int count = m.rows();
|
||||
if( CvType.CV_64FC4 != m.type() || m.cols()!=1 )
|
||||
if (CvType.CV_64FC4 != m.type() || m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"CvType.CV_64FC4 != m.type() || m.cols()!=1\n" + m);
|
||||
|
||||
matches.clear();
|
||||
double[] buff = new double[4*count];
|
||||
double[] buff = new double[4 * count];
|
||||
m.get(0, 0, buff);
|
||||
for(int i=0; i<count; i++) {
|
||||
matches.add( new DMatch( (int)buff[4*i], (int)buff[4*i+1], (int)buff[4*i+2], (float)buff[4*i+3] ) );
|
||||
for (int i = 0; i < count; i++) {
|
||||
matches.add(new DMatch((int) buff[4 * i], (int) buff[4 * i + 1], (int) buff[4 * i + 2], (float) buff[4 * i + 3]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// vector_vector_DMatch
|
||||
public static Mat vector_vector_DMatch_to_Mat(List<List<DMatch>> lldm) {
|
||||
Mat res;
|
||||
int lCount = (lldm!=null) ? lldm.size() : 0;
|
||||
if(lCount>0){
|
||||
List<Mat> mats = new ArrayList<Mat>(lCount);
|
||||
for(List<DMatch> ldm: lldm) mats.add( vector_DMatch_to_Mat(ldm) );
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
// vector_vector_DMatch
|
||||
public static Mat vector_vector_DMatch_to_Mat(List<List<DMatch>> lldm) {
|
||||
Mat res;
|
||||
int lCount = (lldm != null) ? lldm.size() : 0;
|
||||
if (lCount > 0) {
|
||||
List<Mat> mats = new ArrayList<Mat>(lCount);
|
||||
for (List<DMatch> ldm : lldm)
|
||||
mats.add(vector_DMatch_to_Mat(ldm));
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_vector_DMatch(Mat m, List<List<DMatch>> lldm) {
|
||||
if(lldm == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
public static void Mat_to_vector_vector_DMatch(Mat m, List<List<DMatch>> lldm) {
|
||||
if (lldm == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
|
||||
if(m == null)
|
||||
throw new java.lang.IllegalArgumentException("Input Mat can't be null");
|
||||
if (m == null)
|
||||
throw new java.lang.IllegalArgumentException("Input Mat can't be null");
|
||||
|
||||
List<Mat> mats = new ArrayList<Mat>(m.rows());
|
||||
Mat_to_vector_Mat(m, mats);
|
||||
List<DMatch> ldm = new ArrayList<DMatch>();
|
||||
for(Mat mi : mats) {
|
||||
Mat_to_vector_DMatch(mi, ldm);
|
||||
lldm.add(ldm);
|
||||
List<Mat> mats = new ArrayList<Mat>(m.rows());
|
||||
Mat_to_vector_Mat(m, mats);
|
||||
List<DMatch> ldm = new ArrayList<DMatch>();
|
||||
for (Mat mi : mats) {
|
||||
Mat_to_vector_DMatch(mi, ldm);
|
||||
lldm.add(ldm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//vector_vector_char
|
||||
public static Mat vector_vector_char_to_Mat(List<List<Byte>> llb) {
|
||||
Mat res;
|
||||
int lCount = (llb!=null) ? llb.size() : 0;
|
||||
if(lCount>0){
|
||||
List<Mat> mats = new ArrayList<Mat>(lCount);
|
||||
for(List<Byte> lb: llb) mats.add( vector_char_to_Mat(lb) );
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
// vector_vector_char
|
||||
public static Mat vector_vector_char_to_Mat(List<List<Byte>> llb) {
|
||||
Mat res;
|
||||
int lCount = (llb != null) ? llb.size() : 0;
|
||||
if (lCount > 0) {
|
||||
List<Mat> mats = new ArrayList<Mat>(lCount);
|
||||
for (List<Byte> lb : llb)
|
||||
mats.add(vector_char_to_Mat(lb));
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_vector_char(Mat m, List<List<Byte>> llb) {
|
||||
if(llb == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
public static void Mat_to_vector_vector_char(Mat m, List<List<Byte>> llb) {
|
||||
if (llb == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
|
||||
if(m == null)
|
||||
throw new java.lang.IllegalArgumentException("Input Mat can't be null");
|
||||
if (m == null)
|
||||
throw new java.lang.IllegalArgumentException("Input Mat can't be null");
|
||||
|
||||
List<Mat> mats = new ArrayList<Mat>(m.rows());
|
||||
Mat_to_vector_Mat(m, mats);
|
||||
List<Byte> lb = new ArrayList<Byte>();
|
||||
for(Mat mi : mats) {
|
||||
Mat_to_vector_char(mi, lb);
|
||||
llb.add(lb);
|
||||
}
|
||||
}
|
||||
List<Mat> mats = new ArrayList<Mat>(m.rows());
|
||||
Mat_to_vector_Mat(m, mats);
|
||||
List<Byte> lb = new ArrayList<Byte>();
|
||||
for (Mat mi : mats) {
|
||||
Mat_to_vector_char(mi, lb);
|
||||
llb.add(lb);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user