问题
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:
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
回答1:
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
回答2:
You should convert your mask as being object mask pixels value is 255 and background pixels value is 0. After that you can apply and operation or multiply operation for each color channel of RGB image with new mask .
来源:https://stackoverflow.com/questions/34466597/extraction-part-of-image-that-matches-to-a-mask-in-opencv