将项目点从 C 转换为 C++
我正在尝试将 cvProjectPoints2 的简单代码转换为 C++,因此我使用 cv::ProjectPoints。我使用
cv
命名空间以避免在所有内容前加上 cv::
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
);
}
这根本无法编译。 projectPoints
的参数有什么问题?
I'm trying to convert simple code for cvProjectPoints2 to C++, so I'm using cv::ProjectPoints. I'm using
the cv
namespace to avoid prefixing everything with cv::
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
);
}
This simply will not compile. What is wrong with the parameters to projectPoints
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现的文档给出了
projectPoints:
在所有情况下,您都会传递指向这些对象的指针,而不是对象本身。
抛开为什么在这里使用动态分配的问题 - 几乎可以肯定没有必要,而且你可能会出现内存泄漏 - 在将任何内容传递给
projectPoints
之前,你需要取消引用指针:然后你需要找到为
distCoeffs
参数传递一些内容(可能是一个空的Mat
对象?),因为0
不是const Mat&
>。希望有帮助。
The documentation I've found gives the following declarations for
projectPoints
:In all cases, you're passing pointers to these objects, not the objects themselves.
Questions aside as to why you're using dynamic allocation here — it's almost certainly not necessary, and you probably have memory leaks — you need to dereference the pointers before passing anything to
projectPoints
:You then need to find something to pass for the
distCoeffs
parameter (perhaps an emptyMat
object?) because0
is not aconst Mat&
.Hope that helps.