小编Ton*_*Lin的帖子

OpenCV getPerspectiveTransform 和 warpPerspective Java

我目前有一个ArrayList<MatOfPoint>存储图像轮廓并检索到最大轮廓的轮廓,这是我的 warpPerspective 目标。

List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Imgproc.findContours(matOut, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);

sort(contours);
MatOfPoint2f  m2f = MatOfPoint2f(contours.get(0).toArray());
double arc = Imgproc.arcLength(m2f, true);
MatOfPoint2f approx = new MatOfPoint2f();
Imgproc.approxPolyDP(m2f, approx, arc*0.02, true);
Run Code Online (Sandbox Code Playgroud)

我在如何使用 getPerspectiveTransform 然后应用 warpPerspective 来更改图像以使其适合 450x450 图像时遇到问题。

我在 python 中找到了一个很好的例子,但是我对它不是很熟悉,有人可以解释我将如何在 java 中进行纠正吗?

def rectify(h):
    ''' this function put vertices of square we got, in clockwise order '''
    h = h.reshape((4,2))
    hnew = np.zeros((4,2),dtype = np.float32)

    add = h.sum(1)
    hnew[0] = h[np.argmin(add)]
    hnew[2] = h[np.argmax(add)]

    diff …
Run Code Online (Sandbox Code Playgroud)

java opencv transformation perspective

2
推荐指数
1
解决办法
5851
查看次数

标签 统计

java ×1

opencv ×1

perspective ×1

transformation ×1