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


Python cv2.COLOR_RGB2HSV屬性代碼示例

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


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

示例1: _brightness

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_RGB2HSV [as 別名]
def _brightness(image, min=0.5, max=2.0):
    '''
    Randomly changes the brightness of the input image.

    Protected against overflow.
    '''
    hsv = cv2.cvtColor(image,cv2.COLOR_RGB2HSV)

    random_br = np.random.uniform(min,max)

    #To protect against overflow: Calculate a mask for all pixels
    #where adjustment of the brightness would exceed the maximum
    #brightness value and set the value to the maximum at those pixels.
    mask = hsv[:,:,2] * random_br > 255
    v_channel = np.where(mask, 255, hsv[:,:,2] * random_br)
    hsv[:,:,2] = v_channel

    return cv2.cvtColor(hsv,cv2.COLOR_HSV2RGB) 
開發者ID:pierluigiferrari,項目名稱:fcn8s_tensorflow,代碼行數:20,代碼來源:batch_generator.py

示例2: test_yellow_white_thresh_images

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_RGB2HSV [as 別名]
def test_yellow_white_thresh_images(src, dst, y_low=(10,50,0), y_high=(30,255,255), w_low=(180,180,180), w_high=(255,255,255)):
	"""
	apply the thresh to images in a src folder and output to dst foler
	"""
	image_files = glob.glob(src+"*.jpg")
	for idx, file in enumerate(image_files):
		print(file)
		img = mpimg.imread(file)
		image_threshed = yellow_white_thresh(img, y_low, y_high, w_low, w_high)
		
		file_name = file.split("\\")[-1]
		print(file_name)
		out_image = dst+file_name
		print(out_image)
		# convert  binary to RGB, *255, to visiual, 1 will not visual after write to file
		image_threshed = cv2.cvtColor(image_threshed*255, cv2.COLOR_GRAY2RGB)
		
		# HSV = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
		# V = HSV[:,:,2]
		# brightness = np.mean(V)
		# info_str = "brightness is: {}".format(int(brightness))
		# cv2.putText(image_threshed, info_str, (50,700), cv2.FONT_HERSHEY_SIMPLEX,2,(0,255,255),2)
		
		cv2.imwrite(out_image, image_threshed) 
開發者ID:ChengZhongShen,項目名稱:Advanced_Lane_Lines,代碼行數:26,代碼來源:image_process.py

示例3: __call__

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_RGB2HSV [as 別名]
def __call__(self, image, labels=None):
        if self.current == 'RGB' and self.to == 'HSV':
            image = cv2.cvtColor(image, cv2.COLOR_RGB2HSV)
        elif self.current == 'RGB' and self.to == 'GRAY':
            image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
            if self.keep_3ch:
                image = np.stack([image] * 3, axis=-1)
        elif self.current == 'HSV' and self.to == 'RGB':
            image = cv2.cvtColor(image, cv2.COLOR_HSV2RGB)
        elif self.current == 'HSV' and self.to == 'GRAY':
            image = cv2.cvtColor(image, cv2.COLOR_HSV2GRAY)
            if self.keep_3ch:
                image = np.stack([image] * 3, axis=-1)
        if labels is None:
            return image
        else:
            return image, labels 
開發者ID:pierluigiferrari,項目名稱:data_generator_object_detection_2d,代碼行數:19,代碼來源:object_detection_2d_photometric_ops.py

示例4: cv_preprocess_image

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_RGB2HSV [as 別名]
def cv_preprocess_image(img, output_height, output_width, is_training):
        assert output_height == output_width
        img = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
        img[:, :, 0] = np.uint8((np.int32(img[:, :, 0]) + (180 + random.randrange(-9, 10))) % 180)
        img = cv2.cvtColor(img, cv2.COLOR_HSV2RGB)
        rows, cols, ch = img.shape
        output_size = output_width

        def r():
            return (random.random() - 0.5) * 0.1 * output_size
        pts1 = np.float32([[0, 0], [cols, rows], [0, rows]])
        pts2 = np.float32([[r(), r()], [output_size + r(), output_size + r()], [r(), output_size + r()]])
        M = cv2.getAffineTransform(pts1, pts2)
        noize = np.random.normal(0, random.random() * (0.05 * 255), size=img.shape)
        img = np.array(img, dtype=np.float32) + noize
        img = cv2.warpAffine(img, M, (output_size, output_size), flags=cv2.INTER_LINEAR, borderMode=cv2.BORDER_REFLECT_101)
        return img 
