diff --git a/modules/java/src/cpp/converters.cpp b/modules/java/src/cpp/converters.cpp index 94716e5ec..a2ffb7c96 100644 --- a/modules/java/src/cpp/converters.cpp +++ b/modules/java/src/cpp/converters.cpp @@ -18,7 +18,7 @@ using namespace cv; void Mat_to_vector_int(Mat& mat, vector& v_int) { v_int.clear(); - CHECK_MAT(mat.type()!= CV_32SC1 || mat.rows!=1); + CHECK_MAT(mat.type()!= CV_32SC1 || mat.cols!=1); v_int = (vector) mat; } @@ -33,7 +33,7 @@ void vector_int_to_Mat(vector& v_int, Mat& mat) void Mat_to_vector_double(Mat& mat, vector& v_double) { v_double.clear(); - CHECK_MAT(mat.type()!= CV_64FC1 || mat.rows!=1); + CHECK_MAT(mat.type()!= CV_64FC1 || mat.cols!=1); v_double = (vector) mat; } @@ -48,7 +48,7 @@ void vector_double_to_Mat(vector& v_double, Mat& mat) void Mat_to_vector_float(Mat& mat, vector& v_float) { v_float.clear(); - CHECK_MAT(mat.type()!= CV_32FC1 || mat.rows!=1); + CHECK_MAT(mat.type()!= CV_32FC1 || mat.cols!=1); v_float = (vector) mat; } @@ -63,7 +63,7 @@ void vector_float_to_Mat(vector& v_float, Mat& mat) void Mat_to_vector_uchar(Mat& mat, vector& v_uchar) { v_uchar.clear(); - CHECK_MAT(mat.type()!= CV_8UC1 || mat.rows!=1); + CHECK_MAT(mat.type()!= CV_8UC1 || mat.cols!=1); v_uchar = (vector) mat; } @@ -73,21 +73,13 @@ void Mat_to_vector_uchar(Mat& mat, vector& v_uchar) void Mat_to_vector_Rect(Mat& mat, vector& v_rect) { v_rect.clear(); - CHECK_MAT(mat.type()!= CV_32SC4 || mat.rows!=1); + CHECK_MAT(mat.type()!= CV_32SC4 || mat.cols!=1); v_rect = (vector) mat; - /*for(int i=0; i v=mat.at< Vec >(0, i); - v_rect.push_back( Rect(v[0], v[1], v[2], v[3]) ); - }*/ } void vector_Rect_to_Mat(vector& v_rect, Mat& mat) { mat = Mat(v_rect); - /*mat.create(1, v_rect.size(), CV_32SC4); - for(size_t i=0; i >(0, i) = Vec(v_rect[i].x, v_rect[i].y, v_rect[i].width, v_rect[i].height); - }*/ } @@ -95,19 +87,14 @@ void vector_Rect_to_Mat(vector& v_rect, Mat& mat) void Mat_to_vector_Point(Mat& mat, vector& v_point) { v_point.clear(); - CHECK_MAT(mat.type()!= CV_32SC2 || mat.rows!=1); + CHECK_MAT(mat.type()!= CV_32SC2 || mat.cols!=1); v_point = (vector) mat; - /*for(int i=0; i >(0, i) ) );*/ } void vector_Point_to_Mat(vector& v_point, Mat& mat) { mat = Mat(v_point); - /*mat.create(1, v_point.size(), CV_32SC2); - for(size_t i=0; i >(0, i) = Vec(v_point[i].x, v_point[i].y);*/ } @@ -115,10 +102,10 @@ void vector_Point_to_Mat(vector& v_point, Mat& mat) void Mat_to_vector_KeyPoint(Mat& mat, vector& v_kp) { v_kp.clear(); - CHECK_MAT(mat.type()!= CV_64FC(7) || mat.rows!=1); - for(int i=0; i v = mat.at< Vec >(0, i); + Vec v = mat.at< Vec >(i, 0); KeyPoint kp((float)v[0], (float)v[1], (float)v[2], (float)v[3], (float)v[4], (int)v[5], (int)v[6]); v_kp.push_back(kp); } @@ -129,11 +116,11 @@ void Mat_to_vector_KeyPoint(Mat& mat, vector& v_kp) void vector_KeyPoint_to_Mat(vector& v_kp, Mat& mat) { int count = v_kp.size(); - mat.create(1, count, CV_64FC(7)); + mat.create(count, 1, CV_64FC(7)); for(int i=0; i >(0, i) = Vec(kp.pt.x, kp.pt.y, kp.size, kp.angle, kp.response, kp.octave, kp.class_id); + mat.at< Vec >(i, 0) = Vec(kp.pt.x, kp.pt.y, kp.size, kp.angle, kp.response, kp.octave, kp.class_id); } } @@ -142,11 +129,11 @@ void vector_KeyPoint_to_Mat(vector& v_kp, Mat& mat) void Mat_to_vector_Mat(cv::Mat& mat, std::vector& v_mat) { v_mat.clear(); - if(mat.type() == CV_32SC2 && mat.rows == 1) + if(mat.type() == CV_32SC2 && mat.cols == 1) { - for(int i=0; i a = mat.at< Vec >(0, i); + Vec a = mat.at< Vec >(i, 0); long long addr = (((long long)a[0])<<32) | a[1]; Mat& m = *( (Mat*) addr ); v_mat.push_back(m); @@ -158,10 +145,10 @@ void Mat_to_vector_Mat(cv::Mat& mat, std::vector& v_mat) void vector_Mat_to_Mat(std::vector& v_mat, cv::Mat& mat) { int count = v_mat.size(); - mat.create(1, count, CV_32SC2); + mat.create(count, 1, CV_32SC2); for(int i=0; i >(0, i) = Vec(addr>>32, addr&0xffffffff); + mat.at< Vec >(i, 0) = Vec(addr>>32, addr&0xffffffff); } } diff --git a/modules/java/src/java/Converters.java b/modules/java/src/java/Converters.java index 3d69d63bd..1706c4629 100644 --- a/modules/java/src/java/Converters.java +++ b/modules/java/src/java/Converters.java @@ -15,7 +15,7 @@ public class Converters { Mat res; int count = (pts!=null) ? pts.size() : 0; if(count>0){ - res = new Mat(1, count, CvType.CV_32SC2); + res = new Mat(count, 1, CvType.CV_32SC2); int[] buff = new int[count*2]; for(int i=0; i0){ - res = new Mat(1, count, CvType.CV_32FC2); + res = new Mat(count, 1, CvType.CV_32FC2); float[] buff = new float[count*2]; for(int i=0; i0){ - res = new Mat(1, count, CvType.CV_32FC3); + res = new Mat(count, 1, CvType.CV_32FC3); float[] buff = new float[count*3]; for(int i=0; i pts) { if(pts == null) - throw new java.lang.IllegalArgumentException(); - int cols = m.cols(); - if(CvType.CV_32SC2 != m.type() || m.rows()!=1 ) - throw new java.lang.IllegalArgumentException(); + throw new java.lang.IllegalArgumentException("pts == 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 ); pts.clear(); - int[] buff = new int[2*cols]; + int[] buff = new int[2*count]; m.get(0, 0, buff); - for(int i=0; i0){ - res = new Mat(1, count, CvType.CV_32SC2); + res = new Mat(count, 1, CvType.CV_32SC2); int[] buff = new int[count*2]; for(int i=0; i mats) { if(mats == null) - throw new java.lang.IllegalArgumentException(); - int cols = m.cols(); - if(CvType.CV_32SC2 != m.type() || m.rows()!=1 ) - throw new java.lang.IllegalArgumentException(); + throw new java.lang.IllegalArgumentException("mats == 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); mats.clear(); - int[] buff = new int[cols*2]; + int[] buff = new int[count*2]; m.get(0, 0, buff); - for(int i=0; i0){ - res = new Mat(1, count, CvType.CV_32FC1); //Point can be saved into double[2] + res = new Mat(count, 1, CvType.CV_32FC1); float[] buff = new float[count]; for(int i=0; i fs) { if(fs == null) - throw new java.lang.IllegalArgumentException(); - int cols = m.cols(); - if(CvType.CV_32FC1 != m.type() || m.rows()!=1 ) - throw new java.lang.IllegalArgumentException(); + throw new java.lang.IllegalArgumentException("fs == null"); + int count = m.rows(); + if( CvType.CV_32FC1 != m.type() || m.rows()!=1 ) + throw new java.lang.IllegalArgumentException( + "CvType.CV_32FC1 != m.type() || m.rows()!=1\n" + m); fs.clear(); - float[] buff = new float[cols]; + float[] buff = new float[count]; m.get(0, 0, buff); - for(int i=0; i0){ - res = new Mat(1, count, CvType.CV_8UC1); //Point can be saved into double[2] + res = new Mat(count, 1, CvType.CV_8UC1); byte[] buff = new byte[count]; for(int i=0; i0){ - res = new Mat(1, count, CvType.CV_32SC1); //Point can be saved into double[2] + res = new Mat(count, 1, CvType.CV_32SC1); int[] buff = new int[count]; for(int i=0; i is) { if(is == null) - throw new java.lang.IllegalArgumentException(); - int cols = m.cols(); - if(CvType.CV_32SC1 != m.type() || m.rows()!=1 ) - throw new java.lang.IllegalArgumentException(); + throw new java.lang.IllegalArgumentException("is == null"); + int count = m.rows(); + 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[cols]; + int[] buff = new int[count]; m.get(0, 0, buff); - for(int i=0; i0){ - res = new Mat(1, count, CvType.CV_32SC4); + res = new Mat(count, 1, CvType.CV_32SC4); int[] buff = new int[4*count]; for(int i=0; i rs) { if(rs == null) - throw new java.lang.IllegalArgumentException(); - int cols = m.cols(); - if(CvType.CV_32SC4 != m.type() || m.rows()!=1 ) - throw new java.lang.IllegalArgumentException(); + throw new java.lang.IllegalArgumentException("rs == null"); + int count = m.rows(); + 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*cols]; + int[] buff = new int[4*count]; m.get(0, 0, buff); - for(int i=0; i0){ - res = new Mat(1, count, CvType.CV_64FC(7)); + res = new Mat(count, 1, CvType.CV_64FC(7)); double[] buff = new double[count * 7]; for(int i=0; i kps) { if(kps == null) - throw new java.lang.IllegalArgumentException(); - int cols = m.cols(); - if(CvType.CV_64FC(7) != m.type() || m.rows()!=1 ) - throw new java.lang.IllegalArgumentException(); + throw new java.lang.IllegalArgumentException("kps == null"); + int count = m.rows(); + 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*cols]; + double[] buff = new double[7*count]; m.get(0, 0, buff); - for(int i=0; i0){ - res = new Mat(1, count, CvType.CV_64FC1); //Point can be saved into double[2] + res = new Mat(count, 1, CvType.CV_64FC1); double[] buff = new double[count]; for(int i=0; i