Java API generator: pointers handling fixed, KeyPoint manual port added

This commit is contained in:
Andrey Pavlenko
2011-07-27 14:09:49 +00:00
parent 3b558508be
commit 5ba826d297
3 changed files with 97 additions and 66 deletions

View File

@@ -10,29 +10,20 @@
using namespace cv;
#define CHECK_MAT(cond) if(cond){ LOGD(#cond); return; }
// vector_int
void Mat_to_vector_int(Mat& mat, vector<int>& v_int)
{
v_int.clear();
if(mat.type()!= CV_32SC1 || mat.rows!=1)
return;
/*
for(int i=0; i<mat.cols; i++)
v_int.push_back( mat.at< int >(0, i) );
*/
CHECK_MAT(mat.type()!= CV_32SC1 || mat.rows!=1);
v_int = (vector<int>) mat;
}
void vector_int_to_Mat(vector<int>& v_int, Mat& mat)
{
/*
mat.create(1, v_int.size(), CV_32SC1);
for(size_t i=0; i<v_int.size(); i++)
mat.at< int >(0, i) = v_int[i];
*/
mat = Mat(v_int);
}
@@ -42,24 +33,12 @@ 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();
if(mat.type()!= CV_64FC1 || mat.rows!=1)
return;
/*
for(int i=0; i<mat.cols; i++)
v_double.push_back( mat.at< double >(0, i) );
*/
CHECK_MAT(mat.type()!= CV_64FC1 || mat.rows!=1);
v_double = (vector<double>) mat;
}
void vector_double_to_Mat(vector<double>& v_double, Mat& mat)
{
/*
mat.create(1, v_double.size(), CV_64FC1);
for(size_t i=0; i<v_double.size(); i++)
mat.at< double >(0, i) = v_double[i];
*/
mat = Mat(v_double);
}
@@ -69,24 +48,12 @@ 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();
if(mat.type()!= CV_32FC1 || mat.rows!=1)
return;
/*
for(int i=0; i<mat.cols; i++)
v_float.push_back( mat.at< float >(0, i) );
*/
CHECK_MAT(mat.type()!= CV_32FC1 || mat.rows!=1);
v_float = (vector<float>) mat;
}
void vector_float_to_Mat(vector<float>& v_float, Mat& mat)
{
/*
mat.create(1, v_float.size(), CV_32FC1);
for(size_t i=0; i<v_float.size(); i++)
mat.at< float >(0, i) = v_float[i];
*/
mat = Mat(v_float);
}
@@ -96,14 +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();
if(mat.type()!= CV_8UC1 || mat.rows!=1)
return;
/*
for(int i=0; i<mat.cols; i++)
v_uchar.push_back( mat.at< uchar >(0, i) );
*/
CHECK_MAT(mat.type()!= CV_8UC1 || mat.rows!=1);
v_uchar = (vector<uchar>) mat;
}
@@ -113,24 +73,21 @@ 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();
if(mat.type()!= CV_32SC4 || mat.rows!=1) {
LOGD("ERROR mat.type()!= CV_32SC4 || mat.rows!=1");
return;
}
for(int i=0; i<mat.cols; i++) {
CHECK_MAT(mat.type()!= CV_32SC4 || mat.rows!=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.create(1, v_rect.size(), CV_32SC4);
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);
}
}*/
}
@@ -138,32 +95,35 @@ 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();
if(mat.type()!= CV_32SC2 || mat.rows!=1)
return;
for(int i=0; i<mat.cols; i++)
v_point.push_back( Point( mat.at< Vec<int, 2> >(0, i) ) );
CHECK_MAT(mat.type()!= CV_32SC2 || mat.rows!=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.create(1, v_point.size(), CV_32SC2);
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);
mat.at< Vec<int, 2> >(0, i) = Vec<int, 2>(v_point[i].x, v_point[i].y);*/
}
//vector_KeyPoint
void Mat_to_vector_KeyPoint(Mat& mat, vector<KeyPoint>& v_kp)
{
v_kp.clear();
//CHECK_MAT(mat.type()!= ??? || mat.rows!=1);
v_kp = (vector<KeyPoint>) mat;
return;
}
void vector_KeyPoint_to_Mat(vector<KeyPoint>& v_kp, Mat& mat)
{
mat = Mat(v_kp);
return;
}