當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。