$search
00001 # 00002 # Software License Agreement (BSD License) 00003 # 00004 # Copyright (c) 2010, Willow Garage, Inc. 00005 # All rights reserved. 00006 # 00007 # Redistribution and use in source and binary forms, with or without 00008 # modification, are permitted provided that the following conditions 00009 # are met: 00010 # 00011 # * Redistributions of source code must retain the above copyright 00012 # notice, this list of conditions and the following disclaimer. 00013 # * Redistributions in binary form must reproduce the above 00014 # copyright notice, this list of conditions and the following 00015 # disclaimer in the documentation and/or other materials provided 00016 # with the distribution. 00017 # * Neither the name of Willow Garage, Inc. nor the names of its 00018 # contributors may be used to endorse or promote products derived 00019 # from this software without specific prior written permission. 00020 # 00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 # POSSIBILITY OF SUCH DAMAGE. 00033 # 00034 # \author Aitor Aldoma 00035 # 00036 # Connects to the household_objects and call for 00037 # generate_views_vfh for the models for which views and vfh descriptors 00038 # havent been yet generated... 00039 # To execute this script: python scripts/household_objects_db_update.py 00040 # 00041 00042 import psycopg2 00043 import sys 00044 import os 00045 import pickle 00046 import dbutils 00047 00048 try: 00049 connection = psycopg2.connect(database="household_objects", user="willow", password="willow", host="wgs36") 00050 except: 00051 print "I am unable to connect to the database." 00052 00053 cur = connection.cursor() 00054 00055 DB_PATH=dbutils.getPlyModelsRoot(cur) 00056 ITERATION = int(sys.argv[2]) 00057 00058 #read models in a directory 00059 directory = sys.argv[1] 00060 query = "" 00061 for f in os.listdir(directory): 00062 if os.path.isfile(os.path.join(directory, f)) and f.endswith(".ply"): 00063 db_path = "ply/" + f 00064 query = query + "fp.file_path_path = '" + db_path + "' OR " 00065 00066 print query[0:-4] 00067 final_query = "SELECT fp.file_path_path,om.original_model_id from original_model as om, file_path as fp WHERE fp.original_model_id = om.original_model_id AND fp.file_type = 'GEOMETRY_BINARY_PLY' AND (" + query[0:-4] + ") ORDER BY om.original_model_id " 00068 00069 try: 00070 cur.execute(final_query) 00071 #9463 - all except the new models.. 00072 #cur.execute("""SELECT fp.file_path_path,om.original_model_id from original_model as om, file_path as fp WHERE fp.original_model_id = om.original_model_id AND fp.file_type = 'GEOMETRY_BINARY_PLY' ORDER BY om.original_model_id""") 00073 except: 00074 print "I can't SELECT from original_model" 00075 00076 rows = cur.fetchall() 00077 for row in rows: 00078 fnstr = DB_PATH + row[0] 00079 model_id = row[1] 00080 00081 cur.execute("""SELECT scaled_model_id,scaled_model_scale from scaled_model WHERE original_model_id = """ + str(model_id)) 00082 scaled_models = cur.fetchall() 00083 for scaled_model in scaled_models: 00084 #parameters are the path to the ply file, the scaled_model_id and the scale_factor to apply to the ply model 00085 if not dbutils.checkViewsGenerated(cur, scaled_model[0], ITERATION): 00086 scaled_factor = float(scaled_model[1]) * 0.001 00087 print str(scaled_model[0]), model_id, fnstr 00088 os.system("rosrun vfh_recognizer_db generate_views_vfh.py " + fnstr + " " + str(scaled_model[0]) + " " + str(scaled_factor) + " " + str(ITERATION)) 00089 print str(scaled_model[0]), model_id, fnstr