Created
September 17, 2017 05:52
-
-
Save lilacs2039/e0477ed3abd10463243872d243bc0bd0 to your computer and use it in GitHub Desktop.
指定したフォルダ内の画像ファイルのファイル名・幅・高さ・チャネル数・データタイプをファイルに上書き保存
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
指定したフォルダ内の画像ファイルのファイル名・幅・高さ・チャネル数・データタイプをファイルに上書き保存 | |
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