BGR values of masked image (OpenCV, Python)

社会主义新天地 提交于 2019-12-11 10:12:37

问题


Using the follow image..

... I am applying this code to create a circle mask:

import cv2
import numpy as np

img = cv2.imread("car.png")

height, width, depth = img.shape
circle_img = np.zeros((height, width), np.uint8)

mask = cv2.circle(circle_img, (int(width / 2), int(height / 2)), 90, 1, thickness=-1)
masked_img = cv2.bitwise_and(img, img, mask=circle_img)

cv2.imshow("masked", masked_img)
cv2.waitKey(0)

This is the output..

How can I find BGR values of the circle using OpenCV ?


回答1:


You can do it using numpy arrays.

circle_locations = mask == 1
bgr = img[circle_locations]

EDIT: I'm not sure if your mask has values in {0, 1} though I assume it does. If its background value is 0 and all positive values are forground, just change the == 1 to a > 1.



来源:https://stackoverflow.com/questions/50179799/bgr-values-of-masked-image-opencv-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!