如何处理“OSError:cannotseek back after get firstbytes”在尝试将jpg文件提取到numpy数组时

2024-03-28 19:11:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将zip文件中的所有图像收集到numpy数组中。你知道吗

总是出错: OSError:获取firstbytes后无法返回!你知道吗

import urllib.request
import os
import zipfile
import scipy
import numpy as np
import pandas as pd
import glob
import imageio
from os.path import splitext

url = 'https://github.com/yoavram/Sign-Language/raw/master/Dataset.zip'
filename = '../data/sign-lang'
if not os.path.exists('../data'):
    os.mkdir('../data')
if not os.path.exists(filename):
    urllib.request.urlretrieve(url, filename)

zf = zipfile.ZipFile(filename)

for file in zf.namelist():
    basename,extension = splitext(file)
    if extension == '.jpg':
        with zf.open(file) as img_file:
            img = imageio.read(img_file)

救命啊?你知道吗


Tags: pathimportnumpyimgdataifosrequest