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


Python cv2.split方法代码示例

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


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

示例1: find_squares

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import split [as 别名]
def find_squares(img):
    img = cv2.GaussianBlur(img, (5, 5), 0)
    squares = []
    for gray in cv2.split(img):
        for thrs in xrange(0, 255, 26):
            if thrs == 0:
                bin = cv2.Canny(gray, 0, 50, apertureSize=5)
                bin = cv2.dilate(bin, None)
            else:
                retval, bin = cv2.threshold(gray, thrs, 255, cv2.THRESH_BINARY)
            bin, contours, hierarchy = cv2.findContours(bin, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
            for cnt in contours:
                cnt_len = cv2.arcLength(cnt, True)
                cnt = cv2.approxPolyDP(cnt, 0.02*cnt_len, True)
                if len(cnt) == 4 and cv2.contourArea(cnt) > 1000 and cv2.isContourConvex(cnt):
                    cnt = cnt.reshape(-1, 2)
                    max_cos = np.max([angle_cos( cnt[i], cnt[(i+1) % 4], cnt[(i+2) % 4] ) for i in xrange(4)])
                    if max_cos < 0.1:
                        squares.append(cnt)
    return squares 
开发者ID:makelove,项目名称:OpenCV-Python-Tutorial,代码行数:22,代码来源:squares.py

示例2: overlay_transparent_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import split [as 别名]
def overlay_transparent_image(bg, fg, x1, y1):
    # bg is 3 RGB
    # fg is 4 RGBA

    bg = bg.copy()
    fg = fg.copy()

    h, w = fg.shape[:2]
    t = bg[y1:y1 + h, x1:x1 + w]

    b, g, r, a = cv2.split(fg)
    mask = cv2.merge((a, a, a))
    fg = cv2.merge((b, g, r))
    overlaid = alpha_blend(t, fg, mask)

    bg[y1:y1 + h, x1:x1 + w] = overlaid

    return bg 
开发者ID:zerofox-oss,项目名称:deepstar,代码行数:20,代码来源:cv.py

示例3: cal_rgb_confidence

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import split [as 别名]
def cal_rgb_confidence(img_src_rgb, img_sch_rgb):
    """同大小彩图计算相似度."""
    # BGR三通道心理学权重:
    weight = (0.114, 0.587, 0.299)
    src_bgr, sch_bgr = cv2.split(img_src_rgb), cv2.split(img_sch_rgb)

    # 计算BGR三通道的confidence,存入bgr_confidence:
    bgr_confidence = [0, 0, 0]
    for i in range(3):
        res_temp = cv2.matchTemplate(src_bgr[i], sch_bgr[i], cv2.TM_CCOEFF_NORMED)
        min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res_temp)
        bgr_confidence[i] = max_val

    # 加权可信度
    weighted_confidence = bgr_confidence[0] * weight[0] + bgr_confidence[1] * weight[1] + bgr_confidence[2] * weight[2]

    return weighted_confidence 
开发者ID:AirtestProject,项目名称:Airtest,代码行数:19,代码来源:cal_confidence.py

示例4: get_image_and_mask

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import split [as 别名]
def get_image_and_mask(img_location, gray_flag):

    # Load image from file with alpha channel (UNCHANGED flag). If an alpha
    # channel does not exist, just return the base image.
    img = cv2.imread(img_location, cv2.IMREAD_UNCHANGED)
    if img.shape[2] <= 3:
        return img, None

    # Create an alpha channel matrix  with values between 0-255. Then
    # threshold the alpha channel to create a binary mask.
    channels = cv2.split(img)
    mask = np.array(channels[3])
    _, mask = cv2.threshold(mask, 250, 255, cv2.THRESH_BINARY)

    # Convert image and mask to grayscale or BGR based on input flag.
    if gray_flag:
        img = cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY)
    else:
        img = cv2.cvtColor(img, cv2.COLOR_BGRA2BGR)
        mask = cv2.cvtColor(mask, cv2.COLOR_GRAY2BGR)

    return img, mask


# Resize an image and mask based on an input scale ratio. 
开发者ID:jpnaterer,项目名称:smashscan,代码行数:27,代码来源:util.py

示例5: get_img_random_crop

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import split [as 别名]
def get_img_random_crop(src, resize=512, crop=256):
    '''Get & resize image and random crop'''
    img = get_img(src)
    img = resize_to(img, resize=resize)
    
    offset_h = random.randint(0, (img.shape[0]-crop))
    offset_w = random.randint(0, (img.shape[1]-crop))
    
    img = img[offset_h:offset_h+crop, offset_w:offset_w+crop, :]

    return img

# def preserve_colors(content_rgb, styled_rgb):
#     """Extract luminance from styled image and apply colors from content"""
#     if content_rgb.shape != styled_rgb.shape:
#       new_shape = (content_rgb.shape[1], content_rgb.shape[0])
#       styled_rgb = cv2.resize(styled_rgb, new_shape)
#     styled_yuv = cv2.cvtColor(styled_rgb, cv2.COLOR_RGB2YUV)
#     Y_s, U_s, V_s = cv2.split(styled_yuv)
#     image_YUV = cv2.cvtColor(content_rgb, cv2.COLOR_RGB2YUV)
#     Y_i, U_i, V_i = cv2.split(image_YUV)
#     styled_rgb = cv2.cvtColor(np.stack([Y_s, U_i, V_i], axis=-1), cv2.COLOR_YUV2RGB)
#     return styled_rgb 
开发者ID:eridgd,项目名称:AdaIN-TF,代码行数:25,代码来源:utils.py

