本文整理匯總了Python中cv2.COLOR_BGR2YCrCb方法的典型用法代碼示例。如果您正苦於以下問題:Python cv2.COLOR_BGR2YCrCb方法的具體用法?Python cv2.COLOR_BGR2YCrCb怎麽用?Python cv2.COLOR_BGR2YCrCb使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cv2
的用法示例。
在下文中一共展示了cv2.COLOR_BGR2YCrCb方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: describe
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2YCrCb [as 別名]
def describe(self, image, mask):
image = cv.cvtColor(image, cv.COLOR_BGR2YCrCb)
hist_y = cv.calcHist([image], [0], mask, self.bins,
[0, 256])
hist_cr = cv.calcHist([image], [1], mask, self.bins,
[0, 256])
hist_cb = cv.calcHist([image], [2], mask, self.bins,
[0, 256])
hist_y = hist_y / np.sum(hist_y)
hist_cr = hist_cr / np.sum(hist_cr)
hist_cb = hist_cb / np.sum(hist_cb)
# 24 dimensions
return np.concatenate([hist_y, hist_cr, hist_cb], axis=0).reshape(-1)
開發者ID:JACKYLUO1991,項目名稱:Face-skin-hair-segmentaiton-and-skin-color-evaluation,代碼行數:16,代碼來源:cal_histogram.py
示例2: make_dataset
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2YCrCb [as 別名]
def make_dataset(dir):
images = []
assert os.path.isdir(dir), '%s is not a valid directory' % dir
for root, _, fnames in sorted(os.walk(dir)):
for fname in fnames:
if is_image_file(fname):
path = os.path.join(root, fname)
images.append(path)
return images
# Python opencv library (cv2) cv2.COLOR_BGR2YCrCb has different parameters with MATLAB color convertion.
# In order to have a fair comparison with the benchmark, we wrote these functions by ourselves.
示例3: constrastLimit
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2YCrCb [as 別名]
def constrastLimit(image):
img_hist_equalized = cv2.cvtColor(image, cv2.COLOR_BGR2YCrCb)
channels = cv2.split(img_hist_equalized)
channels[0] = cv2.equalizeHist(channels[0])
img_hist_equalized = cv2.merge(channels)
img_hist_equalized = cv2.cvtColor(img_hist_equalized, cv2.COLOR_YCrCb2BGR)
return img_hist_equalized
示例4: color_moments
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2YCrCb [as 別名]
def color_moments(image, mask, color_space):
"""
function: Color Moment Features
image: raw image
mask: image mask
color_space: 'rgb' or 'lab' or 'ycrcb' or 'hsv'
"""
assert image.shape[:2] == mask.shape
assert color_space.lower() in ['lab', 'rgb', 'ycrcb', 'hsv']
if color_space.lower() == 'rgb':
image = cv.cvtColor(image, cv.COLOR_BGR2RGB)
elif color_space.lower() == 'hsv':
image = cv.cvtColor(image, cv.COLOR_BGR2HSV)
elif color_space.lower() == 'lab':
image = cv.cvtColor(image, cv.COLOR_BGR2LAB)
elif color_space.lower() == 'ycrcb':
image = cv.cvtColor(image, cv.COLOR_BGR2YCrCb)
else:
raise ValueError("Color space error...")
# Split image channels info
c1, c2, c3 = cv.split(image)
color_feature = []
# Only process mask != 0 channel region
c1 = c1[np.where(mask != 0)]
c2 = c2[np.where(mask != 0)]
c3 = c3[np.where(mask != 0)]
# Extract mean
mean_1 = np.mean(c1)
mean_2 = np.mean(c2)
mean_3 = np.mean(c3)
# Extract variance
variance_1 = np.std(c1)
variance_2 = np.std(c2)
variance_3 = np.std(c3)
# Extract skewness
skewness_1 = np.mean(np.abs(c1 - mean_1) ** 3) ** (1. / 3)
skewness_2 = np.mean(np.abs(c1 - mean_2) ** 3) ** (1. / 3)
skewness_3 = np.mean(np.abs(c1 - mean_3) ** 3) ** (1. / 3)
color_feature.extend(
[mean_1, mean_2, mean_3, variance_1, variance_2,
variance_3, skewness_1, skewness_2, skewness_3])
return color_feature
開發者ID:JACKYLUO1991,項目名稱:Face-skin-hair-segmentaiton-and-skin-color-evaluation,代碼行數:52,代碼來源:cal_moments.py