简体   繁体   English

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

[英]How can I paste an image to another image by comparing its coordinate values using PIL or opencv in Python?

I need to merge two images with respect to its coordinate values.我需要合并两个图像的坐标值。

I have done merging using single point to point merge using Paste an image to another image at two given co-ordinates with altered opacity using PIL or OpenCV in Python我已经使用单点到点合并完成了合并,使用在两个给定坐标处将图像粘贴到另一个图像,在 Python 中使用 PIL 或 OpenCV 更改不透明度

I got output for that.为此,我得到了 output。 But I need to do multiple coordinate comparison and merge in same 2 images.. Is there any possible way to do that?但是我需要进行多坐标比较并合并到相同的 2 张图像中。有没有可能的方法来做到这一点?

输入1

输入 2

结果

Above images are the results.上图是结果。 Output has only single point to point merge. Output 只有单点对点合并。 But I need in multiple point merge.但我需要多点合并。

The parameters are {"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], "LeftWristpts": [0, 0], "RightWristpts": [0, 0], "Neckpts": [0, 0]}参数是 {"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], "LeftWristpts": [0, 0], "RightWristpts": [0, 0], "Neckpts": [0, 0]}

I'm using cv2.getAffineTransform() .我正在使用cv2.getAffineTransform() Because it can only add three point (only four on cv2.getPerspectiveTransform() ), so I cut the image to multiple triangle.因为它只能添加三个点(在cv2.getPerspectiveTransform()上只有四个),所以我将图像切割成多个三角形。

This is my sample:这是我的样本:

在此处输入图像描述 The point:要点: 在此处输入图像描述

And my goal is to reshape the cat's head in to a 300*300 box.而我的目标是将猫的头部重塑成一个 300*300 的盒子。

First, crop the area into triangle according the point.首先,根据点将区域裁剪成三角形

在此处输入图像描述

And then using cv2.getAffineTransform() to get those specific area which had been adjusted.然后使用cv2.getAffineTransform()来获取那些已经调整过的特定区域。 在此处输入图像描述 在此处输入图像描述 在此处输入图像描述

Then use cv2.bitwise_or() to add them together.然后使用cv2.bitwise_or()将它们加在一起。 Generated image:生成的图像: 在此处输入图像描述

Your project is more complex, but it's the same theory.你的项目更复杂,但它是相同的理论。 You need crop the image into several triangle .您需要将图像裁剪成几个三角形 And then transform them to fit the model.然后将它们转换为适合 model。 After merge those triangle together , you can get your image.将这些三角形合并在一起后,您就可以得到您的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM