提取与OpenCV中的掩码匹配的图像部分 [英] Extraction part of image that matches to a mask in OpenCV

查看:1270
本文介绍了提取与OpenCV中的掩码匹配的图像部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OpenCV 应用程序中, Python ,我有一个掩码和一个 RGB 图片,我想提取与面具匹配的部分图像,但我不知道如何。

In a OpenCV application with Python, i have a mask and an RGB image, i want to extract part of image that matches to mask but i dont know how.

例如这是一个面具:

for example this is a mask:

我希望这样做:

and i want to do like this:

我这样做:

temp = cv2.bitwise_and(img ,img, mask=feature_map)

但它给了我和错误:

cv2.error: /Users/mee/opencv/modules/core/src/arithm.cpp:1589: error: (-215) (mtype == CV_8U || mtype == CV_8S) && _mask.sameSize(*psrc1) in function binary_op


推荐答案

你可以做类似的事情:

mask = cv2.imread('mask.png',0)
im = cv2.imread('guy.png')
mask_inv =  255 - mask;
final_im = mask_inv*im

这篇关于提取与OpenCV中的掩码匹配的图像部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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