from PIL import Image
import csv

import os, sys

sys.path.insert(1, os.path.join(sys.path[0], ".."))
from ml_util import ml
import numpy as np
import data
import image
import config

# choose the screenshots directory
amount = config.amount
path = data.getDataDir(amount=amount, cut=config.cut, big=config.big)

fileList = os.listdir(path)
fileExt = ".png"
# it is currently expected that the files to be histogrammed lie in the
# same directory as histogrammer.py
imgs = filter(lambda File: File[-4:] == fileExt, fileList)
imgs.sort()
print "Found %d %s images" % (len(imgs), fileExt)

histograms = []
for i in xrange(len(imgs)):
    hist = image.imgToBinnedHistogram(path + imgs[i])
    if np.count_nonzero(hist) < 3:
        print hist
        print "Removing", imgs[i]
        os.remove(path + imgs[i])
Exemple #2
0
from PIL import Image
import os
import data
import config

toSize = 68,38

# choose the screenshots directory
amount = config.amount
cut = config.cut
path = data.getDataDir(amount, cut, big=True)
to_path = data.getDataDir(amount, cut, big=False)

fileList = os.listdir(path)
fileExt = ".png"
# it is currently expected that the files to be histogrammed lie in the
# same directory as histogrammer.py
imgs = filter(lambda File: File[-4:] == fileExt, fileList)
imgs.sort()
print "Found %d %s images" % (len(imgs), fileExt)

for i in xrange(len(imgs)):
    try:
        Image.open(path+imgs[i]).resize(toSize).save(to_path + imgs[i])
    except IOError as e:
        print e