英文:
Blend an image into another with Python
问题
我正在尝试使用Python将一幅图像混合到另一幅图像中,以将其设置为壁纸,用于淡入动画的每一帧。我查看了一些论坛,但没有找到任何人尝试做同样的事情,而且我以前从未在Python中进行过照片编辑,只是游戏相关的内容,而我现在正在做的完全不同。
英文:
I am trying to blend an image into another with python to set as your wallpaper for every frame of the fading animation.
I've look on several fourms and haven't found anyone trying to do the same thing and I have never messed with photo editing in python just game stuff and what im doing is completely different.
答案1
得分: 0
I have two png pictures, a smily and a green triangle. Then you can use openCV to perform operations like this:
import cv2
import numpy as np
image1 = cv2.imread('Face1.png')
image2 = cv2.imread('Nose1.png')
print(f"Size of image 1 and image 2 is {image1.shape} and {image2.shape}")
image2_resized = cv2.resize(image2, (image1.shape[1], image1.shape[0]))
print(f"After reshaping, image 1 and image 2 (after resizing) are {image1.shape} and {image2_resized.shape}")
blended_image = cv2.addWeighted(src1=image1, alpha=0.5, src2=image2_resized, beta=0.5, gamma=0)
#cv2.imshow('Im1', image2)
#cv2.imshow('Im2', image2)
cv2.imshow('Blended', blended_image)
cv2.waitKey(0)
Output:
英文:
I have two png pictures a smily and a green triangle. Than you can do e.g. with openCV something like:
import cv2
import numpy as np
image1 = cv2.imread('Face1.png')
image2 = cv2.imread('Nose1.png')
print(f"Size image 1 and image 2 is {image1.shape} and {image2.shape}")
image2_resized = cv2.resize(image2, (image1.shape[1],image1.shape[0]))
print(f"After reshape image 1 and image 2 (after resizing) is {image1.shape} and {image2_resized.shape}")
blended_image = cv2.addWeighted(src1=image1,alpha=0.5,src2=image2_resized,beta=0.5,gamma=0)
#cv2.imshow('Im1',image2)
#cv2.imshow('Im2',image2)
cv2.imshow('Blended',blended_image)
cv2.waitKey(0)
Output:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论