首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我想解压7z文件并将img(在7z中)更改为numpy array

我想解压7z文件并将img(在7z中)更改为numpy array
EN

Stack Overflow用户
提问于 2017-06-28 23:54:09
回答 1查看 559关注 0票数 0

我在kaggle中安装了7z文件。但是我不知道如何在python3中使用7z文件。我想解压7z文件,并将img(在7z中)改为numpy array。

请帮帮我。

https://www.kaggle.com/rhammell/planesnet

EN

回答 1

Stack Overflow用户

发布于 2017-06-29 00:20:24

试试这个:

代码语言:javascript
复制
import subprocess
import os
import cv2  # pip install cv2

def get_images(path_to_7z_file):
    # in windows would be something like C:\Program Files\7-Zip\7z.exe
    # for linux /usr/local/bin/7z. check it using "which" command
    exe_7z = r'path/to/7z/executable' 
    # x is for extracting, you can use other 7zip flags, check "7z --help" command
    subprocess_args = ('%s x %s' % (exe_7z, s7z_file)).split(' ')
    process_7z = subprocess.Popen(subprocess_args)
    ret_code = process_7z.wait()
    if ret_code != 0:
        # maybe the system could not find the 7z executable
        # or the 7z file could not be opened
        print 'error in 7z command' 
    else:
        img_files = [
            f for f in os.listdir('.')
            if (os.path.isfile(f) and 
                f.split('.')[1].lower() in ['png', 'jpg']) # other extensions
        ]
        # img_files holds the list of images within the 7z archive
        for img_file in img_files:
            img = cv2.imread(img_file) 
            # at this point, img is a numpy.array

您可以使用Pillowcv2来处理图像。有关更多信息,请查看此question

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44807386

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档