Skip to content

Instantly share code, notes, and snippets.

@musaprg
Created March 6, 2017 23:10
Show Gist options
  • Save musaprg/f203baa735e9560aa7d884c7b3b4a5db to your computer and use it in GitHub Desktop.
Save musaprg/f203baa735e9560aa7d884c7b3b4a5db to your computer and use it in GitHub Desktop.
一括読み込み
import os, sys
import imghdr
import cv2 #PILでも良いと思います
import logging
logger = logging.getLogger(__name__)
#わたされたパスがディレクトリかどうかチェック
if os.path.isdir(inpath):
imgs = []
files = os.listdir(inpath)
for file in files
if not imghdr.what(file):
logger.error('InvalidFile: "%s" is not valid image file.' % file)
continue
img = imread(file, "r") #画像ファイルなら読み込み
if img is not None:
#読み込んだ画像データを配列に格納していぬ
imgs.append(img)
else:
logger.error('CVError: imread() failed while reading "%s"' % file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment