Package pyvision :: Package tools :: Module sigset_to_csv
[hide private]
[frames] | no frames]

Source Code for Module pyvision.tools.sigset_to_csv

 1  # PyVision License 
 2  # 
 3  # Copyright (c) 2006-2008 David S. Bolme 
 4  # All rights reserved. 
 5  # 
 6  # Redistribution and use in source and binary forms, with or without 
 7  # modification, are permitted provided that the following conditions 
 8  # are met: 
 9  #  
10  # 1. Redistributions of source code must retain the above copyright 
11  # notice, this list of conditions and the following disclaimer. 
12  #  
13  # 2. Redistributions in binary form must reproduce the above copyright 
14  # notice, this list of conditions and the following disclaimer in the 
15  # documentation and/or other materials provided with the distribution. 
16  #  
17  # 3. Neither name of copyright holders nor the names of its contributors 
18  # may be used to endorse or promote products derived from this software 
19  # without specific prior written permission. 
20  #  
21  #  
22  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
23  # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
24  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
25  # A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR 
26  # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
27  # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
28  # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
29  # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
30  # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
31  # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
32  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
33  ''' 
34  Created on Jan 14, 2011 
35   
36  @author: bolme 
37   
38  Convert a simple sigset into a comma sep value file.  Does not currently support complex sigests. 
39  ''' 
40  import pyvision as pv 
41  #import pyvision.analysis.FaceAnalysis.BEE as bee 
42  import optparse 
43  import csv 
44   
45   
46   
47 -def parseOptions():
48 usage = "usage: %prog [options] <input.xml> <output.csv>" 49 parser = optparse.OptionParser(usage) 50 #parser.add_option("-v", "--verbose", 51 # action="store_true", dest="verbose", 52 # help="Turn on more verbose output.") 53 (options, args) = parser.parse_args() 54 55 if len(args) != 2: 56 parser.error("This program requires two arguments: an input sigest and an output csv file.") 57 58 return options, args
59 60 61 62 if __name__ == '__main__': 63 options,args = parseOptions() 64 65 sigset = pv.parseSigSet(args[0]) 66 67 rows = [] 68 header = ["sub_id","rec_id","filename","modality","file_format"] 69 rows.append(header) 70 for each in sigset: 71 sub_id = each[0] 72 rec_id = each[1][0]['name'] 73 filename = each[1][0]['file-name'] 74 modality = each[1][0]['modality'] 75 file_format = each[1][0]['file-format'] 76 row = [sub_id,rec_id,filename,modality,file_format] 77 rows.append(row) 78 79 f = csv.writer(open(args[1],'wb')) 80 f.writerows(rows) 81