File: cvmex.py

package info (click to toggle)
opencv 3.2.0%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 238,480 kB
  • sloc: xml: 901,650; cpp: 703,419; lisp: 20,142; java: 17,843; python: 17,641; ansic: 603; cs: 601; sh: 516; perl: 494; makefile: 117
file content (63 lines) | stat: -rw-r--r-- 2,185 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python

def substitute(cv, output_dir):

    # setup the template engine
    template_dir = os.path.join(os.path.dirname(__file__), 'templates')
    jtemplate    = Environment(loader=FileSystemLoader(template_dir), trim_blocks=True, lstrip_blocks=True)

    # add the filters
    jtemplate.filters['cellarray'] = cellarray
    jtemplate.filters['split'] = split
    jtemplate.filters['csv'] = csv

    # load the template
    template = jtemplate.get_template('template_cvmex_base.m')

    # create the build directory
    output_dir  = output_dir+'/+cv'
    if not os.path.isdir(output_dir):
      os.mkdir(output_dir)

    # populate template
    populated = template.render(cv=cv, time=time)
    with open(os.path.join(output_dir, 'mex.m'), 'wb') as f:
        f.write(populated.encode('utf-8'))

if __name__ == "__main__":
    """
    Usage: python cvmex.py  --jinja2 /path/to/jinja2/engine
                            --opts [-list -of -opts]
                            --include_dirs [-list -of -opencv_include_directories]
                            --lib_dir opencv_lib_directory
                            --libs [-lopencv_core -lopencv_imgproc ...]
                            --flags [-Wall -opencv_build_flags ...]
                            --outdir /path/to/generated/output

    cvmex.py generates a custom mex compiler that automatically links OpenCV
    libraries to built sources where appropriate. The calling syntax is the
    same as the builtin mex compiler, with added cv qualification:
      >> cv.mex(..., ...);
    """

    # parse the input options
    import sys, re, os, time
    from argparse import ArgumentParser
    parser = ArgumentParser()
    parser.add_argument('--jinja2')
    parser.add_argument('--opts')
    parser.add_argument('--include_dirs')
    parser.add_argument('--lib_dir')
    parser.add_argument('--libs')
    parser.add_argument('--flags')
    parser.add_argument('--outdir')
    cv = parser.parse_args()

    # add jinja to the path
    sys.path.append(cv.jinja2)

    from filters import *
    from jinja2 import Environment, FileSystemLoader

    # populate the mex base template
    substitute(cv, cv.outdir)