Yasin Kumar
Yasin Kumar

Reputation: 189

error when i using cv::merge

I am getting following error while using cv::merge() statement to merge two images:

OpenCV Error: Assertion failed (mv[i].size == mv[0].size && mv[i].depth() == depth) in merge, file /home/yasin/ProgramFile/opencv-3.0.0/modules/core/src/convert.cpp, line 950 terminate called after throwing an instance of 'cv::Exception' what(): /home/yasin/ProgramFile/opencv-3.0.0/modules/core/src/convert.cpp:950: error: (-215) mv[i].size == mv[0].size && mv[i].depth() == depth in function merge

I tried to solve this problem by searching and using some methods but my effort was not useful.

My methods are:

void TakeDFT(cv::Mat&source,cv::Mat&DFTofSource){
    cv::Mat OriginalFloat;
    OriginalFloat.convertTo(source,CV_32FC1,1.0/255.0);
    cv::Mat OriginalComplex[2] = {
        OriginalFloat,cv::Mat::zeros(OriginalFloat.size(),CV_32F)
    };
    cv::Mat dftready;
    dftready.convertTo(dftready,CV_32F);
    cv::merge(OriginalComplex,2,dftready);
    cv::dft(dftready,DFTofSource,cv::DFT_COMPLEX_OUTPUT);
}

and:

void TakeDFT(cv::Mat&source,cv::Mat&DFTofSource){
    cv::Mat OriginalFloat;
    OriginalFloat.convertTo(source,CV_32FC1,1.0/255.0);
    cv::Mat OriginalComplex[2] = {
        OriginalFloat,cv::Mat::zeros(OriginalFloat.size(),CV_32F)
    };
    cv::Mat dftready;
    dftready.convertTo(dftready,CV_32F);
    std::vector<cv::Mat>array_to_merge;
    array_to_merge.push_back(OriginalComplex[0]);
    array_to_merge.push_back(OriginalComplex[1]);
    cv::merge(array_to_merge,dftready);
    cv::dft(dftready,DFTofSource,cv::DFT_COMPLEX_OUTPUT);
}

I'm a beginner in opencv and confused. can anyone help me?

Upvotes: 3

Views: 14280

Answers (2)

Bentoy13
Bentoy13

Reputation: 4966

From the OpenCV 3.0 documentation:

The functions merge merge several arrays to make a single multi-channel array.

Your destination matrix dftready is created as one-channel matrix (CV_32F) instead of 2-channel matrix with CV_32FC2.

Upvotes: 1

Axel B.
Axel B.

Reputation: 131

You are only declaring OriginalFloat (not defining it), and then you try to convert it (while it's an empty matrix).

I assume what you want to do is rather

source.convertTo(OriginalFloat, CV_32FC1, 1.0/255.0);

You will have the same problem with dftready. What you need to do is either to define its type by creating the matrix: cv::Mat dftready = cv::Mat dftready(source.size(), CV_32F);, or simply declaring it cv::Mat dftready; and let the cv::merge function creating it with the right type.

Upvotes: 0

Related Questions