Java API: added missing converter vector<Mat> <-> Mat
authorAndrey Pavlenko <no@email>
Mon, 18 Jul 2011 14:23:45 +0000 (14:23 +0000)
committerAndrey Pavlenko <no@email>
Mon, 18 Jul 2011 14:23:45 +0000 (14:23 +0000)
modules/java/src/cpp/utils.cpp

index 62ebdf9..a4af447 100644 (file)
@@ -150,12 +150,28 @@ void vector_KeyPoint_to_Mat(vector<KeyPoint>& v_kp, Mat& mat)
 //vector_Mat\r
 void Mat_to_vector_Mat(cv::Mat& mat, std::vector<cv::Mat>& v_mat)\r
 {\r
-    return;\r
+       v_mat.clear();\r
+       if(mat.type() == CV_32SC2 && mat.rows == 1)\r
+       {\r
+               for(int i=0; i<mat.cols; i++)\r
+               {\r
+                       Vec<int, 2> a = mat.at< Vec<int, 2> >(0, i);\r
+                       long long addr = (((long long)a[0])<<32) | a[1];\r
+                       Mat& m = *( (Mat*) addr );\r
+                       v_mat.push_back(m);\r
+               }\r
+       }\r
 }\r
 \r
 \r
 void vector_Mat_to_Mat(std::vector<cv::Mat>& v_mat, cv::Mat& mat)\r
 {\r
+       int count = v_mat.size();\r
+       mat.create(1, count, CV_32SC2);\r
+       for(int i=0; i<count; i++)\r
+       {\r
+               long long addr = (long long) &v_mat[i];\r
+               mat.at< Vec<int, 2> >(0, i) = Vec<int, 2>(addr>>32, addr&0xffffffff);\r
+       }\r
     return;\r
 }\r
-\r