cvmex.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env python
  2. def substitute(cv, output_dir):
  3. # setup the template engine
  4. template_dir = os.path.join(os.path.dirname(__file__), 'templates')
  5. jtemplate = Environment(loader=FileSystemLoader(template_dir), trim_blocks=True, lstrip_blocks=True)
  6. # add the filters
  7. jtemplate.filters['cellarray'] = cellarray
  8. jtemplate.filters['split'] = split
  9. jtemplate.filters['csv'] = csv
  10. # load the template
  11. template = jtemplate.get_template('template_cvmex_base.m')
  12. # create the build directory
  13. output_dir = output_dir+'/+cv'
  14. if not os.path.isdir(output_dir):
  15. os.mkdir(output_dir)
  16. # populate template
  17. populated = template.render(cv=cv, time=time)
  18. with open(os.path.join(output_dir, 'mex.m'), 'wb') as f:
  19. f.write(populated.encode('utf-8'))
  20. if __name__ == "__main__":
  21. """
  22. Usage: python cvmex.py
  23. --opts [-list -of -opts]
  24. --include_dirs [-list -of -opencv_include_directories]
  25. --lib_dir opencv_lib_directory
  26. --libs [-lopencv_core -lopencv_imgproc ...]
  27. --flags [-Wall -opencv_build_flags ...]
  28. --outdir /path/to/generated/output
  29. cvmex.py generates a custom mex compiler that automatically links OpenCV
  30. libraries to built sources where appropriate. The calling syntax is the
  31. same as the builtin mex compiler, with added cv qualification:
  32. >> cv.mex(..., ...);
  33. """
  34. # parse the input options
  35. import sys, re, os, time
  36. from argparse import ArgumentParser
  37. parser = ArgumentParser()
  38. parser.add_argument('--opts')
  39. parser.add_argument('--include_dirs')
  40. parser.add_argument('--lib_dir')
  41. parser.add_argument('--libs')
  42. parser.add_argument('--flags')
  43. parser.add_argument('--outdir')
  44. cv = parser.parse_args()
  45. from filters import *
  46. from jinja2 import Environment, FileSystemLoader
  47. # populate the mex base template
  48. substitute(cv, cv.outdir)