Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. #!/usr/bin/python2
  2. import os, sys
  3. import os.path as op
  4. from PIL import Image
  5. from modules import data_wizard as dw
  6. from modules import dwarf as db
  7. from modules import imaginarium as img
  8. import pprint
  9. import random as rn
  10. import numpy as np
  11.  
  12. def get_halfs(image):
  13.     w, h = image.size
  14.     im1 = image.crop([0, 0, w/2, h])
  15.     im2 = image.crop([w - w/2, 0, w, h])
  16.     return im1, im2
  17.  
  18.  
  19. def find_in_list(inp_list, target):
  20.     for i, line in enumerate(inp_list):
  21.         # print i, line
  22.         if line == target:
  23.             print target
  24.             raw_input(line)
  25.             return i
  26.     return -1
  27.  
  28. def get_path_linux(path):
  29.     return '/'.join(path.split('/')[-2:])
  30.  
  31.  
  32. def get_path_win(path):
  33.     return '/'.join(path.split('\\')[-2:])[:30]
  34.  
  35.  
  36. def subsample_idxs(src):
  37.     idxs = np.arange(src.table.nrows)
  38.     np.random.shuffle(idxs)
  39.     return idxs[0:1000]
  40.  
  41. if __name__ == '__main__':
  42.     if len(sys.argv) < 3:
  43.         dw.critisize_and_quit('Usage: <src> <dst>')
  44.  
  45.     src = sys.argv[1]
  46.     dst = sys.argv[2]
  47.  
  48.     dw.is_path('Wrong path to src: "%s"' % src, src)
  49.  
  50.     src_base = db.DataBase(src)
  51.     dst_base = db.DataBase(dst)
  52.     ddict = {}
  53.     n = src_base.table.nrows
  54.     # for i in xrange(n):
  55.     for i in subsample_idxs(src_base):
  56.         cell = src_base.get_cell_dict(i)
  57.         name = cell['name']
  58.         # if name not in ddict:
  59.         #   ddict[name] = ''
  60.         cell['image'] = src_base.read_image(i)
  61.         dst_base.append_item(cell)
  62.         dw.show_progress(i, n)
  63.  
  64.     print 'src size %d, dst size %d' % (src_base.table.nrows, dst_base.table.nrows)
  65.     src_base.file_body.close()
  66.     dst_base.file_body.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement