如何使用 Python 中的 PIL 或 opencv 比较图像的坐标值,将图像粘贴到另一图像?

2024-01-07

我需要根据坐标值合并两个图像。

我已经使用单点到点合并完成了合并使用 Python 中的 PIL 或 OpenCV 将图像粘贴到两个给定坐标处的另一图像,并更改不透明度 https://stackoverflow.com/questions/65236363/paste-an-image-to-another-image-at-two-given-co-ordinates-with-altered-opacity-u

我得到了输出。 但我需要进行多个坐标比较并合并到相同的 2 个图像中。 有没有可能的方法来做到这一点?

上图是结果。输出只有单点到点合并。但我需要多点合并。

参数为{“Headpts”:[354,64,“ShoulderSpinepts”:[25,234],“LeftShoulderpts”:[123,243],“LeftElbowpts”:[54,234],“LeftHandpts”:[0, 0],“RightShoulderpts” : [0, 0], "RightElbowpts": [0, 0], "RightHandpts": [0, 0], "MidSpinepts": [0, 0], "BaseSpinepts": [0, 0], "LeftHippts" : [0, 0], "LeftKneepts": [0, 0], "LeftFootpts": [0, 0], "RightHippts": [0, 0], "RightKneepts": [0, 0], "RightFootpts" : [0, 0], "左手腕": [0, 0], "右手腕": [0, 0], "颈部": [0, 0]}


我在用着cv2.getAffineTransform()。因为它只能加三个点(上只能加四个点)cv2.getPerspectiveTransform()),所以我将图像剪切为多个三角形。

这是我的样本:

enter image description here The point:enter image description here

我的目标是将猫的头部重塑成一个 300*300 的盒子。

首先,裁剪面积成三角形根据要点。

And then usingcv2.getAffineTransform() to get those specific area which had been adjusted. enter image description here enter image description here enter image description here

Then use cv2.bitwise_or() to add them together. Generated image: enter image description here

你的项目更复杂,但理论是相同的。您需要将图像裁剪为几个三角形。进而改造他们来拟合模型。后将这些三角形合并在一起,你就可以得到你的图像了。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 Python 中的 PIL 或 opencv 比较图像的坐标值,将图像粘贴到另一图像? 的相关文章

随机推荐