Skip to content

Instantly share code, notes, and snippets.

@lilacs2039
Created September 17, 2017 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lilacs2039/e0477ed3abd10463243872d243bc0bd0 to your computer and use it in GitHub Desktop.
Save lilacs2039/e0477ed3abd10463243872d243bc0bd0 to your computer and use it in GitHub Desktop.
指定したフォルダ内の画像ファイルのファイル名・幅・高さ・チャネル数・データタイプをファイルに上書き保存
"""
指定したフォルダ内の画像ファイルのファイル名・幅・高さ・チャネル数・データタイプをファイルに上書き保存
USAGE
python checkImagesChannels --dir path/to/imgs
"""
import argparse
import glob
import cv2
import sys
parser = argparse.ArgumentParser()
parser.add_argument("--dir", help="path to folder containing images")
parser.add_argument("--resultFile",default='imageChannels.txt', help="file name to save results")
a = parser.parse_args()
def showChannels(imageFileName):
img = cv2.imread(imageFileName, cv2.IMREAD_UNCHANGED)
if img is None:
print("Failed to load image file.")
sys.exit(1)
if len(img.shape) == 3:
height, width, channels = img.shape[:3]
else:
height, width = img.shape[:2]
channels = 1
result = "file:%s,width:%s,height:%s,channels:%s,dtype:%s" % (
str(imageFileName), str(width), str(height), str(channels), str(img.dtype))
print(result)
return result
if __name__ == "__main__":
with open(a.resultFile, 'w') as f:
for file in glob.glob(a.dir + "/*"):
f.write(showChannels(file)+"\r\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment