刚刚通过查看 OpenCV 源代码(在 /modules/java/generator/src/cpp/converters.cpp 下,第 185 行附近)发现了这一点:
void Mat_to_vector_KeyPoint(Mat& mat, vector<KeyPoint>& v_kp)
{
v_kp.clear();
CHECK_MAT(mat.type()==CV_32FC(7) && mat.cols==1);
for(int i=0; i<mat.rows; i++)
{
Vec<float, 7> v = mat.at< Vec<float, 7> >(i,0);
KeyPoint kp(v[0], v[1], v[2], v[3], v[4], (int)v[5], (int)v[6]);
v_kp.push_back(kp);
}
return;
}
我将其用作:
vector<KeyPoint> mat_to_keypoints(Mat* mat) {
vector<KeyPoint> c_keypoints;
for ( int i = 0; i < mat->rows; i++) {
Vec<float, 7> v = mat.at< Vec<float, 7> >(i,0);
KeyPoint kp(v[0], v[1], v[2], v[3], v[4], (int)v[5], (int)v[6]);
c_keypoints.push_back(kp);
};
return c_keypoints;
};