gpt4 book ai didi

android - 特征检测后OpenCV Android提取匹配Mat

转载 作者:行者123 更新时间:2023-12-02 17:13:43 24 4
gpt4 key购买 nike

我想提取与我的引用图像匹配的图像部分。
我尝试使用 Calib3d.findHomography 方法转换图像。
完成此操作后,我使用 Imgproc.warpPerspective 进行转换,但没有好的结果。我在这里想念什么吗?
我需要对透视变换做些什么吗?我已经尝试过了,但到目前为止没有任何运气。

这是我的 findSceneCorners 方法:

 private void findSceneCorners(Mat src) {
mFeatureDetector.detect(src, mSceneKeypoints);
mDescriptorExtractor.compute(src, mSceneKeypoints, mSceneDescriptors);
mDescriptorMatcher.match(mSceneDescriptors, mReferenceDescriptors, mMatches);

List<DMatch> matchesList = mMatches.toList();
if (matchesList.size() < 4) {
// There are too few matches to find the homography.
return;
}

List<KeyPoint> referenceKeypointsList =
mReferenceKeypoints.toList();
List<KeyPoint> sceneKeypointsList =
mSceneKeypoints.toList();

// Calculate the max and min distances between keypoints.
double maxDist = 0.0;
double minDist = Double.MAX_VALUE;
for(DMatch match : matchesList) {
double dist = match.distance;
if (dist < minDist) {
minDist = dist;
}
if (dist > maxDist) {
maxDist = dist;
}
}

// The thresholds for minDist are chosen subjectively
// based on testing. The unit is not related to pixel
// distances; it is related to the number of failed tests
// for similarity between the matched descriptors.
if (minDist > 50.0) {
// The target is completely lost.
// Discard any previously found corners.
mSceneCorners.create(0, 0, mSceneCorners.type());
return;
} else if (minDist > 20.0) {
// The target is lost but maybe it is still close.
// Keep any previously found corners.
return;
}


// Identify "good" keypoints based on match distance.
ArrayList<Point> goodReferencePointsList =
new ArrayList<Point>();
ArrayList<Point> goodScenePointsList =
new ArrayList<Point>();

double maxGoodMatchDist = 1.75 * minDist;
for(DMatch match : matchesList) {
if (match.distance < maxGoodMatchDist) {
goodReferencePointsList.add(
referenceKeypointsList.get(match.trainIdx).pt);
goodScenePointsList.add(
sceneKeypointsList.get(match.queryIdx).pt);
}
}

if (goodReferencePointsList.size() < 4 ||
goodScenePointsList.size() < 4) {
// There are too few good points to find the homography.
return;
}

Log.i(TAG, "Match found");

MatOfPoint2f goodReferencePoints = new MatOfPoint2f();
goodReferencePoints.fromList(goodReferencePointsList);

MatOfPoint2f goodScenePoints = new MatOfPoint2f();
goodScenePoints.fromList(goodScenePointsList);

homography = Calib3d.findHomography(goodReferencePoints, goodScenePoints);

Mat quad = new Mat(mReferenceImage.size(), CvType.CV_32F);
Imgproc.warpPerspective(src, quad, homography, quad.size());
objectDetectedListener.objectDetected(quad);

}

最佳答案

我认为你应该使用 WARP_INVERSE_MAP作为warpPerspective的旗帜如:Imgproc.warpPerspective(src, quad, homography, quad.size(),WARP_INVERSE_MAP); .

我没有完全使用您的代码,而只是使用了单应性之后的部分,而且我已经看到镜像中的图像被扭曲了,而不是我们想要的(使用更大的显示图像来确切地查看那里的内容)。实际上,在您发布的页面上,使用 10 卡,它使用了那个标志,抱歉我之前没有想到要提到这个。

关于android - 特征检测后OpenCV Android提取匹配Mat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21087804/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com