2011-05-07 38 views
0

私はcvProjectPoints2の簡単なコードをC++に変換しようとしていますので、私はcv :: ProjectPointsを使用しています。私は単純にコンパイルされませんcv::CからC++へのprojectPointsの変換

Mat_<double>* object_points  = new Mat_<double>(10, 3, CV_64FC1); 
Mat_<double>* rotation_vector = new Mat_<double>(3,3, CV_64FC1); 
Mat_<double>* translation_vector = new Mat_<double>(Size(3,1), CV_64FC1); 
Mat_<double>* intrinsic_matrix = new Mat_<double>(Size(3, 3), CV_64FC1); 
vector<Point2f>* image_points  = new vector<Point2f>; 

double t[] = { 
    70, 95, 120 
}; 

double object[] = { 
    150, 200, 400, 
    0,0,0, 
    0,0,0, 
    0,0,0, 
    0,0,0, 
    0,0,0, 
    0,0,0, 
    0,0,0, 
    0,0,0, 
    0,0,0 
}; 

double rotation[] = { 
    0, 1, 0, 
    -1, 0, 0, 
    0, 0, 1 
}; 

double intrinsic[] = { 
    -500, 0, 320, 
    0, -500, 240, 
    0, 0, 1 
}; 

int main() { 

    for (int i = 0; i < 30; i++) { 
     (*object_points)[i/3][i%3] = object[i]; 
    } 

    for (int i = 0; i < 9; i++) { 
     (*rotation_vector)[i/3][i%3] = rotation[i]; 
     (*intrinsic_matrix)[i/3][i%3] = intrinsic[i]; 
    } 

    for (int i = 0; i < 3; i++) { 
     (*translation_vector)[0][i] = t[i]; 
    } 

    projectPoints(
     object_points, 
     rotation_vector, 
     translation_vector, 
     intrinsic_matrix, 
     0, 
     image_points 
    ); 
} 

これですべてのものを前に置く避けるためにusingcv名前空間です。 projectPointsのパラメータに何が間違っていますか?

+0

エラーメッセージは...ですか? –

答えて

0

私が見つけたdocumentationprojectPointsために次の宣言を提供します:

void projectPoints(const Mat& objectPoints, const Mat& rvec, const Mat& tvec, const Mat& cameraMatrix, const Mat& distCoeffs, vector<Point2f>& imagePoints); 
void projectPoints(const Mat& objectPoints, const Mat& rvec, const Mat& tvec, const Mat& cameraMatrix, const Mat& distCoeffs, vector<Point2f>& imagePoints, Mat& dpdrot, Mat& dpdt, Mat& dpdf, Mat& dpdc, Mat& dpddist, double aspectRatio=0); 

すべてのケースでは、これらのオブジェクトではなく、オブジェクト自体へのポインタを渡しています。あなたがここに—を動的割り当てを使用している理由、それはほぼ確実に必要はありません、あなたはおそらく、あなたがprojectPointsに何かを渡す前にポインタを間接参照する必要があり—メモリリークを持つようさておき

質問:

projectPoints(
    *object_points, 
    *rotation_vector, 
    *translation_vector, 
    *intrinsic_matrix, 
    0, 
    *image_points 
); 

ます0const Mat&ではないため、distCoeffsパラメータ(おそらく空のMatオブジェクト?)に渡すものを見つける必要があります。

希望に役立ちます。