Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ OpenCV convertTo如何转换?_C++_Opencv - Fatal编程技术网

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)