開發者ID:yuantailing,項目名稱:ctw-baseline,代碼行數:19,代碼來源:chineselib.py

示例5: preprocess

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_RGB2HSV [as 別名]
def preprocess(self, data):
        # random hue and saturation
        data = cv2.cvtColor(data, cv2.COLOR_RGB2HSV);
        delta = (np.random.random() * 2 - 1) * 0.2
        data[:, :, 0] = np.mod(data[:,:,0] + (delta * 360 + 360.), 360.)

        delta_sature = np.random.random() + 0.5
        data[:, :, 1] *= delta_sature
        data[:,:, 1] = np.maximum( np.minimum(data[:,:,1], 1), 0 )
        data = cv2.cvtColor(data, cv2.COLOR_HSV2RGB)

        # adjust brightness
        delta = (np.random.random() * 2 - 1) * 0.3
        data += delta

        # adjust contrast
        mean = data.mean(axis=2, keepdims=True)
        data = (data - mean) * (np.random.random() + 0.5) + mean
        data = np.minimum(np.maximum(data, 0), 1)
        return data 
開發者ID:princeton-vl,項目名稱:pytorch_stacked_hourglass,代碼行數:22,代碼來源:dp.py

示例6: pre_processing

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_RGB2HSV [as 別名]
def pre_processing(img):
    # Random exposure and saturation (0.9 ~ 1.1 scale)
    rand_s = random.uniform(0.9, 1.1)
    rand_v = random.uniform(0.9, 1.1)

    img = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)

    tmp = np.ones_like(img[:, :, 1]) * 255
    img[:, :, 1] = np.where(img[:, :, 1] * rand_s > 255, tmp, img[:, :, 1] * rand_s)
    img[:, :, 2] = np.where(img[:, :, 2] * rand_v > 255, tmp, img[:, :, 2] * rand_v)

    img = cv2.cvtColor(img, cv2.COLOR_HSV2RGB)

    # Centering helps normalization image (-1 ~ 1 value)
    return img / 127.5 - 1


# Get ImageDataGenerator arguments(options) depends on mode - (train, val, test) 
開發者ID:dhkim0225,項目名稱:keras-image-segmentation,代碼行數:20,代碼來源:generator.py

示例7: __call__

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_RGB2HSV [as 別名]
def __call__(self, img, labelmap=None, maskmap=None):
        assert isinstance(img, Image.Image)
        assert labelmap is None or isinstance(labelmap, Image.Image)
        assert maskmap is None or isinstance(maskmap, Image.Image)

        if random.random() > self.ratio:
            return img, labelmap, maskmap

        img = np.array(img).astype(np.float32)
        img = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)

        img[:, :, 0] += random.uniform(-self.delta, self.delta)
        img[:, :, 0][img[:, :, 0] > 360] -= 360
        img[:, :, 0][img[:, :, 0] < 0] += 360
        img = cv2.cvtColor(img, cv2.COLOR_HSV2RGB)
        img = np.clip(img, 0, 255)
        return Image.fromarray(img.astype(np.uint8)), labelmap, maskmap 
開發者ID:openseg-group,項目名稱:openseg.pytorch,代碼行數:19,代碼來源:pil_aug_transforms.py

