locationmap.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import numpy as np
  2. from utils.path import path
  3. from intersect import Mesh2D
  4. from utils.objparser import Mesh
  5. from scipy.misc import pilutil
  6. from PIL import ImageDraw
  7. OBJ_FILE = path(r'D:\loco-dev\maps\UMIC\umic.obj')
  8. LOCATION_FILE = path(r'D:\loco-dev\maps\UMIC\experiment\locations.txt')
  9. locations = []
  10. for l in LOCATION_FILE.lines():
  11. if l.startswith('#'):
  12. continue
  13. locid, x, y, z = l.split()
  14. locations.append((locid, float(x), float(y), float(z)))
  15. mesh = Mesh()
  16. mesh.parseObjFile(OBJ_FILE)
  17. mesh_xlim = (-1, 58)
  18. mesh_ylim = (-1, 18)
  19. pixel_per_meter = 16
  20. m2d = Mesh2D(mesh, mesh_xlim, mesh_ylim, pixel_per_meter)
  21. Z = [('eg', -2.0), ('og1', 1.0), ('og2', 4.5)]
  22. for name, z_cut in Z:
  23. print 'building %s...' % name
  24. f = path(r'N:\loco\dirk\lws\static\measure_%s.png' % name)
  25. to_be_combined = []
  26. for objname in m2d.objnames:
  27. print 'object: %s' % objname
  28. img = m2d.cut(objname, z_cut)
  29. to_be_combined.append(pilutil.fromimage(img))
  30. all_objects = np.add.reduce(np.array(to_be_combined))
  31. #~ combined_object_image
  32. print 'cache file to %s' % f.abspath()
  33. img = pilutil.toimage(all_objects)
  34. img = img.convert('RGB')
  35. draw = ImageDraw.Draw(img)
  36. for locid, x, y, z in locations:
  37. if abs(z - z_cut) < 2:
  38. _x, _y = m2d.meter2pixel(x, y)
  39. draw.text((_x, _y), locid, fill='#CC1111')
  40. draw.point((_x, _y), fill='#00FF00')
  41. img.save(f)