我是OpenCV的新成员。我刚收到一个错误,我无法理解为什么会这样,并且不知道如何解决它。
有我的代码。
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(int argc, char *argv[])
{
Mat I = imread("water.jpg", 0);
Mat W = imread("laosiji.jpg", CV_LOAD_IMAGE_GRAYSCALE);
cout << I.channels() << endl;
Mat CI(I.rows,I.cols,CV_32FC);
I.convertTo(CI, CV_32FC);
Mat FI;
Mat IFI;
dft(CI,FI,DFT_COMPLEX_OUTPUT | DFT_SCALE);
idft(FI,IFI);
imshow("water.jpg after idft transformation",IFI);
return 0;
}
当我运行该程序时,它给了我一个错误:
OpenCV Error: Bad number of channels (Source image must have 1, 3 or 4 channels) in cvConvertImage, file /var/tmp/portage/media-libs/opencv-3.1.0-r7/work/opencv-3.1.0/modules/imgcodecs/src/utils.cpp, line 611
terminate called after throwing an instance of 'cv::Exception'
what(): /var/tmp/portage/media-libs/opencv-3.1.0-r7/work/opencv-3.1.0/modules/imgcodecs/src/utils.cpp:611: error: (-15) Source image must have 1, 3 or 4 channels in function cvConvertImage
然而,从上面的代码来看,程序输出的频道是1.我很难摆弄这个问题,因为我对OpenCV不是很熟悉,任何老手都可以出来解释一下我?提前谢谢。