opencv:Assertion failed (type == CV_32FC1 || type == CV_64FC1) in cv::dct

使用opencv中的dct()函数进行离散余弦变换时出现如下错误:

OpenCV Error: Assertion failed (type == CV_32FC1 || type == CV_64FC1) in cv::dct, file .......

原问题处:

    Mat src = imread("son.jpg", 0); 
    if(src.empty())
    {
        cout << "the image is not exist" << endl;  
        return -1;
    }
    resize(src, src, Size(32, 32));
    Mat srcDCT; 
    dct(src, srcDCT);

后打印出src.type()发现为0即CV_8U,而非要求的CV_32F或CV_64F故引发错误。

使用convertTo()将图像类型转换为CV_32F。更改后问题消除:

    Mat src = imread("E:\\image\\image\\image\\person.jpg", 0); 
    if(src.empty())
    {
        cout << "the image is not exist" << endl;  
        return -1;
    }
    resize(src, src, Size(32, 32));
    src.convertTo(src, CV_32F, 1.0/255.0);
    //cout<"\n";
    Mat srcDCT; 
    dct(src, srcDCT);

矩阵类型:
opencv:Assertion failed (type == CV_32FC1 || type == CV_64FC1) in cv::dct_第1张图片

你可能感兴趣的:(OpenCV,opencv,dct)