opencv中的dft()函数网上只找到了c++接口的,部分代码:
Mat padded; //expand input image to optimal size
int m = getOptimalDFTSize( I.rows );
int n = getOptimalDFTSize( I.cols ); // on the border add zero values
copyMakeBorder(I, padded, 0, m - I.rows, 0, n - I.cols, BORDER_CONSTANT, Scalar::all(0));
Mat planes[] = {Mat_(padded), Mat::zeros(padded.size(), CV_32F)};
Mat complexI;
merge(planes, 2, complexI); // Add to the expanded another plane with zeros
dft(complexI, complexI); // this way the result may fit in the source matrix
链接:http://www.blogbus.com/shijuanfeng-logs/222165953.html
现在需要一个在Android上可以实现的Java代码,我尝试着按上面那个c++代码搬到Java中,代码如下:
Mat bmMat = new Mat();
Utils.bitmapToMat(bm, bmMat); //bm是已经读入了的bitmap,将其转换成Mat
Mat pad=new Mat();
MatOfFloat padded = new MatOfFloat();
int m = Core.getOptimalDFTSize(bmMat.rows());
int n = Core.getOptimalDFTSize(bmMat.cols());
Imgproc.copyMakeBorder(bmMat, pad, 0, m - bmMat.rows(), 0, n- bmMat.cols(),Imgproc.BORDER_CONSTANT, Scalar.all(0));
padded=(MatOfFloat)pad;
Mat[] userid = { padded, Mat.zeros(padded.size(), CvType.CV_32F) };
List planes = Arrays.asList(userid);
Mat complexI = new Mat();
Core.merge(planes, complexI);
Core.dft(complexI, complexI);
可是运行失败,我感觉是c++中Mat_(padded)和Java中MatOfFloat这一块没有对应上,所以出现了问题。求大神解答,谢谢!!!