如何使用python opencv2减去两个图像以获取前景对象 [英] How to subtract two images using python opencv2 to get the foreground object

查看:299
本文介绍了如何使用python opencv2减去两个图像以获取前景对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以在python opencv2中减去两个图像?

Is there any way to subtract two images in python opencv2 ?

  • 图片1:任何图片(例如房屋图片)(静态图片)
  • 图像2:与对象相同的图像(在室内,一个人正站着……) (静态图片+动态对象)
  • 图片3 =图片2-图片1
  • Image 1 : Any image (eg. a house Image) (static image)
  • Image 2 : The same Image with an Object (In house, a person is standing...) (static image + dynamic objects)
  • Image 3 = Image 2 - Image 1

如果我们从Image1中减去Image2,则意味着Image3应该只给出Object(person).

If we subtract Image2 from Image1 means Image3 should give Object(person) only.

推荐答案

如果两张图片中的背景完全相同,则可以按照您在帖子中提到的方式减去它们.

If the background in the two images are exactly the same, you can subtract them as you mention in your post.

image1 = imread("/path/to/image1")
image2 = imread("/path/to/image2")
image3 = image1 - image2

这篇关于如何使用python opencv2减去两个图像以获取前景对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