当前位置:   article > 正文

python画四边形_在python matplotlib中将不规则的四边形转换为...

python 四边形图转正方形

您可以使用scikit-image中的skimage.transform.ProjectiveTransform将四边形内部的坐标转换为局部正方形空间[0,1]×[0,1].

假设您按顺时针顺序有四边形的角:

bottom_left = [58.6539, 31.512]

top_left = [27.8129, 127.462]

top_right = [158.03, 248.769]

bottom_right = [216.971, 84.2843]

我们实例化一个ProjectiveTransform,并要求它在四边形到单位正方形的内侧找到投影变换映射点:

from skimage.transform import ProjectiveTransform

t = ProjectiveTransform()

src = np.asarray(

[bottom_left, top_left, top_right, bottom_right])

dst = np.asarray([[0, 0], [0, 1], [1, 1], [1, 0]])

if not t.estimate(src, dst): raise Exception("estimate failed")

现在,转换t已准备好将您的点转换为单位平方.当然,通过更改上面的dst,您可以缩放到与单位正方形不同的矩形(甚至缩放到完全不同的四边形).

data = np.asarray([

[69.1216, 51.7061], [72.7985, 73.2601], [75.9628, 91.8095],

[79.7145, 113.802], [83.239, 134.463], [86.6833, 154.654],

[88.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/86742
推荐阅读
相关标签
  

闽ICP备14008679号