本文整理匯總了Python中cv2.COLOR_YCR_CB2BGR屬性的典型用法代碼示例。如果您正苦於以下問題:Python cv2.COLOR_YCR_CB2BGR屬性的具體用法?Python cv2.COLOR_YCR_CB2BGR怎麽用?Python cv2.COLOR_YCR_CB2BGR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類cv2
的用法示例。
在下文中一共展示了cv2.COLOR_YCR_CB2BGR屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: convert_to_original_colors
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_YCR_CB2BGR [as 別名]
def convert_to_original_colors(content_img, stylized_img):
content_img = postprocess(content_img)
stylized_img = postprocess(stylized_img)
if args.color_convert_type == 'yuv':
cvt_type = cv2.COLOR_BGR2YUV
inv_cvt_type = cv2.COLOR_YUV2BGR
elif args.color_convert_type == 'ycrcb':
cvt_type = cv2.COLOR_BGR2YCR_CB
inv_cvt_type = cv2.COLOR_YCR_CB2BGR
elif args.color_convert_type == 'luv':
cvt_type = cv2.COLOR_BGR2LUV
inv_cvt_type = cv2.COLOR_LUV2BGR
elif args.color_convert_type == 'lab':
cvt_type = cv2.COLOR_BGR2LAB
inv_cvt_type = cv2.COLOR_LAB2BGR
content_cvt = cv2.cvtColor(content_img, cvt_type)
stylized_cvt = cv2.cvtColor(stylized_img, cvt_type)
c1, _, _ = cv2.split(stylized_cvt)
_, c2, c3 = cv2.split(content_cvt)
merged = cv2.merge((c1, c2, c3))
dst = cv2.cvtColor(merged, inv_cvt_type).astype(np.float32)
dst = preprocess(dst)
return dst
示例2: hist
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_YCR_CB2BGR [as 別名]
def hist(img):
ycrcb = cv2.cvtColor(img, cv2.COLOR_BGR2YCR_CB)
channels = cv2.split(ycrcb)
cv2.equalizeHist(channels[0], channels[0]) #輸入通道、輸出通道矩陣
cv2.merge(channels, ycrcb) #合並結果通道
cv2.cvtColor(ycrcb, cv2.COLOR_YCR_CB2BGR, img)
return img
示例3: color_draw
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_YCR_CB2BGR [as 別名]
def color_draw(path="img/sjtu.jpg", gammaS=1, gammaI=1):
im = Image.open(path)
if im.mode == 'RGB':
ycbcr = im.convert('YCbCr')
Iruv = np.ndarray((im.size[1], im.size[0], 3), 'u1', ycbcr.tobytes())
type = "colour"
else:
Iruv = np.array(im)
type = "black"
S = get_s(Iruv[:, :, 0], gammaS=gammaS)
T = get_t(Iruv[:, :, 0], type, gammaI=gammaI)
Ypencil = S * T
new_Iruv = Iruv.copy()
new_Iruv.flags.writeable = True
new_Iruv[:, :, 0] = Ypencil * 255
R = cv2.cvtColor(new_Iruv, cv2.COLOR_YCR_CB2BGR)
img = Image.fromarray(R)
# img.show()
name = path.rsplit("/")[-1].split(".")[0]
suffix = path.rsplit("/")[-1].split(".")[1]
save_output(Image.fromarray(S * 255), name + "_s", suffix)
save_output(Image.fromarray(T * 255), name + "_t", suffix)
save_output(img, name + "_color", suffix)
示例4: create_mask
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_YCR_CB2BGR [as 別名]
def create_mask(self, img, color):
img = cv2.cvtColor(img, cv2.COLOR_BGR2Lab)
if color == 'green':
threshold = [(20, 0, 128), (235, 128, 255)]
elif color == 'white':
threshold = [(100, 110, 110), (200, 140, 140)]
else:
raise Exception('Color undefined')
mask = cv2.inRange(img, threshold[0], threshold[1])
# kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (7,7))
# mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel)
# mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)
mask = mask > 0
# img = cv2.cvtColor(img, cv2.COLOR_YCR_CB2BGR)
# thres_img = np.zeros_like(img, np.uint8)
# thres_img[mask] = img[mask]
binary_img = np.zeros((img.shape[0],img.shape[1]), np.uint8)
binary_img[mask] = 255
# cv2.imshow('img', binary_img)
# cv2.waitKey(0)
# exit(0)
return mask
示例5: houghCircles
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_YCR_CB2BGR [as 別名]
def houghCircles(path, counter):
img = cv2.imread(path, 0)
# img = cv2.medianBlur(img, 5)
x = cv2.Sobel(img, -1, 1, 0, ksize=3)
y = cv2.Sobel(img, -1, 0, 1, ksize=3)
absx = cv2.convertScaleAbs(x)
absy = cv2.convertScaleAbs(y)
img = cv2.addWeighted(absx, 0.5, absy, 0.5, 0)
# ycrcb = cv2.cvtColor(img, cv2.COLOR_BGR2YCR_CB)
# channels = cv2.split(ycrcb)
# cv2.equalizeHist(channels[0], channels[0]) #輸入通道、輸出通道矩陣
# cv2.merge(channels, ycrcb) #合並結果通道
# cv2.cvtColor(ycrcb, cv2.COLOR_YCR_CB2BGR, img)
# img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cimg = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
# cv2.imshow("img2", img)
# cv2.imshow("grayimg", grayimg)
circles = cv2.HoughCircles(
img,
cv2.HOUGH_GRADIENT,
1,
50,
param1=50,
param2=10,
minRadius=2,
maxRadius=0)
circles = np.uint16(np.around(circles))
for i in circles[0, :]:
# draw the outer circle
# cv2.circle(cimg, (i[0], i[1]), i[2], (0, 255, 0), 1)
# draw the center of the circle
cv2.circle(cimg, (i[0], i[1]), 2, (0, 0, 255), 2)
# cv2.imshow("img" + str(counter), cimg)
return (i[0] + 3, i[1] + 3)
#彩色直方圖均衡化