Java API: new converters, findFundamentalMat/cornerSubPix/findHomography/solvePnP/solvePnPRansac and their tests are updated
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
|
||||
using namespace cv;
|
||||
|
||||
#define CHECK_MAT(cond) if(cond){ LOGD(#cond); return; }
|
||||
#define CHECK_MAT(cond) if(!(cond)){ LOGD("FAILED: " #cond); return; }
|
||||
|
||||
|
||||
// vector_int
|
||||
@@ -18,7 +18,7 @@ using namespace cv;
|
||||
void Mat_to_vector_int(Mat& mat, vector<int>& v_int)
|
||||
{
|
||||
v_int.clear();
|
||||
CHECK_MAT(mat.type()!= CV_32SC1 || mat.cols!=1);
|
||||
CHECK_MAT(mat.type()==CV_32SC1 && mat.cols==1);
|
||||
v_int = (vector<int>) mat;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ void vector_int_to_Mat(vector<int>& v_int, Mat& mat)
|
||||
void Mat_to_vector_double(Mat& mat, vector<double>& v_double)
|
||||
{
|
||||
v_double.clear();
|
||||
CHECK_MAT(mat.type()!= CV_64FC1 || mat.cols!=1);
|
||||
CHECK_MAT(mat.type()==CV_64FC1 && mat.cols==1);
|
||||
v_double = (vector<double>) mat;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ void vector_double_to_Mat(vector<double>& v_double, Mat& mat)
|
||||
void Mat_to_vector_float(Mat& mat, vector<float>& v_float)
|
||||
{
|
||||
v_float.clear();
|
||||
CHECK_MAT(mat.type()!= CV_32FC1 || mat.cols!=1);
|
||||
CHECK_MAT(mat.type()==CV_32FC1 && mat.cols==1);
|
||||
v_float = (vector<float>) mat;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ void vector_float_to_Mat(vector<float>& v_float, Mat& mat)
|
||||
void Mat_to_vector_uchar(Mat& mat, vector<uchar>& v_uchar)
|
||||
{
|
||||
v_uchar.clear();
|
||||
CHECK_MAT(mat.type()!= CV_8UC1 || mat.cols!=1);
|
||||
CHECK_MAT(mat.type()==CV_8UC1 && mat.cols==1);
|
||||
v_uchar = (vector<uchar>) mat;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ void Mat_to_vector_uchar(Mat& mat, vector<uchar>& v_uchar)
|
||||
void Mat_to_vector_Rect(Mat& mat, vector<Rect>& v_rect)
|
||||
{
|
||||
v_rect.clear();
|
||||
CHECK_MAT(mat.type()!= CV_32SC4 || mat.cols!=1);
|
||||
CHECK_MAT(mat.type()==CV_32SC4 && mat.cols==1);
|
||||
v_rect = (vector<Rect>) mat;
|
||||
}
|
||||
|
||||
@@ -87,22 +87,88 @@ void vector_Rect_to_Mat(vector<Rect>& v_rect, Mat& mat)
|
||||
void Mat_to_vector_Point(Mat& mat, vector<Point>& v_point)
|
||||
{
|
||||
v_point.clear();
|
||||
CHECK_MAT(mat.type()!= CV_32SC2 || mat.cols!=1);
|
||||
CHECK_MAT(mat.type()==CV_32SC2 && mat.cols==1);
|
||||
v_point = (vector<Point>) mat;
|
||||
}
|
||||
|
||||
//vector_Point2f
|
||||
void Mat_to_vector_Point2f(Mat& mat, vector<Point2f>& v_point)
|
||||
{
|
||||
v_point.clear();
|
||||
CHECK_MAT(mat.type()==CV_32FC2 && mat.cols==1);
|
||||
v_point = (vector<Point2f>) mat;
|
||||
}
|
||||
|
||||
//vector_Point2d
|
||||
void Mat_to_vector_Point2d(Mat& mat, vector<Point2d>& v_point)
|
||||
{
|
||||
v_point.clear();
|
||||
CHECK_MAT(mat.type()==CV_64FC2 && mat.cols==1);
|
||||
v_point = (vector<Point2d>) mat;
|
||||
}
|
||||
|
||||
|
||||
//vector_Point3i
|
||||
void Mat_to_vector_Point3i(Mat& mat, vector<Point3i>& v_point)
|
||||
{
|
||||
v_point.clear();
|
||||
CHECK_MAT(mat.type()==CV_32SC3 && mat.cols==1);
|
||||
v_point = (vector<Point3i>) mat;
|
||||
}
|
||||
|
||||
//vector_Point3f
|
||||
void Mat_to_vector_Point3f(Mat& mat, vector<Point3f>& v_point)
|
||||
{
|
||||
v_point.clear();
|
||||
CHECK_MAT(mat.type()==CV_32FC3 && mat.cols==1);
|
||||
v_point = (vector<Point3f>) mat;
|
||||
}
|
||||
|
||||
//vector_Point3d
|
||||
void Mat_to_vector_Point3d(Mat& mat, vector<Point3d>& v_point)
|
||||
{
|
||||
v_point.clear();
|
||||
CHECK_MAT(mat.type()==CV_64FC3 && mat.cols==1);
|
||||
v_point = (vector<Point3d>) mat;
|
||||
}
|
||||
|
||||
|
||||
void vector_Point_to_Mat(vector<Point>& v_point, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_point);
|
||||
}
|
||||
|
||||
void vector_Point2f_to_Mat(vector<Point2f>& v_point, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_point);
|
||||
}
|
||||
|
||||
void vector_Point2d_to_Mat(vector<Point2d>& v_point, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_point);
|
||||
}
|
||||
|
||||
void vector_Point3i_to_Mat(vector<Point3i>& v_point, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_point);
|
||||
}
|
||||
|
||||
void vector_Point3f_to_Mat(vector<Point3f>& v_point, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_point);
|
||||
}
|
||||
|
||||
void vector_Point3d_to_Mat(vector<Point3d>& v_point, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_point);
|
||||
}
|
||||
|
||||
|
||||
//vector_KeyPoint
|
||||
void Mat_to_vector_KeyPoint(Mat& mat, vector<KeyPoint>& v_kp)
|
||||
{
|
||||
v_kp.clear();
|
||||
CHECK_MAT(mat.type()!= CV_64FC(7) || mat.cols!=1);
|
||||
CHECK_MAT(mat.type()==CV_64FC(7) && mat.cols==1);
|
||||
for(int i=0; i<mat.rows; i++)
|
||||
{
|
||||
Vec<double, 7> v = mat.at< Vec<double, 7> >(i, 0);
|
||||
@@ -138,6 +204,8 @@ void Mat_to_vector_Mat(cv::Mat& mat, std::vector<cv::Mat>& v_mat)
|
||||
Mat& m = *( (Mat*) addr );
|
||||
v_mat.push_back(m);
|
||||
}
|
||||
} else {
|
||||
LOGD("Mat_to_vector_Mat() FAILED: mat.type() == CV_32SC2 && mat.cols == 1");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -29,8 +29,18 @@ void vector_Rect_to_Mat(std::vector<cv::Rect>& v_rect, cv::Mat& mat);
|
||||
|
||||
|
||||
void Mat_to_vector_Point(cv::Mat& mat, std::vector<cv::Point>& v_point);
|
||||
void Mat_to_vector_Point2f(cv::Mat& mat, std::vector<cv::Point2f>& v_point);
|
||||
void Mat_to_vector_Point2d(cv::Mat& mat, std::vector<cv::Point2d>& v_point);
|
||||
void Mat_to_vector_Point3i(cv::Mat& mat, std::vector<cv::Point3i>& v_point);
|
||||
void Mat_to_vector_Point3f(cv::Mat& mat, std::vector<cv::Point3f>& v_point);
|
||||
void Mat_to_vector_Point3d(cv::Mat& mat, std::vector<cv::Point3d>& v_point);
|
||||
|
||||
void vector_Point_to_Mat(std::vector<cv::Point>& v_point, cv::Mat& mat);
|
||||
void vector_Point2f_to_Mat(std::vector<cv::Point2f>& v_point, cv::Mat& mat);
|
||||
void vector_Point2d_to_Mat(std::vector<cv::Point2d>& v_point, cv::Mat& mat);
|
||||
void vector_Point3i_to_Mat(std::vector<cv::Point3i>& v_point, cv::Mat& mat);
|
||||
void vector_Point3f_to_Mat(std::vector<cv::Point3f>& v_point, cv::Mat& mat);
|
||||
void vector_Point3d_to_Mat(std::vector<cv::Point3d>& v_point, cv::Mat& mat);
|
||||
|
||||
|
||||
void Mat_to_vector_KeyPoint(cv::Mat& mat, std::vector<cv::KeyPoint>& v_kp);
|
||||
|
@@ -12,74 +12,220 @@ import org.opencv.features2d.KeyPoint;
|
||||
public class Converters {
|
||||
|
||||
public static Mat vector_Point_to_Mat(List<Point> pts) {
|
||||
Mat res;
|
||||
int count = (pts!=null) ? pts.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++) {
|
||||
Point p = pts.get(i);
|
||||
buff[i*2] = (int)p.x;
|
||||
buff[i*2+1] = (int)p.y;
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
return vector_Point_to_Mat(pts, CvType.CV_32S);
|
||||
}
|
||||
|
||||
public static Mat vector_Point2f_to_Mat(List<Point> pts) {
|
||||
return vector_Point_to_Mat(pts, CvType.CV_32F);
|
||||
}
|
||||
|
||||
public static Mat vector_Point2d_to_Mat(List<Point> pts) {
|
||||
return vector_Point_to_Mat(pts, CvType.CV_64F);
|
||||
}
|
||||
|
||||
public static Mat vector_Point_to_Mat(List<Point> pts, int typeDepth) {
|
||||
Mat res;
|
||||
int count = (pts!=null) ? pts.size() : 0;
|
||||
if(count>0){
|
||||
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;
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("'typeDepth' can be CV_32S, CV_32F or CV_64F");
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public static Mat vector_Point3i_to_Mat(List<Point3> pts) {
|
||||
return vector_Point3_to_Mat(pts, CvType.CV_32S);
|
||||
}
|
||||
|
||||
public static Mat vector_Point3f_to_Mat(List<Point3> pts) {
|
||||
return vector_Point3_to_Mat(pts, CvType.CV_32F);
|
||||
}
|
||||
|
||||
public static Mat vector_Point3d_to_Mat(List<Point3> pts) {
|
||||
return vector_Point3_to_Mat(pts, CvType.CV_64F);
|
||||
}
|
||||
|
||||
public static Mat vector_Point3_to_Mat(List<Point3> pts, int typeDepth) {
|
||||
Mat res;
|
||||
int count = (pts!=null) ? pts.size() : 0;
|
||||
if(count>0){
|
||||
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;
|
||||
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_64FC3);
|
||||
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);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("'typeDepth' can be CV_32S, CV_32F or CV_64F");
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_Point2f(Mat m, List<Point> pts) {
|
||||
Mat_to_vector_Point(m, pts);
|
||||
}
|
||||
|
||||
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)
|
||||
throw new java.lang.IllegalArgumentException("pts == null");
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
int count = m.rows();
|
||||
if( CvType.CV_32SC2 != m.type() || m.cols()!=1 )
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"CvType.CV_32SC2 != m.type() || m.cols()!=1\n" + m );
|
||||
int type = m.type();
|
||||
if(m.cols() != 1)
|
||||
throw new java.lang.IllegalArgumentException( "Input Mat should have one column\n" + m );
|
||||
|
||||
pts.clear();
|
||||
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]) );
|
||||
}
|
||||
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]) );
|
||||
}
|
||||
} 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]) );
|
||||
}
|
||||
} 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]) );
|
||||
}
|
||||
} else {
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"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);
|
||||
}
|
||||
|
||||
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)
|
||||
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 );
|
||||
|
||||
pts.clear();
|
||||
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]) );
|
||||
}
|
||||
} 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]) );
|
||||
}
|
||||
} 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]) );
|
||||
}
|
||||
} else {
|
||||
throw new java.lang.IllegalArgumentException(
|
||||
"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) {
|
||||
|
Reference in New Issue
Block a user