Skip to content

Instantly share code, notes, and snippets.

@monajalal
Created November 29, 2016 01:31
Show Gist options
  • Save monajalal/a150dbd2adbddce070ab8ac870274d88 to your computer and use it in GitHub Desktop.
Save monajalal/a150dbd2adbddce070ab8ac870274d88 to your computer and use it in GitHub Desktop.
creating a database for vidoes
import collections
import sys, os
sys.path.append("/u/j/a/jalal/lib/lib64/python/")
import psycopg2
try:
conn = psycopg2.connect("dbname='tuffydb' user='tuffer' host='localhost' password='strongPassword'")
except:
print "I am unable to connect to the database"
c = conn.cursor()
c.execute("SELECT * FROM web_features")
records = c.fetchall()
features = ["fCLD.txt","fCSD.txt", "fDCD.txt","fEHD.txt", "fHTD.txt", "fSCD.txt"]
x = collections.defaultdict(list)
feat=[]
array1=["3"]
a111=[]
video_name=" ";
keyframe_number=0;
def get_all_arrays_for_a_keyframe(dirname,n,video_id):
print video_id
ar_csd=[]
ar_scd=[]
ar_cld=[]
ar_dcd=[]
ar_htd=[]
ar_ehd=[]
try:
for f in features:
feat_name=f[1:4]
fname=dirname + "/" + f
f = open(fname, 'r')
ar1=[]
for line in f:
line = line.rstrip()
line = line.lstrip()
elems = line.split()
for elem in elems:
if feat_name=="CSD":
ar_csd.append(float(elem))
elif feat_name=="SCD":
ar_scd.append(float(elem))
elif feat_name=="CLD":
ar_cld.append(float(elem))
elif feat_name=="DCD":
ar_dcd.append(float(elem))
elif feat_name=="HTD":
ar_htd.append(float(elem))
elif feat_name=="EHD":
ar_ehd.append(float(elem))
c.execute("INSERT into visual_features( farme_id,csd,scd,cld,dcd,htd,ehd,video_id) values (%s,%s,%s,%s,%s,%s,%s,%s);", (n,ar_csd,ar_scd,ar_cld,ar_dcd,ar_htd,ar_ehd,video_id))
except IOError as e:
return 'NULL'
def get_all_arrays_for_a_clip(keyframe_dir):
for clipd in os.listdir(keyframe_dir):
fullname = keyframe_dir + '/' + clipd
if os.path.isdir(fullname):
(n, v) = clipd.split('_')
if v == "keyframe":
vid=os.path.basename(keyframe_dir)
print vid
get_all_arrays_for_a_keyframe(fullname,n,vid)
else:
print "Skipping {0}".format(clipd)
def get_all_clips(clip_dir): #getting all the clips existing in the visual_features directory
for cdr in os.listdir(clip_dir):
fullname = clip_dir + '/' + cdr
if os.path.isdir(fullname):
(n, v) = cdr.split('_')
if v == "clip":
get_all_arrays_for_a_clip(fullname)
clipdir = sys.argv[1]
get_all_clips(clipdir)
conn.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment