【发布时间】:2018-10-14 07:13:19
【问题描述】:
我尝试在 openCV 和 PIL 中叠加 openCV 中的两个图像,但无济于事。我正在使用np.zeros 的1000x1000x3 数组作为背景(又名黑色背景)和this 显示器的随机图像,但由于某种我不知道的原因,我真的无法让它工作。
仅尝试使用 OpenCV:(result(如果你注意的话,你会在中间看到几条奇怪的线和点))
base_temp = np.zeros((1000,1000,3))
foreground_temp = cv2.imread('exampleImageThatILinkedAbove.png')
base_temp[offset_y:offset_y+foreground_temp.shape[0], offset_x:offset_x+foreground_temp.shape[1]] = foreground_temp
尝试使用 PIL:(结果与 OpenCV 版本字面上相同)
base_temp = cv2.convertScaleAbs(self.base) #Convert to uint8 for cvtColor
base_temp = cv2.cvtColor(base_temp, cv2.COLOR_BGR2RGB) #PIL uses RGB and OpenCV uses BGR
base_temp = Image.fromarray(base_temp) #Convert to PIL Image
foreground_temp = cv2.cvtColor(cv2.convertScaleAbs(self.last_img), cv2.COLOR_BGR2RGB)
foreground_temp = Image.fromarray(foreground_temp)
base_temp.paste(foreground_temp, offset)
我在 Windows 10 上使用 python3.5 和 OpenCV3.4,如果有帮助的话。
我希望 喜欢 避免任何需要保存 cv2 图像然后在另一个模块中重新加载它们以进行转换的解决方案,但如果这是不可避免的,那也没关系。任何帮助将不胜感激!
【问题讨论】:
-
你期望得到什么样的结果图像?
-
@DmitriiZ。
foreground_temp就在base_temp的中间——或者至少根据提供的偏移量粘贴在base_temp的中间
标签: python opencv python-imaging-library cv2