示例8: modify_illumination

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_RGB2HSV [as 別名]
def modify_illumination(images: list, ilrange: list, random_bright: float=None):
    """
    Convert images to HSV color space, modify Value channel according to random brightness value and convert back to
    RGB. If random_bright is None, the random brightness value is uniformly sampled from ilrange tuple, otherwise
    random_bright is directly used. This brightness value is multiplied to the original Value channel.
    :param images: list of images
    :param ilrange: illumination range (min, max) from which the brightness value is uniformly sampled if random_bright is None.
    :param random_bright: optional value specifying the brightness multiplier.
    :return: transformed images, random_bright value
    """
    if random_bright is None:
        random_bright = np.random.uniform(ilrange[0], ilrange[1])
    new_images = []
    for image in images:
        image1 = cv.cvtColor(image, cv.COLOR_RGB2HSV)
        image1[:, :, 2] = image1[:, :, 2] * random_bright
        image1[:, :, 2] = np.clip(image1[:, :, 2], 0., 255.)
        image1 = cv.cvtColor(image1, cv.COLOR_HSV2RGB)
        new_images.append(image1)
    return new_images, random_bright 
開發者ID:crisie,項目名稱:RecurrentGaze,代碼行數:22,代碼來源:images_data_augmenter_seqaware.py

示例9: random_distort_image

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_RGB2HSV [as 別名]
def random_distort_image(image, hue=18, saturation=1.5, exposure=1.5):
    # determine scale factors
    dhue = np.random.uniform(-hue, hue)
    dsat = _rand_scale(saturation)
    dexp = _rand_scale(exposure)

    # convert RGB space to HSV space
    image = cv2.cvtColor(image, cv2.COLOR_RGB2HSV).astype('float')
    
    # change satuation and exposure
    image[:, :, 1] *= dsat
    image[:, :, 2] *= dexp
    
    # change hue
    image[:, :, 0] += dhue
    image[:, :, 0] -= (image[:, :, 0] > 180) * 180
    image[:, :, 0] += (image[:, :, 0] < 0)   * 180
    
    # convert back to RGB from HSV
    return cv2.cvtColor(image.astype('uint8'), cv2.COLOR_HSV2RGB) 
開發者ID:OlafenwaMoses,項目名稱:ImageAI,代碼行數:22,代碼來源:image.py

示例10: preprocess

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_RGB2HSV [as 別名]
def preprocess(self, data):
        # random hue and saturation
        data = cv2.cvtColor(data, cv2.COLOR_RGB2HSV);
        delta = (np.random.random() * 2 - 1) * 0.2
        data[:, :, 0] = np.mod(data[:,:,0] + (delta * 360 + 360.), 360.)

        delta_sature = np.random.random() + 0.5
        data[:, :, 1] *= delta_sature
        data[:,:, 1] = np.maximum( np.minimum(data[:,:,1], 1), 0 )
        data = cv2.cvtColor(data, cv2.COLOR_HSV2RGB)

        # adjust brightness
        delta = (np.random.random() * 2 - 1) * 0.3
        data += delta

        # adjust contrast
        mean = data.mean(axis=2, keepdims=True)
        data = (data - mean) * (np.random.random() + 0.5) + mean
        data = np.minimum(np.maximum(data, 0), 1)
        #cv2.imwrite('x.jpg', (data*255).astype(np.uint8))
        return data 
開發者ID:princeton-vl,項目名稱:pose-ae-train,代碼行數:23,代碼來源:dp.py

示例11: _add_hue_saturation

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_RGB2HSV [as 別名]
def _add_hue_saturation(cls, img, value=None, value_hue=None,
                            value_saturation=None):
        if value is not None:
            assert value_hue is None and value_saturation is None
        else:
            assert value_hue is not None or value_saturation is not None

        if value is not None:
            value_hue = value
            value_saturation = value
        else:
            value_hue = value_hue or 0
            value_saturation = value_saturation or 0

        img_hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
        img_hsv = img_hsv.astype(np.int32)
        img_hsv[..., 0] = np.mod(
            img_hsv[..., 0] + int((value_hue/255.0) * (360/2)), 180)
        img_hsv[..., 1] = np.clip(
            img_hsv[..., 1] + value_saturation, 0, 255)
        img_hsv = img_hsv.astype(np.uint8)
        return cv2.cvtColor(img_hsv, cv2.COLOR_HSV2RGB) 
開發者ID:aleju,項目名稱:imgaug,代碼行數:24,代碼來源:test_color.py

示例12: __call__

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_RGB2HSV [as 別名]
def __call__(self, img):
        assert img.ndim == 3 and img.shape[2] == 3

        if self.random.random_sample() >= self.prob:
            return img

        var = self.random.uniform(-self.var, self.var)

        to_HSV, from_HSV = [(cv2.COLOR_RGB2HSV, cv2.COLOR_HSV2RGB),
                            (cv2.COLOR_BGR2HSV, cv2.COLOR_HSV2BGR)][self.random.randint(2)]

        hsv = cv2.cvtColor(img, to_HSV).astype(np.float32)

        hue = hsv[:, :, 0] / 179. + var
        hue = hue - np.floor(hue)
        hsv[:, :, 0] = hue * 179.

        img = cv2.cvtColor(hsv.astype('uint8'), from_HSV)
        return img 
開發者ID:uoip,項目名稱:SSD-variants,代碼行數:21,代碼來源:transforms.py

示例13: color_hist

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_RGB2HSV [as 別名]
def color_hist(img, nbins=32, bins_range=(0, 256)):
    # Convert from RGB to HSV using cv2.cvtColor()
    hsv_img = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
    # Compute the histogram of the HSV channels separately
    h_hist = np.histogram(hsv_img[:,:,0], bins=nbins, range=bins_range)
    s_hist = np.histogram(hsv_img[:,:,1], bins=nbins, range=bins_range)
    v_hist = np.histogram(hsv_img[:,:,2], bins=nbins, range=bins_range)
    # Concatenate the histograms into a single feature vector
    hist_features = np.concatenate((h_hist[0], s_hist[0], v_hist[0])).astype(np.float64)
    # Normalize the result
    norm_features = hist_features / np.sum(hist_features)
    # Return the feature vector
    return norm_features

# Define a function to extract features from a list of images
# Have this function call color_hist() 
開發者ID:mkhuthir,項目名稱:RoboND-Perception-Intro,代碼行數:18,代碼來源:car_nocar.py

示例14: color_hist

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_RGB2HSV [as 別名]
def color_hist(img, nbins=32, bins_range=(0, 256)):
    
    # Convert from RGB to HSV using cv2.cvtColor()
    hsv_img = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
    
    # Compute the histogram of the HSV channels separately
    h_hist = np.histogram(hsv_img[:,:,0], bins=nbins, range=bins_range)
    s_hist = np.histogram(hsv_img[:,:,1], bins=nbins, range=bins_range)
    v_hist = np.histogram(hsv_img[:,:,2], bins=nbins, range=bins_range)
    
    # Concatenate the histograms into a single feature vector
    hist_features = np.concatenate((h_hist[0], s_hist[0], v_hist[0])).astype(np.float64)
    
    # Normalize the result
    norm_features = hist_features / np.sum(hist_features)
    
    # Return the feature vector
    return norm_features 
開發者ID:mkhuthir,項目名稱:RoboND-Perception-Intro,代碼行數:20,代碼來源:color_histogram.py

示例15: _l1_quantile

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_RGB2HSV [as 別名]
def _l1_quantile(batch, quantile=50, size=32):
    """Compute differences between subsequent frames in a batch.
    """
    bsize = batch.bsize
    msize = bsize + 1
    assert msize <= batch.get_frames().shape[0]

    simg = zeros((msize, size, size, 3))
    for iran in range(msize):
        fsmall = resize(batch.get_frames()[iran, :, :, :], (size, size))
        fsmall_hsv = cvtColor(fsmall, COLOR_RGB2HSV)
        simg[iran, :, :, :] = fsmall_hsv

    norm = simg[slice(0, bsize), :, :, :] - simg[slice(1, bsize + 1), :, :, :]

    return percentile(npabs(norm), q=quantile, axis=(1, 2, 3)) 
開發者ID:distant-viewing,項目名稱:dvt,代碼行數:18,代碼來源:diff.py


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