将项目点从 C 转换为 C++
Converting projectPoints from C to C++
我正在尝试将cvProjectPoints2的简单代码转换为C++,所以我正在使用cv::P rojectPoints。 我using
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
的参数有什么问题?
我找到的文档给出了以下projectPoints
声明:
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
);
然后,您需要找到要为 distCoeffs
参数传递的内容(也许是一个空的 Mat
对象?),因为0
不是const Mat&
。
希望有帮助。
相关文章:
- 防止主数据类型C++的隐式转换
- 模板参数替换失败,并且未完成隐式转换
- 努力将整数转换为链表。不知道我在这里做错了什么
- HEX值到wchar_t字符(UTF-8)的转换
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将 Qvector<uint8_t> 转换为 QString
- 如何在cuSparse中使用cusparseXcoo2csr从coo转换为csc
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 在c++中使用nlohmann从类到json的转换
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 将Integer转换为4字节的unsined字符矢量(按大端字节顺序)
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- 复制列表初始化的隐式转换的等级是多少
- 正在将指针转换为范围
- 如何防止 c++ 在从浮点型转换为双精度型(不适用于 IO)时添加额外的小数?
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 是否可以从int转换为enum类类型
- 了解 GLM- openGL 中的相机转换
- 将无符号char*转换为std::istream*C++