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.
i do this:
temp = cv2.bitwise_and(img ,img, mask=feature_map)
but it gives me and error:
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
You can do something like:
mask = cv2.imread('mask.png',0)
im = cv2.imread('guy.png')
mask_inv = 255 - mask;
final_im = mask_inv*im
您应该将掩码转换为对象掩码像素值为255且背景像素值为0.之后,您可以使用新掩码对RGB图像的每个颜色通道应用和操作或乘法运算。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.