当前位置: 首页>>代码示例>>Python>>正文


Python cv2.COLOR_BGR2HSV属性代码示例

本文整理汇总了Python中cv2.COLOR_BGR2HSV属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.COLOR_BGR2HSV属性的具体用法?Python cv2.COLOR_BGR2HSV怎么用?Python cv2.COLOR_BGR2HSV使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在cv2的用法示例。


在下文中一共展示了cv2.COLOR_BGR2HSV属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: standard_test

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2HSV [as 别名]
def standard_test(self):
        for fnum in range(self.start_fnum, self.stop_fnum):
            frame = util.get_frame(self.capture, fnum)
            frame = frame[280:, :]
            frame_HSV = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

            mask = cv2.inRange(frame_HSV, (self.low_H, self.low_S, self.low_V),
                (self.high_H, self.high_S, self.high_V))

            res = cv2.bitwise_and(frame, frame, mask=mask)
            res_inv = cv2.bitwise_and(frame, frame, mask=cv2.bitwise_not(mask))

            cv2.imshow(self.window_name, mask)
            cv2.imshow('Video Capture AND', res)
            cv2.imshow('Video Capture INV', res_inv)

            if cv2.waitKey(30) & 0xFF == ord('q'):
                break


    # A number of methods corresponding to the various trackbars available. 
开发者ID:jpnaterer,项目名称:smashscan,代码行数:23,代码来源:thresholding.py

示例2: remove_other_color

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2HSV [as 别名]
def remove_other_color(img):
    frame = cv2.GaussianBlur(img, (3,3), 0) 
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
    # define range of blue color in HSV
    lower_blue = np.array([100,128,0])
    upper_blue = np.array([215,255,255])
    # Threshold the HSV image to get only blue colors
    mask_blue = cv2.inRange(hsv, lower_blue, upper_blue)

    lower_white = np.array([0,0,128], dtype=np.uint8)
    upper_white = np.array([255,255,255], dtype=np.uint8)
    # Threshold the HSV image to get only blue colors
    mask_white = cv2.inRange(hsv, lower_white, upper_white)

    lower_black = np.array([0,0,0], dtype=np.uint8)
    upper_black = np.array([170,150,50], dtype=np.uint8)

    mask_black = cv2.inRange(hsv, lower_black, upper_black)

    mask_1 = cv2.bitwise_or(mask_blue, mask_white)
    mask = cv2.bitwise_or(mask_1, mask_black)
    # Bitwise-AND mask and original image
    #res = cv2.bitwise_and(frame,frame, mask= mask)
    return mask 
开发者ID:hoanglehaithanh,项目名称:Traffic-Sign-Detection,代码行数:26,代码来源:main.py

示例3: augment_hsv

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2HSV [as 别名]
def augment_hsv(img, hgain=0.5, sgain=0.5, vgain=0.5):
    x = (np.random.uniform(-1, 1, 3) * np.array([hgain, sgain, vgain]) + 1).astype(np.float32)  # random gains
    img_hsv = (cv2.cvtColor(img, cv2.COLOR_BGR2HSV) * x.reshape((1, 1, 3))).clip(None, 255).astype(np.uint8)
    cv2.cvtColor(img_hsv, cv2.COLOR_HSV2BGR, dst=img)  # no return needed


# def augment_hsv(img, hgain=0.5, sgain=0.5, vgain=0.5):  # original version
#     # SV augmentation by 50%
#     img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)  # hue, sat, val
#
#     S = img_hsv[:, :, 1].astype(np.float32)  # saturation
#     V = img_hsv[:, :, 2].astype(np.float32)  # value
#
#     a = random.uniform(-1, 1) * sgain + 1
#     b = random.uniform(-1, 1) * vgain + 1
#     S *= a
#     V *= b
#
#     img_hsv[:, :, 1] = S if a < 1 else S.clip(None, 255)
#     img_hsv[:, :, 2] = V if b < 1 else V.clip(None, 255)
#     cv2.cvtColor(img_hsv, cv2.COLOR_HSV2BGR, dst=img)  # no return needed 
开发者ID:zbyuan,项目名称:pruning_yolov3,代码行数:23,代码来源:datasets.py

示例4: _update_mean_shift_bookkeeping

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2HSV [as 别名]
def _update_mean_shift_bookkeeping(self, frame, box_grouped):
        """Preprocess all valid bounding boxes for mean-shift tracking

            This method preprocesses all relevant bounding boxes (those that
            have been detected by both mean-shift tracking and saliency) for
            the next mean-shift step.

            :param frame: current RGB input frame
            :param box_grouped: list of bounding boxes
        """
        hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

        self.object_roi = []
        self.object_box = []
        for box in box_grouped:
            (x, y, w, h) = box
            hsv_roi = hsv[y:y + h, x:x + w]
            mask = cv2.inRange(hsv_roi, np.array((0., 60., 32.)),
                               np.array((180., 255., 255.)))
            roi_hist = cv2.calcHist([hsv_roi], [0], mask, [180], [0, 180])
            cv2.normalize(roi_hist, roi_hist, 0, 255, cv2.NORM_MINMAX)

            self.object_roi.append(roi_hist)
            self.object_box.append(box) 
开发者ID:PacktPublishing,项目名称:OpenCV-Computer-Vision-Projects-with-Python,代码行数:26,代码来源:tracking.py

示例5: calculate_roi_hist

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2HSV [as 别名]
def calculate_roi_hist(self, frame):
    """Calculates region of interest histogram.

    Args:
      frame: The np.array image frame to calculate ROI histogram for.
    """
    (x, y, w, h) = self.box
    roi = frame[y:y + h, x:x + w]

    hsv_roi = cv2.cvtColor(roi, cv2.COLOR_BGR2HSV)
    mask = cv2.inRange(hsv_roi, np.array((0., 60., 32.)),
                       np.array((180., 255., 255.)))
    roi_hist = cv2.calcHist([hsv_roi], [0, 1], mask, [180, 255],
                            [0, 180, 0, 255])
    cv2.normalize(roi_hist, roi_hist, 0, 255, cv2.NORM_MINMAX)
    self.roi_hist = roi_hist

  # Run this every frame 
开发者ID:google,项目名称:automl-video-ondevice,代码行数:20,代码来源:camshift_object_tracker.py

示例6: run

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2HSV [as 别名]
def run(self, frame):
    """Processes a single frame.

    Args:
      frame: The np.array image frame.
    """
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
    dst = cv2.calcBackProject([hsv], [0, 1], self.roi_hist, [0, 180, 0, 255], 1)
    _, self.box = cv2.CamShift(dst, self.box, self.term_crit)

    (x, y, x2, y2) = self.glob_to_relative(
        (self.box[0], self.box[1], self.box[0] + self.box[2],
         self.box[1] + self.box[3]))

    self.annotation.bbox.left = x
    self.annotation.bbox.top = y
    self.annotation.bbox.right = x2
    self.annotation.bbox.bottom = y2

    self.age = self.age + 1
    self.degrade() 
开发者ID:google,项目名称:automl-video-ondevice,代码行数:23,代码来源:camshift_object_tracker.py

示例7: __call__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2HSV [as 别名]
def __call__(self, img, labelmap=None, maskmap=None):
        assert isinstance(img, np.ndarray)
        assert labelmap is None or isinstance(labelmap, np.ndarray)
        assert maskmap is None or isinstance(maskmap, np.ndarray)

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

        img = img.astype(np.float32)
        img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
        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_HSV2BGR)
        img = np.clip(img, 0, 255).astype(np.uint8)
        return img, labelmap, maskmap 
开发者ID:openseg-group,项目名称:openseg.pytorch,代码行数:18,代码来源:cv2_aug_transforms.py

示例8: __call__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2HSV [as 别名]
def __call__(self, image):


        if self.contrast_range is not None:
            contrast_factor = _uniform(self.contrast_range)
            image = adjust_contrast(image,contrast_factor)
        if self.brightness_range is not None:
            brightness_delta = _uniform(self.brightness_range)
            image = adjust_brightness(image, brightness_delta)

        if self.hue_range is not None or self.saturation_range is not None:

            image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)

            if self.hue_range is not None:
                hue_delta = _uniform(self.hue_range)
                image = adjust_hue(image, hue_delta)

            if self.saturation_range is not None:
                saturation_factor = _uniform(self.saturation_range)
                image = adjust_saturation(image, saturation_factor)

            image = cv2.cvtColor(image, cv2.COLOR_HSV2BGR)

        return image 
开发者ID:610265158,项目名称:face_landmark,代码行数:27,代码来源:visual_augmentation.py

示例9: __call__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2HSV [as 别名]
def __call__(self, image):
        """ Apply a visual effect on the image.

        Args
            image: Image to adjust
        """

        if self.contrast_factor:
            image = adjust_contrast(image, self.contrast_factor)
        if self.brightness_delta:
            image = adjust_brightness(image, self.brightness_delta)

        if self.hue_delta or self.saturation_factor:

            image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)

            if self.hue_delta:
                image = adjust_hue(image, self.hue_delta)
            if self.saturation_factor:
                image = adjust_saturation(image, self.saturation_factor)

            image = cv2.cvtColor(image, cv2.COLOR_HSV2BGR)

        return image 
开发者ID:weecology,项目名称:DeepForest,代码行数:26,代码来源:image.py

示例10: capture_histogram

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2HSV [as 别名]
def capture_histogram(path_of_sample):

    # read the image
    color = cv2.imread(path_of_sample)

    # convert to HSV
    color_hsv = cv2.cvtColor(color, cv2.COLOR_BGR2HSV)

    # compute the histogram
    object_hist = cv2.calcHist([color_hsv],      # image
                               [0, 1],           # channels
                               None,             # no mask
                               [180, 256],       # size of histogram
                               [0, 180, 0, 256]  # channel values
                               )

    # min max normalization
    cv2.normalize(object_hist, object_hist, 0, 255, cv2.NORM_MINMAX)

    return object_hist 
