问题描述
我想实现在Android上DCT code。我使用的分割和合并方法来获取图像的原始颜色。
I am trying to implement a DCT code in Android. I'm using the split and merge method to obtain the original colors of the image.
下面是code的代码片段
Here is the snippet of the code
image = Highgui.imread(imageName);
secondImage = new Mat(image.rows(), image.cols(), CvType.CV_32FC3);
image.convertTo(secondImage, CvType.CV_32FC3);
int m = Core.getOptimalDFTSize(image.rows());
int n = Core.getOptimalDFTSize(image.cols()); // on the border add zero values
Mat padded = new Mat(new Size(n, m), CvType.CV_32FC3); // expand input image to optimal size
Imgproc.copyMakeBorder(secondImage, padded, 0, m - secondImage.rows(), 0, n - secondImage.cols(), Imgproc.BORDER_CONSTANT);
List<Mat> planes = new ArrayList<Mat>();
Core.split(padded, planes);
List<Mat> outplanes = new ArrayList<Mat>(planes.size());
for (int k = 0; k < planes.size(); k++) {
outplanes.add(new Mat(padded.size(), CvType.CV_32FC1));
}
Mat trans = new Mat(padded.size(), padded.type());
for (int k = 0; k < planes.size(); k++) {
Core.dct(planes.get(k), outplanes.get(k));
}
List<Mat> ioutplanes = new ArrayList<Mat>(outplanes.size());
for (int k = 0; k < planes.size(); k++) {
ioutplanes.add(new Mat(padded.size(), CvType.CV_32FC1));
}
for (int k = 0; k < planes.size(); k++) {
Core.idct(outplanes.get(k), ioutplanes.get(k));
}
Core.merge(ioutplanes, trans);
这时候得到这个异常:
This time got this exception :
的功能/特性尚未实现在虚空CV(奇数大小的DCT的未实现):: DCT(CV :: InputArray,CV :: OutputArray,INT),文件/ home /报告/ CI / slave_desktop / 50 -SDK / OpenCV的/模块/核心/ src目录/ dxt.cpp,线路2330
这是code正确吗?你的帮助是非常AP preciated。
Is this code correct? Your help is very much appreciated.
更新:我注意到copyMakeBorder()是导致我的图像大小为奇数的人,这就是为什么我有这个例外
Updated: I noticed that the copyMakeBorder() is the one that caused my image size to be odd, that is why I am having this exception.
推荐答案
也许你可以改变这个code
Maybe you can change this code
int m = Core.getOptimalDFTSize(image.rows());
int n = Core.getOptimalDFTSize(image.cols());
到
int m =Core.getOptimalDFTSize((image.rows()+1)/2)*2;
int n = Core.getOptimalDFTSize((image.cols()+1)/2)*2;
为了获得DCT奇数大小,因为该功能是用于DFT
in order to get the odd size for DCT, since this function is for DFT.
这是写的函数文档从网站,这样的:
It is written in the function documentation from the website as this:
虽然功能不能直接用于估计的最优矢量大小为DCT变换(因为当前的DCT实现支持仅偶数大小的载体)时,它可以很容易地处理为getOptimalDFTSize((vecsize + 1)/ 2)* 2。
While the function cannot be used directly to estimate the optimal vector size for DCT transform (since the current DCT implementation supports only even-size vectors), it can be easily processed as getOptimalDFTSize((vecsize+1)/2)*2.
这篇关于OpenCV的 - 实现拆分和合并为DCT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!