changeset 235:584613399513

added script and functions to remove object tables
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 05 Jul 2012 23:32:14 -0400
parents 2d34060db2e9
children eb4525853030
files python/compute-homography.py python/cvutils.py python/delete-object-tables.py python/storage.py python/utils.py
diffstat 5 files changed, 31 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/python/compute-homography.py	Thu Jul 05 23:01:36 2012 -0400
+++ b/python/compute-homography.py	Thu Jul 05 23:32:14 2012 -0400
@@ -52,16 +52,14 @@
 # cvFindHomography(imagePoints, worldPoints, H);
 
 
-if '--help' in options.keys() or '-h' in options.keys():
-    print('''The argument should be the name of a file containing at least 4 non-colinear point coordinates:
+if '--help' in options.keys() or '-h' in options.keys() or len(args) == 0::
+    print('Usage: {0} --help|-h [--video_frame <video frame filename>] [<point_correspondences.txt>]'.format(sys.argv[0]))
+    print('''The positional argument should be the name
+ of a file containing at least 4 non-colinear point coordinates (point correspondences:
  - the first two lines are the x and y coordinates in the projected space (usually world space)
  - the last two lines are the x and y coordinates in the origin space (usually image space)''')
     sys.exit()
 
-if len(args) == 0:
-    print('Usage: {0} --help|-h [--video_frame <video frame filename>] [<point_correspondences.txt>]'.format(sys.argv[0]))
-    sys.exit()
-
 dstPts, srcPts = cvutils.loadPointCorrespondences(args[0])
 homography, mask = cv2.findHomography(srcPts, dstPts) # method=0, ransacReprojThreshold=3
 np.savetxt(utils.removeExtension(sys.argv[1])+'-homography.txt',homography)
--- a/python/cvutils.py	Thu Jul 05 23:01:36 2012 -0400
+++ b/python/cvutils.py	Thu Jul 05 23:32:14 2012 -0400
@@ -138,7 +138,6 @@
             frameNum = firstFrameNum
             capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNum)
             while ret and key!= 113: # 'q'
-                print('capture')
                 ret, img = capture.read()
                 if ret:
                     print('frame {0}'.format(frameNum))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/delete-object-tables.py	Thu Jul 05 23:32:14 2012 -0400
@@ -0,0 +1,15 @@
+#! /usr/bin/env python
+
+import sys,getopt
+
+import utils
+import storage
+
+options, args = getopt.getopt(sys.argv[1:], 'h',['help'])
+options = dict(options)
+
+if '--help' in options.keys() or '-h' in options.keys() or len(args) == 0:
+    print('Usage: {0} --help|-h <database-filename.sqlite>'.format(sys.argv[0]))
+    sys.exit()
+
+storage.removeObjectsFromSqlite(args[0])
--- a/python/storage.py	Thu Jul 05 23:01:36 2012 -0400
+++ b/python/storage.py	Thu Jul 05 23:32:14 2012 -0400
@@ -118,6 +118,13 @@
     connection.close()
     return objects
 
+def removeObjectsFromSqlite(filename):
+    'Removes the objects and object_features tables in the filename'
+    import sqlite3
+    connection = sqlite3.connect(filename)
+    utils.dropTables(connection, ['objects', 'objects_features'])
+    connection.close()
+
 def loadTrajectoriesFromNgsimFile(filename, nObjects = -1, sequenceNum = -1):
     '''Reads data from the trajectory data provided by NGSIM project 
     and returns the list of Feature objects'''
--- a/python/utils.py	Thu Jul 05 23:01:36 2012 -0400
+++ b/python/utils.py	Thu Jul 05 23:32:14 2012 -0400
@@ -320,11 +320,11 @@
 # sqlite
 #########################
 
-#def dropTable(db, tableName):
-    
-
-#def removeObjectsSqlite(filename):
-#    'Removes the objects and object_features tables in the filename'
+def dropTables(connection, tableNames):
+    'deletes the table with names in tableNames'
+    cursor = connection.cursor()
+    for tableName in tableNames:
+        cursor.execute('DROP TABLE '+tableName)
 
 #########################
 # running tests