當前位置: 首頁>>代碼示例>>Python>>正文


Python cv2.COLOR_BGR2YUV屬性代碼示例

本文整理匯總了Python中cv2.COLOR_BGR2YUV屬性的典型用法代碼示例。如果您正苦於以下問題:Python cv2.COLOR_BGR2YUV屬性的具體用法?Python cv2.COLOR_BGR2YUV怎麽用?Python cv2.COLOR_BGR2YUV使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在cv2的用法示例。


在下文中一共展示了cv2.COLOR_BGR2YUV屬性的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: convert_to_original_colors

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2YUV [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 
開發者ID:cysmith,項目名稱:neural-style-tf,代碼行數:25,代碼來源:neural_style.py

示例2: pre_process_image

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2YUV [as 別名]
def pre_process_image(image):
    #image = cv2.cvtColor(image, cv2.COLOR_BGR2YUV)
    #print(image)
	
    image[:,:,0] = cv2.equalizeHist(image[:,:,0])
    image[:,:,1] = cv2.equalizeHist(image[:,:,1])
    image[:,:,2] = cv2.equalizeHist(image[:,:,2])
    image = image/255. - 0.5
    return image 
開發者ID:evtimovi,項目名稱:robust_physical_perturbations,代碼行數:11,代碼來源:calc_accuracy_yadav.py

示例3: pre_process_image

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2YUV [as 別名]
def pre_process_image(image):
    #image = cv2.cvtColor(image, cv2.COLOR_BGR2YUV)
    #print(image)
	
    #image[:,:,0] = cv2.equalizeHist(image[:,:,0])
    #image[:,:,1] = cv2.equalizeHist(image[:,:,1])
    #image[:,:,2] = cv2.equalizeHist(image[:,:,2])
    image = image/255.-0.5
    return image 
開發者ID:evtimovi,項目名稱:robust_physical_perturbations,代碼行數:11,代碼來源:train_yadav.py

示例4: transform_image

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2YUV [as 別名]
def transform_image(image,ang_range,shear_range,trans_range):

    # Rotation

    ang_rot = np.random.uniform(ang_range)-ang_range/2
    rows,cols,ch = image.shape    
    Rot_M = cv2.getRotationMatrix2D((cols/2,rows/2),ang_rot,1)

    # Translation
    tr_x = trans_range*np.random.uniform()-trans_range/2
    tr_y = trans_range*np.random.uniform()-trans_range/2
    Trans_M = np.float32([[1,0,tr_x],[0,1,tr_y]])

    # Shear
    pts1 = np.float32([[5,5],[20,5],[5,20]])

    pt1 = 5+shear_range*np.random.uniform()-shear_range/2
    pt2 = 20+shear_range*np.random.uniform()-shear_range/2

    pts2 = np.float32([[pt1,5],[pt2,pt1],[5,pt2]])

    shear_M = cv2.getAffineTransform(pts1,pts2)

    image = cv2.warpAffine(image,Rot_M,(cols,rows))
    image = cv2.warpAffine(image,Trans_M,(cols,rows))
    image = cv2.warpAffine(image,shear_M,(cols,rows))

    image = pre_process_image(image.astype(np.uint8))

    #image = cv2.cvtColor(image, cv2.COLOR_BGR2YUV)
    #image = image[:,:,0]
    #image = cv2.resize(image, (img_resize,img_resize),interpolation = cv2.INTER_CUBIC)

    return image 
開發者ID:evtimovi,項目名稱:robust_physical_perturbations,代碼行數:36,代碼來源:train_yadav.py

示例5: read_an_image

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2YUV [as 別名]
def read_an_image(filename):
    img = cv2.imread(filename)
    img = cv2.resize(img[-150:], (200, 66))
    # BGR space to YUV space
    img = cv2.cvtColor(img,cv2.COLOR_BGR2YUV)
    return img 
開發者ID:Kejie-Wang,項目名稱:End-to-End-Learning-for-Self-Driving-Cars,代碼行數:8,代碼來源:split_data.py

示例6: __call__

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2YUV [as 別名]
def __call__(self, im):
        img_yuv = cv2.cvtColor(im, cv2.COLOR_BGR2YUV)
        clahe = cv2.createCLAHE(clipLimit=self.clipLimit, tileGridSize=self.tileGridSize)
        img_yuv[:, :, 0] = clahe.apply(img_yuv[:, :, 0])
        img_output = cv2.cvtColor(img_yuv, cv2.COLOR_YUV2BGR)
        return img_output 
開發者ID:asanakoy,項目名稱:kaggle_carvana_segmentation,代碼行數:8,代碼來源:transforms.py

示例7: histogram_equalization2

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2YUV [as 別名]
def histogram_equalization2(img: np.ndarray):
        if len(np.shape(img)) == 3:
            img_yuv = cv2.cvtColor(img, cv2.COLOR_BGR2YUV)
            # equalize the histogram of the Y channel
            img_yuv[:, :, 0] = cv2.equalizeHist(img_yuv[:, :, 0])
            # convert the YUV image back to RGB format
            img = cv2.cvtColor(img_yuv, cv2.COLOR_YUV2BGR)
        return img 
開發者ID:haruiz,項目名稱:CvStudio,代碼行數:10,代碼來源:img_util.py

示例8: equalize_clahe_color_yuv

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2YUV [as 別名]
def equalize_clahe_color_yuv(img):
    """Equalize the image splitting it after conversion to YUV and applying CLAHE
    to the Y channel and merging the channels and convert back to BGR
    """

    cla = cv2.createCLAHE(clipLimit=4.0)
    Y, U, V = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2YUV))
    eq_Y = cla.apply(Y)
    eq_image = cv2.cvtColor(cv2.merge([eq_Y, U, V]), cv2.COLOR_YUV2BGR)
    return eq_image 
開發者ID:PacktPublishing,項目名稱:Mastering-OpenCV-4-with-Python,代碼行數:12,代碼來源:clahe_histogram_equalization.py

示例9: frame_pre_processing

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2YUV [as 別名]
def frame_pre_processing(img):
    img_yuv = cv2.cvtColor(img, cv2.COLOR_BGR2YUV)
    img_yuv[:, :, 0] = cv2.equalizeHist(img_yuv[:, :, 0])
    img_output = cv2.cvtColor(img_yuv, cv2.COLOR_YUV2RGB)
    return img_output 
開發者ID:seongahjo,項目名稱:Mosaicer,代碼行數:7,代碼來源:mosaicer.py

示例10: computeForwardPasses

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2YUV [as 別名]
def computeForwardPasses(nets, alexnet, im, transformer, transformer_alex, resize_net):
	"""
	Compute the forward passes for CALC and optionallly alexnet
	"""

	img_yuv = cv2.cvtColor(im, cv2.COLOR_BGR2YUV)
	img_yuv[:,:,0] = cv2.equalizeHist(img_yuv[:,:,0])
	im = cv2.cvtColor(img_yuv, cv2.COLOR_YUV2BGR)
	alex_conv3 = None
	t_alex = -1

	imcp = np.copy(im) # for AlexNet
	
	if im.shape[2] > 1:
		im = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
	if not resize_net:
		im = cv2.resize(im, (160, 120), interpolation = cv2.INTER_CUBIC)
	else:
		transformer = caffe.io.Transformer({'X1':(1,1,im.shape[0],im.shape[1])})	
		transformer.set_raw_scale('X1',1./255)
		for net in nets:
			x1 = net.blobs['X1']
			x1.reshape(1,1,im.shape[0],im.shape[1])
			net.reshape()
	descr = []
	t_calc = []
	for net in nets:
		t0 = time()
		net.blobs['X1'].data[...] = transformer.preprocess('X1', im)
		net.forward()
		d = np.copy(net.blobs['descriptor'].data[...])
		t_calc.append(time() - t0)
		d /= np.linalg.norm(d)
		descr.append(d)

	if alexnet is not None:
		im2 = cv2.resize(imcp, (227,227), interpolation=cv2.INTER_CUBIC)
		t0 =  time()
		alexnet.blobs['data'].data[...] = transformer_alex.preprocess('data', im2)
		alexnet.forward()
		alex_conv3 = np.copy(alexnet.blobs['conv3'].data[...])
		alex_conv3 = np.reshape(alex_conv3, (alex_conv3.size, 1))
		global first_it
		global A
		if first_it:
			np.random.seed(0)
			A = np.random.randn(descr[0].size, alex_conv3.size) # For Gaussian random projection
			first_it = False
		alex_conv3 = np.matmul(A, alex_conv3)
		alex_conv3 = np.reshape(alex_conv3, (1, alex_conv3.size))
		t_alex = time() - t0
		alex_conv3 /= np.linalg.norm(alex_conv3)

	return descr, alex_conv3, t_calc, t_alex 
開發者ID:rpng,項目名稱:calc,代碼行數:56,代碼來源:testNet.py

示例11: read_ori_img

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2YUV [as 別名]
def read_ori_img(self,filename):
        #傻逼opencv因為數組類型不會變,輸入是uint8輸出也是uint8,而UV可以是負數且uint8會去掉小數部分
        ori_img = cv2.imread(filename).astype(np.float32)
        self.ori_img_shape = ori_img.shape[:2]
        if self.color_mod == 'RGB':
            self.ori_img_YUV = ori_img
        elif self.color_mod == 'YUV':
            self.ori_img_YUV = cv2.cvtColor(ori_img, cv2.COLOR_BGR2YUV)

        if not self.ori_img_YUV.shape[0]%(2**self.dwt_deep)==0:
            temp = (2**self.dwt_deep)-self.ori_img_YUV.shape[0]%(2**self.dwt_deep)
            self.ori_img_YUV = np.concatenate((self.ori_img_YUV,np.zeros((temp,self.ori_img_YUV.shape[1],3))),axis=0)
        if not self.ori_img_YUV.shape[1]%(2**self.dwt_deep)==0:
            temp = (2**self.dwt_deep)-self.ori_img_YUV.shape[1]%(2**self.dwt_deep)
            self.ori_img_YUV = np.concatenate((self.ori_img_YUV,np.zeros((self.ori_img_YUV.shape[0],temp,3))),axis=1)
        assert self.ori_img_YUV.shape[0]%(2**self.dwt_deep)==0
        assert self.ori_img_YUV.shape[1]%(2**self.dwt_deep)==0

        if self.dwt_deep==1:
            coeffs_Y = dwt2(self.ori_img_YUV[:,:,0],'haar')
            ha_Y = coeffs_Y[0]
            coeffs_U = dwt2(self.ori_img_YUV[:,:,1],'haar')
            ha_U = coeffs_U[0]
            coeffs_V = dwt2(self.ori_img_YUV[:,:,2],'haar')
            ha_V = coeffs_V[0]
            self.coeffs_Y = [coeffs_Y[1]]
            self.coeffs_U = [coeffs_U[1]]
            self.coeffs_V = [coeffs_V[1]]

        elif self.dwt_deep>=2:
            #不希望使用太多級的dwt,2,3次就行了
            coeffs_Y = dwt2(self.ori_img_YUV[:,:,0],'haar')
            ha_Y = coeffs_Y[0]
            coeffs_U = dwt2(self.ori_img_YUV[:,:,1],'haar')
            ha_U = coeffs_U[0]
            coeffs_V = dwt2(self.ori_img_YUV[:,:,2],'haar')
            ha_V = coeffs_V[0]
            self.coeffs_Y = [coeffs_Y[1]]
            self.coeffs_U = [coeffs_U[1]]
            self.coeffs_V = [coeffs_V[1]]
            for i in range(self.dwt_deep-1):
                coeffs_Y = dwt2(ha_Y,'haar')
                ha_Y = coeffs_Y[0]
                coeffs_U = dwt2(ha_U,'haar')
                ha_U = coeffs_U[0]
                coeffs_V = dwt2(ha_V,'haar')
                ha_V = coeffs_V[0]
                self.coeffs_Y.append(coeffs_Y[1])
                self.coeffs_U.append(coeffs_U[1])
                self.coeffs_V.append(coeffs_V[1])
        self.ha_Y = ha_Y
        self.ha_U = ha_U
        self.ha_V = ha_V

        self.ha_block_shape = (int(self.ha_Y.shape[0]/self.block_shape[0]),int(self.ha_Y.shape[1]/self.block_shape[1]),self.block_shape[0],self.block_shape[1])
        strides = self.ha_Y.itemsize*(np.array([self.ha_Y.shape[1]*self.block_shape[0],self.block_shape[1],self.ha_Y.shape[1],1]))
        
        self.ha_Y_block = np.lib.stride_tricks.as_strided(self.ha_Y.copy(),self.ha_block_shape,strides)
        self.ha_U_block = np.lib.stride_tricks.as_strided(self.ha_U.copy(),self.ha_block_shape,strides)
        self.ha_V_block = np.lib.stride_tricks.as_strided(self.ha_V.copy(),self.ha_block_shape,strides) 
開發者ID:fire-keeper,項目名稱:BlindWatermark,代碼行數:62,代碼來源:BlindWatermark copy.py


注:本文中的cv2.COLOR_BGR2YUV屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。