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


Python cv2.addWeighted方法代码示例

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


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

示例1: blend_transparent

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import addWeighted [as 别名]
def blend_transparent(face_img, overlay_t_img):
    # Split out the transparency mask from the colour info
    overlay_img = overlay_t_img[:, :, :3]  # Grab the BRG planes
    overlay_mask = overlay_t_img[:, :, 3:]  # And the alpha plane

    # Again calculate the inverse mask
    background_mask = 255 - overlay_mask

    # Turn the masks into three channel, so we can use them as weights
    overlay_mask = cv2.cvtColor(overlay_mask, cv2.COLOR_GRAY2BGR)
    background_mask = cv2.cvtColor(background_mask, cv2.COLOR_GRAY2BGR)

    # Create a masked out face image, and masked out overlay
    # We convert the images to floating point in range 0.0 - 1.0
    face_part = (face_img * (1 / 255.0)) * (background_mask * (1 / 255.0))
    overlay_part = (overlay_img * (1 / 255.0)) * (overlay_mask * (1 / 255.0))

    # And finally just add them together, and rescale it back to an 8bit integer image
    return np.uint8(cv2.addWeighted(face_part, 255.0, overlay_part, 255.0, 0.0)) 
开发者ID:akshaybahadur21,项目名称:Emojinator,代码行数:21,代码来源:Emojinator_V2.py

示例2: crop_row_detect

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import addWeighted [as 别名]
def crop_row_detect(image_in):
    
    save_image('0_image_in', image_in)
    
    ### Grayscale Transform ###
    image_edit = grayscale_transform(image_in)
    save_image('1_image_gray', image_edit)
        
    ### Binarization ###
    _, image_edit = cv2.threshold(image_edit, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
    save_image('2_image_bin', image_edit)
    
    ### Stripping ###
    crop_points = strip_process(image_edit)
    save_image('8_crop_points', crop_points)
    
    ### Hough Transform ###
    crop_lines = crop_point_hough(crop_points)
    save_image('9_image_hough', cv2.addWeighted(image_in, 1, crop_lines, 1, 0.0))
    
    return crop_lines 
开发者ID:petern3,项目名称:crop_row_detection,代码行数:23,代码来源:line_detect_1.py

示例3: crop_row_detect

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import addWeighted [as 别名]
def crop_row_detect(image_in):
    '''Inputs an image and outputs the lines'''

    save_image('0_image_in', image_in)

    ### Grayscale Transform ###
    image_edit = grayscale_transform(image_in)
    save_image('1_image_gray', image_edit)

    ### Skeletonization ###
    skeleton = skeletonize(image_edit)
    save_image('2_image_skeleton', skeleton)

    ### Hough Transform ###
    (crop_lines, crop_lines_hough) = crop_point_hough(skeleton)

    save_image('3_image_hough', cv2.addWeighted(image_in, 1, crop_lines_hough, 1, 0.0))
    save_image('4_image_lines', cv2.addWeighted(image_in, 1, crop_lines, 1, 0.0))

    return crop_lines 
开发者ID:petern3,项目名称:crop_row_detection,代码行数:22,代码来源:line_detect_2.py

示例4: vis_parsing_maps

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import addWeighted [as 别名]
def vis_parsing_maps(im, parsing_anno, data_name):
    part_colors = [[255, 255, 255], [0, 255, 0], [255, 0, 0]]

    if data_name == 'figaro1k':
        part_colors = [[255, 255, 255], [255, 0, 0]]

    im = np.array(im)
    vis_im = im.copy().astype(np.uint8)
    vis_parsing_anno_color = np.zeros(
        (parsing_anno.shape[0], parsing_anno.shape[1], 3))

    for pi in range(len(part_colors)):
        index = np.where(parsing_anno == pi)
        vis_parsing_anno_color[index[0], index[1], :] = part_colors[pi]
    vis_parsing_anno_color = vis_parsing_anno_color.astype(np.uint8)

    # Guided filter
    # vis_parsing_anno_color = cv.ximgproc.guidedFilter(
    #     guide=vis_im, src=vis_parsing_anno_color, radius=4, eps=50, dDepth=-1)
    vis_im = cv.addWeighted(vis_im, 0.7, vis_parsing_anno_color, 0.3, 0)

    return vis_im 
开发者ID:JACKYLUO1991,项目名称:Face-skin-hair-segmentaiton-and-skin-color-evaluation,代码行数:24,代码来源:test.py

示例5: draw_lane_fit

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import addWeighted [as 别名]
def draw_lane_fit(undist, warped ,Minv, left_fitx, right_fitx, ploty):
	# Drawing
	# Create an image to draw the lines on
	warp_zero = np.zeros_like(warped).astype(np.uint8)
	color_warp = np.dstack((warp_zero, warp_zero, warp_zero))

	# Recast the x and y points into usable format for cv2.fillPoly()
	pts_left = np.array([np.transpose(np.vstack([left_fitx, ploty]))])
	pts_right = np.array([np.flipud(np.transpose(np.vstack([right_fitx, ploty])))])
	pts = np.hstack((pts_left, pts_right))

	# Draw the lane onto the warped blank image
	cv2.fillPoly(color_warp, np.int_([pts]), (0,255,0))

	# Warp the blank back to original image space using inverse perspective matrix(Minv)
	newwarp = cv2.warpPerspective(color_warp, Minv, (undist.shape[1], undist.shape[0]))
	# Combine the result with the original image
	result = cv2.addWeighted(undist, 1, newwarp, 0.3, 0)

	return result 
开发者ID:ChengZhongShen,项目名称:Advanced_Lane_Lines,代码行数:22,代码来源:image_process.py

示例6: motion2video

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import addWeighted [as 别名]
def motion2video(motion, h, w, save_path, colors, transparency=False, motion_tgt=None, fps=25, save_frame=False):
    nr_joints = motion.shape[0]
    videowriter = imageio.get_writer(save_path, fps=fps)
    vlen = motion.shape[-1]
    if save_frame:
        frames_dir = save_path[:-4] + '-frames'
        ensure_dir(frames_dir)
    for i in tqdm(range(vlen)):
        [img, img_cropped] = joints2image(motion[:, :, i], colors, transparency, H=h, W=w, nr_joints=nr_joints)
        if motion_tgt is not None:
            [img_tgt, img_tgt_cropped] = joints2image(motion_tgt[:, :, i], colors, transparency, H=h, W=w, nr_joints=nr_joints)
            img_ori = img.copy()
            img = cv2.addWeighted(img_tgt, 0.3, img_ori, 0.7, 0)
            img_cropped = cv2.addWeighted(img_tgt, 0.3, img_ori, 0.7, 0)
            bb = bounding_box(img_cropped)
            img_cropped = img_cropped[:, bb[2]:bb[3], :]
        if save_frame:
            save_image(img_cropped, os.path.join(frames_dir, "%04d.png" % i))
        videowriter.append_data(img)
    videowriter.close() 
开发者ID:ChrisWu1997,项目名称:2D-Motion-Retargeting,代码行数:22,代码来源:visualization.py

示例7: sharpen_frame

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import addWeighted [as 别名]
def sharpen_frame(old: np.ndarray) -> np.ndarray:
    """
    refine the edges of an image

    - https://answers.opencv.org/question/121205/how-to-refine-the-edges-of-an-image/
    - https://stackoverflow.com/questions/4993082/how-to-sharpen-an-image-in-opencv

    :param old:
    :return:
    """

    # TODO these args are locked and can not be changed
    blur = turn_blur(old)
    smooth = cv2.addWeighted(blur, 1.5, old, -0.5, 0)
    canny = cv2.Canny(smooth, 50, 150)
    return canny 
开发者ID:williamfzc,项目名称:stagesepx,代码行数:18,代码来源:toolbox.py

示例8: blend_non_transparent

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import addWeighted [as 别名]
def blend_non_transparent(sprite, background_img):
    gray_overlay = cv2.cvtColor(background_img, cv2.COLOR_BGR2GRAY)
    overlay_mask = cv2.threshold(gray_overlay, 1, 255, cv2.THRESH_BINARY)[1]

    overlay_mask = cv2.erode(overlay_mask, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)))
    overlay_mask = cv2.blur(overlay_mask, (3, 3))

    background_mask = 255 - overlay_mask

    overlay_mask = cv2.cvtColor(overlay_mask, cv2.COLOR_GRAY2BGR)
    background_mask = cv2.cvtColor(background_mask, cv2.COLOR_GRAY2BGR)

    sprite_part = (sprite * (1 / 255.0)) * (background_mask * (1 / 255.0))
    overlay_part = (background_img * (1 / 255.0)) * (overlay_mask * (1 / 255.0))

    return np.uint8(cv2.addWeighted(sprite_part, 255.0, overlay_part, 255.0, 0.0)) 
开发者ID:guille0,项目名称:hazymaze,代码行数:18,代码来源:helpers.py

示例9: add_coco_hp

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import addWeighted [as 别名]
def add_coco_hp(image, points, color): 
    for j in range(17):
        cv2.circle(image,
                 (points[j, 0], points[j, 1]), 2, (int(color[0]), int(color[1]), int(color[2])), -1)
                 
    stickwidth = 2
    cur_canvas = image.copy()             
    for j, e in enumerate(_kp_connections):
        if points[e].min() > 0:
            X = [points[e[0], 1], points[e[1], 1]]
            Y = [points[e[0], 0], points[e[1], 0]]
            mX = np.mean(X)
            mY = np.mean(Y)
            length = ((X[0] - X[1]) ** 2 + (Y[0] - Y[1]) ** 2) ** 0.5
            angle = math.degrees(math.atan2(X[0] - X[1], Y[0] - Y[1]))
            polygon = cv2.ellipse2Poly((int(mY),int(mX)), (int(length/2), stickwidth), int(angle), 0, 360, 1)
            cv2.fillConvexPoly(cur_canvas, polygon, (int(color[0]), int(color[1]), int(color[2])))
            image = cv2.addWeighted(image, 0.5, cur_canvas, 0.5, 0)

    return image 
开发者ID:tensorboy,项目名称:centerpose,代码行数:22,代码来源:demo_main.py

示例10: add_coco_hp

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import addWeighted [as 别名]
def add_coco_hp(self, points, points_prob, img_id='default'): 
        points = np.array(points, dtype=np.int32).reshape(self.num_joints, 2)
        points_prob = np.array(points_prob, dtype=np.float32).reshape(self.num_joints)

        for j in range(self.num_joints):
            if points_prob[j]>0.:
                cv2.circle(self.imgs[img_id],
                          (points[j, 0], points[j, 1]), 2, (255,255,255), -1)
                         
        stickwidth = 2
        cur_canvas = self.imgs[img_id].copy()             
        for j, e in enumerate(self.edges):
            if points_prob[e[0]] > 0. and points_prob[e[1]] > 0.:
                X = [points[e[0], 1], points[e[1], 1]]
                Y = [points[e[0], 0], points[e[1], 0]]
                mX = np.mean(X)
                mY = np.mean(Y)
                length = ((X[0] - X[1]) ** 2 + (Y[0] - Y[1]) ** 2) ** 0.5
                angle = math.degrees(math.atan2(X[0] - X[1], Y[0] - Y[1]))
                polygon = cv2.ellipse2Poly((int(mY),int(mX)), (int(length/2), stickwidth), int(angle), 0, 360, 1)
                cv2.fillConvexPoly(cur_canvas, polygon, (255, 255, 255))
                self.imgs[img_id] = cv2.addWeighted(self.imgs[img_id], 0.8, cur_canvas, 0.2, 0) 
开发者ID:tensorboy,项目名称:centerpose,代码行数:24,代码来源:debugger.py

示例11: read_h5py_example

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import addWeighted [as 别名]
def read_h5py_example():
    h5_in = h5py.File(os.path.join(dir_path, 'data.h5'), 'r')
    print (h5_in.keys())
    print (h5_in['train']['image'].dtype)
    print (h5_in['train']['image'][0].shape)

    image_size = h5_in['train']['image'].attrs['size']
    label_size = h5_in['train']['label'].attrs['size']

    x_img = np.reshape(h5_in['train']['image'][0], tuple(image_size))
    y_img = np.reshape(h5_in['train']['label'][0], tuple(label_size))
    name = h5_in['train']['name'][0]
    print (name)
    y_img = (y_img.astype(np.float32)*255/33).astype(np.uint8)
    y_show = cv2.applyColorMap(y_img, cv2.COLORMAP_JET)
    show = cv2.addWeighted(x_img, 0.5, y_show, 0.5, 0)
    cv2.imshow("show", show)
    cv2.waitKey() 
开发者ID:dhkim0225,项目名称:keras-image-segmentation,代码行数:20,代码来源:h5_test.py

示例12: image_copy_to_dir

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import addWeighted [as 别名]
def image_copy_to_dir(mode, x_paths, y_paths):
    target_path = '/run/media/tkwoo/myWorkspace/workspace/01.dataset/03.Mask_data/cityscape'
    target_path = os.path.join(target_path, mode)

    for idx in trange(len(x_paths)):
        image = cv2.imread(x_paths[idx], 1)
        mask = cv2.imread(y_paths[idx], 0)

        image = cv2.resize(image, None, fx=0.25, fy=0.25, interpolation=cv2.INTER_LINEAR)
        mask = cv2.resize(mask, None, fx=0.25, fy=0.25, interpolation=cv2.INTER_NEAREST)

        cv2.imwrite(os.path.join(target_path, 'image', os.path.basename(x_paths[idx])), image)
        cv2.imwrite(os.path.join(target_path, 'mask', os.path.basename(y_paths[idx])), mask)

        # show = image.copy()
        # mask = (mask.astype(np.float32)*255/33).astype(np.uint8)
        # mask_color = cv2.applyColorMap(mask, cv2.COLORMAP_JET)
        # show = cv2.addWeighted(show, 0.5, mask_color, 0.5, 0.0)
        # cv2.imshow('show', show)
        # key = cv2.waitKey(1)
        # if key == 27:
        #     return 
开发者ID:dhkim0225,项目名称:keras-image-segmentation,代码行数:24,代码来源:h5_test.py

示例13: parse_img_seg

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import addWeighted [as 别名]
def parse_img_seg(self, image_file, label_file):
        if image_file is None or not os.path.exists(image_file):
            Log.error('Image file: {} not existed.'.format(image_file))
            return

        if label_file is None or not os.path.exists(label_file):
            Log.error('Label file: {} not existed.'.format(label_file))
            return

        image_canvas = cv2.imread(image_file)  # B, G, R order.

        mask_canvas = self.colorize(np.array(Image.open(label_file).convert('P')))
        image_canvas = cv2.addWeighted(image_canvas, 0.6, mask_canvas, 0.4, 0)

        cv2.imshow('main', image_canvas)
        cv2.waitKey() 
开发者ID:openseg-group,项目名称:openseg.pytorch,代码行数:18,代码来源:seg_parser.py

示例14: parse_dir_seg

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import addWeighted [as 别名]
def parse_dir_seg(self, image_dir, label_dir):
        if image_dir is None or not os.path.exists(image_dir):
            Log.error('Image Dir: {} not existed.'.format(image_dir))
            return

        if label_dir is None or not os.path.exists(label_dir):
            Log.error('Label Dir: {} not existed.'.format(label_dir))
            return

        for image_file in os.listdir(image_dir):
            shotname, extension = os.path.splitext(image_file)
            Log.info(image_file)
            image_canvas = cv2.imread(os.path.join(image_dir, image_file))  # B, G, R order.
            label_file = os.path.join(label_dir, '{}.png'.format(shotname))
            mask_canvas = self.colorize(np.array(Image.open(label_file).convert('P')))
            image_canvas = cv2.addWeighted(image_canvas, 0.6, mask_canvas, 0.4, 0)

            cv2.imshow('main', image_canvas)
            cv2.waitKey() 
开发者ID:openseg-group,项目名称:openseg.pytorch,代码行数:21,代码来源:seg_parser.py

示例15: colorize

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import addWeighted [as 别名]
def colorize(self, label_map, image_canvas=None):
        height, width = label_map.shape
        color_dst = np.zeros((height, width, 3), dtype=np.uint8)
        color_list = self.configer.get('details', 'color_list')
        for i in range(self.configer.get('data', 'num_classes')):
            color_dst[label_map == i] = color_list[i % len(color_list)]

        color_img_rgb = np.array(color_dst, dtype=np.uint8)
        color_img_bgr = cv2.cvtColor(color_img_rgb, cv2.COLOR_RGB2BGR)

        if image_canvas is not None:
            image_canvas = cv2.addWeighted(image_canvas, 0.6, color_img_bgr, 0.4, 0)
            return image_canvas

        else:
            return color_img_bgr 
开发者ID:openseg-group,项目名称:openseg.pytorch,代码行数:18,代码来源:seg_parser.py


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