Yasin Kumar Yasin Kumar - 12 days ago 6
C++ Question

error when i using cv::merge

I have a problem when i using cv::merge()
statement to merging two image,
and i get this errors:

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



(same error for my methods!)

I tried for solve this problem by search and using some methods but my struggle not be usefull.

my methods was here :

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 its:

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 beginner in opencv and confused .
can anyone help me?

Answer

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.

Comments