Java API: converters vector<> to/from Mat are fixed
This commit is contained in:
@@ -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.rows!=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.rows!=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.rows!=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.rows!=1);
|
||||
CHECK_MAT(mat.type()!= CV_8UC1 || mat.cols!=1);
|
||||
v_uchar = (vector<uchar>) mat;
|
||||
}
|
||||
|
||||
@@ -73,21 +73,13 @@ 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.rows!=1);
|
||||
CHECK_MAT(mat.type()!= CV_32SC4 || mat.cols!=1);
|
||||
v_rect = (vector<Rect>) mat;
|
||||
/*for(int i=0; i<mat.cols; i++) {
|
||||
Vec<int, 4> v=mat.at< Vec<int, 4> >(0, i);
|
||||
v_rect.push_back( Rect(v[0], v[1], v[2], v[3]) );
|
||||
}*/
|
||||
}
|
||||
|
||||
void vector_Rect_to_Mat(vector<Rect>& v_rect, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_rect);
|
||||
/*mat.create(1, v_rect.size(), CV_32SC4);
|
||||
for(size_t i=0; i<v_rect.size(); i++) {
|
||||
mat.at< Vec<int, 4> >(0, i) = Vec<int, 4>(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<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.rows!=1);
|
||||
CHECK_MAT(mat.type()!= CV_32SC2 || mat.cols!=1);
|
||||
v_point = (vector<Point>) mat;
|
||||
/*for(int i=0; i<mat.cols; i++)
|
||||
v_point.push_back( Point( mat.at< Vec<int, 2> >(0, i) ) );*/
|
||||
}
|
||||
|
||||
|
||||
void vector_Point_to_Mat(vector<Point>& v_point, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_point);
|
||||
/*mat.create(1, v_point.size(), CV_32SC2);
|
||||
for(size_t i=0; i<v_point.size(); i++)
|
||||
mat.at< Vec<int, 2> >(0, i) = Vec<int, 2>(v_point[i].x, v_point[i].y);*/
|
||||
}
|
||||
|
||||
|
||||
@@ -115,10 +102,10 @@ void vector_Point_to_Mat(vector<Point>& v_point, Mat& mat)
|
||||
void Mat_to_vector_KeyPoint(Mat& mat, vector<KeyPoint>& v_kp)
|
||||
{
|
||||
v_kp.clear();
|
||||
CHECK_MAT(mat.type()!= CV_64FC(7) || mat.rows!=1);
|
||||
for(int i=0; i<mat.cols; i++)
|
||||
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> >(0, i);
|
||||
Vec<double, 7> v = mat.at< Vec<double, 7> >(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<KeyPoint>& v_kp)
|
||||
void vector_KeyPoint_to_Mat(vector<KeyPoint>& 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<count; i++)
|
||||
{
|
||||
KeyPoint kp = v_kp[i];
|
||||
mat.at< Vec<double, 7> >(0, i) = Vec<double, 7>(kp.pt.x, kp.pt.y, kp.size, kp.angle, kp.response, kp.octave, kp.class_id);
|
||||
mat.at< Vec<double, 7> >(i, 0) = Vec<double, 7>(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<KeyPoint>& v_kp, Mat& mat)
|
||||
void Mat_to_vector_Mat(cv::Mat& mat, std::vector<cv::Mat>& 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<mat.cols; i++)
|
||||
for(int i=0; i<mat.rows; i++)
|
||||
{
|
||||
Vec<int, 2> a = mat.at< Vec<int, 2> >(0, i);
|
||||
Vec<int, 2> a = mat.at< Vec<int, 2> >(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<cv::Mat>& v_mat)
|
||||
void vector_Mat_to_Mat(std::vector<cv::Mat>& 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<count; i++)
|
||||
{
|
||||
long long addr = (long long) new Mat(v_mat[i]);
|
||||
mat.at< Vec<int, 2> >(0, i) = Vec<int, 2>(addr>>32, addr&0xffffffff);
|
||||
mat.at< Vec<int, 2> >(i, 0) = Vec<int, 2>(addr>>32, addr&0xffffffff);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user