示例6: brightness

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import split [as 别名]
def brightness(self, im):
        '''
        Return the brightness of an image
        Args:
            im(numpy): image

        Returns:
            float, average brightness of an image
        '''
        im_hsv = cv2.cvtColor(im, cv2.COLOR_BGR2HSV)
        h, s, v = cv2.split(im_hsv)
        height, weight = v.shape[:2]
        total_bright = 0
        for i in v:
            total_bright = total_bright + sum(i)
        return float(total_bright) / (height * weight) 
开发者ID:openatx,项目名称:uiautomator2,代码行数:18,代码来源:__init__.py

示例7: image_stats

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import split [as 别名]
def image_stats(image):
	"""
	Parameters:
	-------
	image: NumPy array
		OpenCV image in L*a*b* color space

	Returns:
	-------
	Tuple of mean and standard deviations for the L*, a*, and b*
	channels, respectively
	"""
	# compute the mean and standard deviation of each channel
	(l, a, b) = cv2.split(image)
	(lMean, lStd) = (l.mean(), l.std())
	(aMean, aStd) = (a.mean(), a.std())
	(bMean, bStd) = (b.mean(), b.std())

	# return the color statistics
	return (lMean, lStd, aMean, aStd, bMean, bStd) 
开发者ID:jrosebr1,项目名称:color_transfer,代码行数:22,代码来源:__init__.py

示例8: convert_to_original_colors

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import split [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

示例9: random_hue_saturation_value

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import split [as 别名]
def random_hue_saturation_value(image,
                                hue_shift_limit=(-180, 180),
                                sat_shift_limit=(-255, 255),
                                val_shift_limit=(-255, 255)):

    image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
    h, s, v = cv2.split(image)
    hue_shift = np.random.uniform(hue_shift_limit[0], hue_shift_limit[1])
    h = cv2.add(h, hue_shift)
    sat_shift = np.random.uniform(sat_shift_limit[0], sat_shift_limit[1])
    s = cv2.add(s, sat_shift)
    val_shift = np.random.uniform(val_shift_limit[0], val_shift_limit[1])
    v = cv2.add(v, val_shift)
    image = cv2.merge((h, s, v))
    image = cv2.cvtColor(image, cv2.COLOR_HSV2BGR)

    return image 
开发者ID:asanakoy,项目名称:kaggle_carvana_segmentation,代码行数:19,代码来源:train.py

示例10: brightness

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import split [as 别名]
def brightness(im):
    '''
    Return the brightness of an image
    Args:
        im(numpy): image

    Returns:
        float, average brightness of an image
    '''
    im_hsv = cv2.cvtColor(im, cv2.COLOR_BGR2HSV)
    h, s, v = cv2.split(im_hsv) 
    height, weight = v.shape[:2]
    total_bright = 0
    for i in v:
        total_bright = total_bright+sum(i)
    return float(total_bright)/(height*weight) 
开发者ID:NetEaseGame,项目名称:aircv,代码行数:18,代码来源:__init__.py

示例11: get_alpha

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import split [as 别名]
def get_alpha(imtmp, bgval=1.):
    h, w = imtmp.shape[:2]
    alpha = (~np.all(imtmp == bgval, axis=2)).astype(imtmp.dtype)

    b_channel, g_channel, r_channel = cv2.split(imtmp)

    im_RGBA = cv2.merge((b_channel, g_channel, r_channel, alpha.astype(
        imtmp.dtype)))
    return im_RGBA 
开发者ID:soubhiksanyal,项目名称:RingNet,代码行数:11,代码来源:renderer.py

示例12: append_alpha

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import split [as 别名]
def append_alpha(imtmp):
    alpha = np.ones_like(imtmp[:, :, 0]).astype(imtmp.dtype)
    if np.issubdtype(imtmp.dtype, np.uint8):
        alpha = alpha * 255
    b_channel, g_channel, r_channel = cv2.split(imtmp)
    im_RGBA = cv2.merge((b_channel, g_channel, r_channel, alpha))
    return im_RGBA 
开发者ID:soubhiksanyal,项目名称:RingNet,代码行数:9,代码来源:renderer.py

示例13: color_histogram_of_test_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import split [as 别名]
def color_histogram_of_test_image(test_src_image):

    # load the image
    image = test_src_image

    chans = cv2.split(image)
    colors = ('b', 'g', 'r')
    features = []
    feature_data = ''
    counter = 0
    for (chan, color) in zip(chans, colors):
        counter = counter + 1

        hist = cv2.calcHist([chan], [0], None, [256], [0, 256])
        features.extend(hist)

        # find the peak pixel values for R, G, and B
        elem = np.argmax(hist)

        if counter == 1:
            blue = str(elem)
        elif counter == 2:
            green = str(elem)
        elif counter == 3:
            red = str(elem)
            feature_data = red + ',' + green + ',' + blue
    with open(current_path + '/utils/color_recognition_module/'
              + 'test.data', 'w') as myfile:
        myfile.write(feature_data) 
开发者ID:ahmetozlu,项目名称:vehicle_counting_tensorflow,代码行数:31,代码来源:color_histogram_feature_extraction.py

示例14: __init__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import split [as 别名]
def __init__(self, config):
        name = inflection.underscore(type(self).__name__)
        self.adjust = tuple(map(int, config.get('augmentation', name).split())) 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:5,代码来源:image.py

示例15: __call__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import split [as 别名]
def __call__(self, hsv):
        h, s, v = cv2.split(hsv)
        adjust = random.randint(*self.adjust)
        h = h.astype(np.int) + adjust
        h = np.clip(h, 0, 179).astype(hsv.dtype)
        return cv2.merge((h, s, v)) 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:8,代码来源:image.py


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