开发者ID:PacktPublishing,项目名称:Hands-On-Machine-Learning-with-OpenCV-4,代码行数:22,代码来源:object_detection_using_color.py

示例11: face_whiten

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2HSV [as 别名]
def face_whiten(self, im_bgr, whiten_rate=0.15):
        """Face whitening.
        Parameters
        ----------
        im_bgr: mat 
            The Mat data format of reading from the original image using opencv.
        whiten_rate: float, default is 0.15
            The face whitening rate.
        Returns
        -------
        type: mat
            The result of face whitening.
        """  
        im_hsv = cv2.cvtColor(im_bgr, cv2.COLOR_BGR2HSV)
        im_hsv[:,:,-1] = np.minimum(im_hsv[:,:,-1] * (1 + whiten_rate), 255).astype('uint8')
        im_whiten = cv2.cvtColor(im_hsv, cv2.COLOR_HSV2BGR)
        return im_whiten 
开发者ID:becauseofAI,项目名称:MobileFace,代码行数:19,代码来源:mobileface_makeup.py

示例12: augment

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2HSV [as 别名]
def augment(self, image, target):
        """Augments the data.

        Args:
            image: The image.
            target: The target image.

        Returns:
            A tuple of augmented image and target image.
        """
        # Sample the color factor.
        factor = np.random.uniform(self._min_delta, self._max_delta)

        hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)

        hsv_image[:, :, 1] *= factor
        hsv_image[:, :, 1] = np.clip(hsv_image[:, :, 1], 0.0, 1.0)

        image = cv2.cvtColor(hsv_image, cv2.COLOR_HSV2BGR)

        return image, target 
开发者ID:TobyPDE,项目名称:FRRN,代码行数:23,代码来源:data.py

示例13: threshold_video

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2HSV [as 别名]
def threshold_video(lower_color, upper_color, blur):


    # Convert BGR to HSV
    hsv = cv2.cvtColor(blur, cv2.COLOR_BGR2HSV)

    # hold the HSV image to get only red colors
    mask = cv2.inRange(hsv, lower_color, upper_color)

    # Returns the masked imageBlurs video to smooth out image

    return mask



# Finds the tape targets from the masked image and displays them on original stream + network tales 
开发者ID:team3997,项目名称:ChickenVision,代码行数:18,代码来源:ChickenVision.py

示例14: _detect_team_color

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2HSV [as 别名]
def _detect_team_color(self, pixels):
        criteria = \
            (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 10, 1.0)

        pixels = np.array(pixels.reshape((-1, 3)), dtype=np.float32)

        ret, label, center = cv2.kmeans(
            pixels, 2, None, criteria, 10, cv2.KMEANS_RANDOM_CENTERS)

        # one is black, another is the team color.

        colors = np.array(center, dtype=np.uint8).reshape((1, 2, 3))
        colors_hsv = cv2.cvtColor(colors, cv2.COLOR_BGR2HSV)
        x = np.argmax(colors_hsv[:, :, 2])
        team_color_bgr = colors[0, x, :]
        team_color_hsv = colors_hsv[0, x, :]

        return {
            'rgb': cv2.cvtColor(colors, cv2.COLOR_BGR2RGB).tolist()[0][x],
            'hsv': cv2.cvtColor(colors, cv2.COLOR_BGR2HSV).tolist()[0][x],
        } 
开发者ID:hasegaw,项目名称:IkaLog,代码行数:23,代码来源:inklings_tracker.py

示例15: analyze_team_colors

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2HSV [as 别名]
def analyze_team_colors(self, context, img):
        # スクリーンショットからチームカラーを推測
        assert 'won' in context['game']
        assert img is not None

        if context['game']['won']:
            my_team_color_bgr = img[115:116, 1228:1229]
            counter_team_color_bgr = img[452:453, 1228:1229]
        else:
            counter_team_color_bgr = img[115:116, 1228:1229]
            my_team_color_bgr = img[452:453, 1228:1229]

        my_team_color = {
            'rgb': cv2.cvtColor(my_team_color_bgr, cv2.COLOR_BGR2RGB).tolist()[0][0],
            'hsv': cv2.cvtColor(my_team_color_bgr, cv2.COLOR_BGR2HSV).tolist()[0][0],
        }

        counter_team_color = {
            'rgb': cv2.cvtColor(counter_team_color_bgr, cv2.COLOR_BGR2RGB).tolist()[0][0],
            'hsv': cv2.cvtColor(counter_team_color_bgr, cv2.COLOR_BGR2HSV).tolist()[0][0],
        }

        return (my_team_color, counter_team_color) 
开发者ID:hasegaw,项目名称:IkaLog,代码行数:25,代码来源:result_detail.py


注:本文中的cv2.COLOR_BGR2HSV属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。