C++ OpenCV convertTo如何转换?
我将灰度模式下的图像加载到C++ OpenCV convertTo如何转换?,c++,opencv,C++,Opencv,我将灰度模式下的图像加载到Mat image中。我使用image.convertTo(image,CV_32F) 将数据类型转换为双精度。我想将图像转换为向量,因此我以以下方式迭代矩阵: int channels = image.channels(); int nRows = image.rows; int nCols = image.cols; vector<double> vectorizedMatrix (nRows*nCols); i
Mat image
中。我使用image.convertTo(image,CV_32F)代码>
将数据类型转换为双精度。我想将图像转换为向量
,因此我以以下方式迭代矩阵:
int channels = image.channels();
int nRows = image.rows;
int nCols = image.cols;
vector<double> vectorizedMatrix (nRows*nCols);
if (image.isContinuous()) {
nCols *= nRows;
nRows = 1;
}
double* pI;
int k = 0;
for (int i=0; i<nRows; i++) {
pI = image.ptr<double>(i);
for (int j=0;j<nCols;j++) {
vectorizedMatrix.at(k) = pI[j];
k++;
}
}
return vectorizedMatrix;
int channels=image.channels();
int nRows=image.rows;
int nCols=image.cols;
向量向量矩阵(nRows*nCols);
if(image.isContinuous()){
nCols*=nRows;
nRows=1;
}
双*π;
int k=0;
对于(int i=0;i“我使用image.convertTo(image,CV_32F);将数据类型转换为double”
不,这将转换为浮点。如果您想要双精度,请使用:
image.convertTo(图像,CV_64F)