Created
November 29, 2016 05:13
-
-
Save Gotoryoo/d81f992ef58a2cd941f447ff615ba3c6 to your computer and use it in GitHub Desktop.
指定したディレクトリの中にある全bmpファイルをタイムスタンプ順でunsignedcharのバイナリファイルに書き出す。
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
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed Apr 15 18:12:36 2015 | |
@author: ryousuke | |
""" | |
""" | |
Created on Wed Apr 15 10:42:49 2015 | |
指定したディレクトリの中にある全bmpファイルをタイムスタンプ順でunsignedcharのバイナリファイルに書き出す | |
@author: jyoshida-sci | |
""" | |
import cv2 | |
import glob | |
import os | |
import struct | |
#files = glob.glob("\\\\192.168.0.54\\share\\work\\20140509_mod64pl9twin_betaray\\twin_electron\\20140515x100centerbottom\\*.bmp") | |
files = glob.glob("C:\\imagedir\\*.bmp") | |
files.sort(key=os.path.getmtime) | |
fout = open('file.dat','wb') | |
for file in files: | |
print file | |
img = cv2.imread(file,cv2.CV_LOAD_IMAGE_GRAYSCALE) | |
'''enhancing contrast''' | |
#(minval,maxval,minloc,maxloc) = cv2.minMaxLoc(img) | |
#minval=20 | |
#maxval=110 | |
#cv2.convertScaleAbs(img, img, 255/(maxval-minval),-255*minval/(maxval-minval)) | |
#print(str.format('{0} {1}', minval,maxval)) | |
for py in range(img.shape[0]): | |
data = struct.pack('B'*img.shape[1], *img[py]) | |
fout.write(data) | |
fout.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment