gpt4 book ai didi

java - OpencCv - 将像素映射到 `warpAffine` 或 `warpPerspective` 之后的新位置(投影变换/形态操作)

转载 作者:行者123 更新时间:2023-12-02 09:01:24 34 4
gpt4 key购买 nike

我有以下代码:

        Rect rect = Imgproc.boundingRect(screenCnt2f);

// do transpose
Mat destImage = new Mat(new Size(rect.width, rect.height), orig.type());
Mat src = orderPointsClockwise(screenCnt2f);
dst = new MatOfPoint2f(new Point(0, 0), new Point(rect.width - 1, 0),
new Point(rect.width - 1, rect.height - 1), new Point(0, rect.height - 1));
Mat transform = Imgproc.getPerspectiveTransform(src, dst);
Imgproc.warpPerspective(orig, destImage, transform, destImage.size());

如果我在位置 x,y 处有一个像素,

如何计算 destImage 中相同像素的位置?

因此,如果Point p包含x,y值,我想要一个方法newPointLocation:

Point pp = newPointLocation(p, tranform);

使ppdestImage中包含相同的像素

warpAffine相同的代码:

    Point center = new Point(src.width() / 2, src.height() / 2);
Mat rotImage = Imgproc.getRotationMatrix2D(center, angle, 1.0);
// 1.0 means 100 % scale
Size size = new Size(src.width(), src.height());
Imgproc.warpAffine(src, src, rotImage, size, Imgproc.INTER_LINEAR + Imgproc.CV_WARP_FILL_OUTLIERS);

Point pp = newPointLocation(p, rotImage);

最佳答案

您可以使用Core.transform(matOfPoint, dst, rotImage)来实现

代码:

    Point center = new Point(source.width() / 2, source.height() / 2);
Mat rotImage = Imgproc.getRotationMatrix2D(center, angle, 1.0);
// 1.0 means 100 % scale
Size size = new Size(source.width(), source.height());
Imgproc.warpAffine(source, source, rotImage, size, Imgproc.INTER_LINEAR + Imgproc.CV_WARP_FILL_OUTLIERS);

// calculate new bounding box location
// zBoundingBox contain the matOfPoint that describe the bounding box in the Orig location
for (ZBoundingBox zBoundingBox : boundingBoxesOrig) {
MatOfPoint matOfPoint = zBoundingBox.matOfPoint, dst = new MatOfPoint();
Core.transform(matOfPoint, dst, rotImage);
boundingBoxes.add(dst); // Add to predefined collection
}

关于java - OpencCv - 将像素映射到 `warpAffine` 或 `warpPerspective` 之后的新位置(投影变换/形态操作),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60134413/

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