遮罩图像的BGR值(OpenCV,Python) [英] BGR values of masked image (OpenCV, Python)
本文介绍了遮罩图像的BGR值(OpenCV,Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用后续图片.
...我正在应用以下代码来创建圆形蒙版:
... 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)
这是输出.
如何使用OpenCV查找圆的BGR值?
How can I find BGR values of the circle using OpenCV ?
推荐答案
您可以使用numpy数组来实现.
You can do it using numpy arrays.
circle_locations = mask == 1
bgr = img[circle_locations]
我不确定您的掩码是否具有{0,1}中的值,尽管我认为确实如此.如果它的背景值为0,并且所有正值为前景,则只需将== 1
更改为> 1
.
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
.
这篇关于遮罩图像的BGR值(OpenCV,Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文