【发布时间】:2019-10-18 05:17:13
【问题描述】:
我正在尝试比较并检查两张图片是否相互匹配。我在 android studio 中找不到与 OpenCV java 进行比较的合适教程。所以,我找到了一些步骤并开始计算直方图,这样我就可以比较两张图像的直方图,然后看看它们是否匹配。
我已经编写了以下方法来计算直方图,然后进行比较。
Mat matB2 = new Mat(sourceSize, sourceMat.type());
Mat matG2 = new Mat(sourceSize, sourceMat.type());
Mat matR2 = new Mat(sourceSize, sourceMat.type());
Imgproc.calcHist(channels2, allChannel2[0], new Mat(), matB2, hisSize2, histRange2);
Imgproc.calcHist(channels2, allChannel2[1], new Mat(), matG2, hisSize2, histRange2);
Imgproc.calcHist(channels2, allChannel2[2], new Mat(), matR2, hisSize2, histRange2);
Toast.makeText(MainActivity.this, "test", Toast.LENGTH_SHORT).show();
int graphHeight2 = 300;
int graphWidth2 = 200;
int binWidth2 = 3;
Mat graphMat2 = new Mat(graphHeight2, graphWidth2, CvType.CV_8UC3, new Scalar(0, 0, 0));
//Normalize channel
Core.normalize(matB2, matB2, graphMat2.height(), 0, Core.NORM_INF);
Core.normalize(matG2, matG2, graphMat2.height(), 0, Core.NORM_INF);
Core.normalize(matR2, matR2, graphMat2.height(), 0, Core.NORM_INF);
//Comparing histograms
int compareMethod = 1;
double comparisonValueB = Imgproc.compareHist(matB,matB2, Imgproc.CV_COMP_CORREL);
double comparisonValueG = Imgproc.compareHist(matG,matG2,Imgproc.CV_COMP_CORREL);
double comparisonValueR = Imgproc.compareHist(matR,matR2,Imgproc.CV_COMP_CORREL);
Toast.makeText(MainActivity.this, "comparisonValueB::"+comparisonValueB, Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.this, "comparisonValueG::"+comparisonValueG, Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.this, "comparisonValueR::"+comparisonValueR, Toast.LENGTH_SHORT).show();
但是,我从添加了比较值的三个 toast 中得到的结果是,
- **comparisonValueB:**1984.5519 **比较值G:**2159.2307 **comparisonValueR:**3420.9038
我不明白这些值的含义。有人可以让我知道这些值的含义以及如何确定图像是否相似。 值也不应该介于 0 和 1 之间,其中 1 是最高匹配,0 是最低匹配?
我对 OpenCV 很陌生,所以请帮助我。如果我比较错误,请告诉我正确的方法。
【问题讨论】: