Python cv2 模块,hconcat() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用cv2.hconcat()

项目:SketchSimplification    作者:La4La    | 项目源码 | 文件源码
def save_as_img(array, name, origin, transposed=False):
    if transposed:
        origin = origin.transpose(2, 1, 0)
        array = array.transpose(2, 1, 0)
    else:
        origin = origin.transpose(1, 2, 0)
        array = array.transpose(1, 2, 0)

    array = array * 255
    array = array.clip(0, 255).astype(np.uint8)
    img = cuda.to_cpu(array)
    origin = origin.clip(0, 255).astype(np.uint8)

    if args.concat:
        img_concat = cv2.hconcat([origin, img])
        cv2.imwrite(name, img_concat)
    else:
        cv2.imwrite(name, img)
项目:SketchSimplification    作者:La4La    | 项目源码 | 文件源码
def save_as_img(array, name, origin, transposed=False):
    if transposed:
        origin = origin.transpose(2, 1, 0)
        array = array.transpose(2, 1, 0)
    else:
        origin = origin.transpose(1, 2, 0)
        array = array.transpose(1, 2, 0)

    array = array * 255
    array = array.clip(0, 255).astype(np.uint8)
    img = cuda.to_cpu(array)
    origin = origin.clip(0, 255).astype(np.uint8)

    if args.concat:
        img_concat = cv2.hconcat([origin, img])
        cv2.imwrite(name, img_concat)
    else:
        cv2.imwrite(name, img)
项目:SketchSimplification    作者:La4La    | 项目源码 | 文件源码
def save_as_img(model1, model2, name, origin, transposed=False):
    if transposed:
        origin = origin.transpose(2, 1, 0)
        model1 = model1.transpose(2, 1, 0)
        model2 = model2.transpose(2, 1, 0)
    else:
        origin = origin.transpose(1, 2, 0)
        model1 = model1.transpose(1, 2, 0)
        model2 = model2.transpose(1, 2, 0)

    model1 = model1 * 255
    model1 = model1.clip(0, 255).astype(np.uint8)
    img1 = cuda.to_cpu(model1)

    model2 = model2 * 255
    model2 = model2.clip(0, 255).astype(np.uint8)
    img2 = cuda.to_cpu(model2)

    origin = origin.clip(0, 255).astype(np.uint8)

    img_concat = cv2.hconcat([origin, img1])
    img_concat = cv2.hconcat([img_concat, img2])
    cv2.imwrite(name, img_concat)
项目:imgtile    作者:knjcode    | 项目源码 | 文件源码
def collect(target, output='output.png', per_subdir=False, size='128x128', interpolation='INTER_LINEAR', keep_aspect=False, space='0', space_color='black', tile_num=0, limit=False, imgcat=False, progress=False):
    filename_list = []
    if (per_subdir):
        print("Create images per subdir. `--output` option is ignored.")
        find_all_files_per_subdir(
            target, size, interpolation, keep_aspect, space, space_color, tile_num, limit, imgcat, progress)
        return
    else:
        if (os.path.isdir(target)):
            for filename in find_all_files(target):
                filename_list.append(filename)

    if limit:
        limit = int(limit)
        filename_list = filename_list[0:limit]

    print("files:", len(filename_list))
    if (tile_num == 0):
        tile_num = int(math.ceil(math.sqrt(len(filename_list))))
    print("horizontal tile number:", tile_num)

    space = int(space)
    if isinstance(space_color, string_types):
        space_color = webcolors.name_to_rgb(space_color)
    interpolation = getattr(cv2, interpolation, 1)
    image_list = []
    for filename in tqdm(filename_list, desc='Loading images', disable=(not progress)):
        img = cv2.imread(filename)
        resize_x, resize_y = int(size.split('x')[0]), int(size.split('x')[1])
        if keep_aspect:
            part_img = resize_keep_aspect(img, resize_x, resize_y, space_color, interpolation=interpolation)
        else:
            part_img = cv2.resize(img, (resize_x, resize_y), interpolation=interpolation)
        if space > 0:
            part_img = padding_blank(part_img, space, space, 0, 0, space_color)
        image_list.append(part_img)

    horizontal_image_list = []
    for horizontal in chunks(image_list, tile_num):
        while (len(horizontal) < tile_num):
            height, width = horizontal[0].shape[:2]
            horizontal.append(create_blank(height, width, space_color))
        horizontal_image_list.append(cv2.hconcat(horizontal))

    result_img = cv2.vconcat(horizontal_image_list)

    if space > 0:
        result_img = padding_blank(result_img, 0, 0, space, space, space_color)

    stdout.write(b'Saving... ')
    stdout.flush()
    if cv2.imwrite(output, result_img):
        stdout.write(b'\rSaved: %s\n' % output.encode('utf8'))
    else:
        stdout.write(b'\rError: Failed to save %s\n' % output.encode('utf8'))
        sys.exit(1)

    if imgcat:
        imgcat_for_iTerm2(output)