opencv 怎么将vector<double> XValues, std::vector<double> YValues 放入到mat中两行
时间: 2023-09-24 17:09:23 浏览: 138
将vector<double> XValues和YValues放入到Mat中,每个向量对应矩阵的一行,可以使用以下代码:
```c++
std::vector<double> XValues, YValues;
int Size = XValues.size();
cv::Mat mat_array(2, Size, CV_64F);
// 将XValues和YValues数据复制到Mat的两行中
memcpy(mat_array.row(0).data, XValues.data(), XValues.size()*sizeof(double));
memcpy(mat_array.row(1).data, YValues.data(), YValues.size()*sizeof(double));
```
首先,定义了两个vector<double>对象XValues和YValues,并根据XValues的大小定义了一个2行Size列的Mat对象mat_array。然后,使用memcpy函数将XValues和YValues中的数据分别复制到Mat的两行中。
需要注意的是,这里使用memcpy函数的前提是vector和Mat对象的内存布局是相同的,即在内存中都是连续的double类型数据。如果vector和Mat对象的内存布局不同,需要使用其他方法来实现数据的复制。
相关问题
opencv 怎么将vector<double> YValues 放入mat中
将vector<double> YValues放入Mat中,可以使用以下代码:
```c++
std::vector<double> YValues;
int Size = YValues.size();
cv::Mat mat_array(1, Size, CV_64F);
// 将vector数据复制到Mat中
memcpy(mat_array.data, YValues.data(), YValues.size()*sizeof(double));
```
首先,定义了一个vector<double>对象YValues,然后根据YValues的大小定义了一个Mat对象mat_array。最后,使用memcpy函数将vector中的数据复制到Mat中。
需要注意的是,这里使用memcpy函数的前提是vector和Mat对象的内存布局是相同的,即在内存中都是连续的double类型数据。如果vector和Mat对象的内存布局不同,需要使用其他方法来实现数据的复制。
error: no matching function for call to ‘projectPoints(std::vector<cv::Point3_<float> >&, std::vector<cv::Point_<float> >&, cv::Mat&, cv::Mat&, cv::Mat*&, cv::Mat*&)’ cv::fisheye::projectPoints(vPt3DPnpIn, vPt2DPnpProject, rvec, tvec, K, distCoef); 怎么解决 ^
这个错误提示表明在你的代码中,没有找到与 `projectPoints()` 函数的调用所需参数类型匹配的函数。这个函数的参数类型是:
```
cv::fisheye::projectPoints(
const std::vector<cv::Point3f>& objectPoints,
std::vector<cv::Point2f>& imagePoints,
const cv::Mat& rvec,
const cv::Mat& tvec,
const cv::Mat& K,
const cv::Mat& D,
const double alpha = 0
)
```
你需要检查你的代码,确保参数的类型和数量都正确。如果你确定参数类型和数量都正确,那么可能是因为你没有包含正确的头文件。你需要包含以下头文件:
```
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/calib3d.hpp>
#include <opencv2/fisheye.hpp>
```
如果你已经包含了这些头文件,你可能需要升级你的 OpenCV 版本。这个函数在 OpenCV 3.4.1 版本中引入,如果你使用的是早期版本,它可能不存在。
阅读全文
相关推荐
















