本文整理汇总了Python中util.Util.ellipse2bbox方法的典型用法代码示例。如果您正苦于以下问题:Python Util.ellipse2bbox方法的具体用法?Python Util.ellipse2bbox怎么用?Python Util.ellipse2bbox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类util.Util
的用法示例。
在下文中一共展示了Util.ellipse2bbox方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_aflw_face_data
# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import ellipse2bbox [as 别名]
def get_aflw_face_data(k = 12, on_drive = False):
dbpath = 'F:\\datasets\\image_data_sets\\faces\\AFLW'
dbpath = join(dbpath,'aflw.sqlite')
rfpath = 'F:\\datasets\\image_data_sets\\faces\\AFLW\\img'
conn = sqlite3.connect(dbpath)
X = []
c = 0
for file_id,x,y,ra,rb,theta in conn.execute('SELECT file_id,x,y,ra,rb,theta FROM Faces NATURAL JOIN FaceEllipse'):
fpath = join(rfpath,file_id)
frame = fr.get_frame(fpath)
x1,y1,x2,y2 = util.ellipse2bbox(a = ra, b = rb, angle = theta, cx = x, cy = y)
x = x1
y = y1
h = abs(y2-y1)
w = abs(x2-x1)
no_neg = sp.all(sp.array([x,y,h,w]) > 0) ## ignore a bad data in sql table
if frame != None and no_neg:
y,x,w,h = [int(e) for e in (y,x,w,h)]
face = fr.get_patch(frame,y,x,(w,h))
face_r,good_example = Datasets.sample_resize(face,k,k)
if good_example:
print('face:',fpath)
vec = fr.frame_to_vect(face_r)
if not on_drive:
X.append(vec)
face_flip_r = fr.flip_frame(face_r)
vec = fr.frame_to_vect(face_flip_r)
X.append(vec)
else:
for item in Datasets.data_augmentation(frame,y,x,w,h):
fr.write_frame('F:\\train_data\\pos\\' + str(c) + '_' + str(file_id)[:-4] + '_' + 'pos',item)
c +=1
X = sp.array(X)
y = sp.ones(len(X))
return X,y
示例2: get_train_calib_data
# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import ellipse2bbox [as 别名]
def get_train_calib_data(k = 12):
'''
for calibration net
return X - features
y - labels
cnt - count of examples
'''
sp.random.seed(42)
X_data,y_data = [],[]
suff = str(k)
c = 0
X_name = 'train_data_icalib_'+ suff + '.npz'
y_name = 'labels_icalib_'+ suff + '.npz'
label = -1
dbpath = 'F:\\datasets\\image_data_sets\\faces\\AFLW'
dbpath = join(dbpath,'aflw.sqlite')
rfpath = 'F:\\datasets\\image_data_sets\\faces\\AFLW\\img'
conn = sqlite3.connect(dbpath)
c = 0
for file_id,x,y,ra,rb,theta in conn.execute('SELECT file_id,x,y,ra,rb,theta FROM Faces NATURAL JOIN FaceEllipse'):
fpath = join(rfpath,file_id)
frame = fr.get_frame(fpath)
x1,y1,x2,y2 = util.ellipse2bbox(a = ra, b = rb, angle = theta, cx = x, cy = y)
x = x1
y = y1
h = abs(y2-y1)
w = abs(x2-x1)
no_neg = sp.all(sp.array([x,y,h,w]) > 0) ## ignore a bad data in sql table
if frame != None and no_neg:
y,x,w,h = [int(e) for e in (y,x,w,h)]
face = fr.get_patch(frame,y,x,(w,h))
#fr.write_frame('F:\\1\\' + str(c) + 'orig',face)
c += 1
for ((new_y,new_x,new_w,new_h),label) in [(util.calib(y,x,w,h,k),k) for k in sp.random.randint(0,45,5)]:
face = fr.get_patch(frame,new_y,new_x,(new_w,new_h))
no_neg_calib = sp.all(sp.array([new_x,new_y,new_h,new_w]) > 0)
face_r,good_example = Datasets.sample_resize(face,k,k)
if good_example and no_neg_calib:
#fr.write_frame('F:\\1\\' + str(c) + 'calib_'+str(label) ,face)
print('face:',fpath,label)
vec = fr.frame_to_vect(face_r)
X_data.append(vec)
y_data.append(label)
y_data = sp.array(y_data)
sp.savez(y_name,y_data)
X_data = sp.array(X_data)
sp.savez(X_name,X_data)
return X_data,y_data
示例3: get_fddb_face_data
# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import ellipse2bbox [as 别名]
def get_fddb_face_data(k = 12, on_drive = False):
root = 'F:\\datasets\\image_data_sets\\faces\\FDDB\\'
iroot = os.path.join(root,'originalPics')
eroot = os.path.join(root,'FDDB-folds')
pattern = '-ellipseList.txt'
c = 0
X,y = [],[]
for path, subdirs, files in os.walk(eroot):
for fname in files:
if fname.find(pattern) > 0:
fpath = os.path.join(path,fname)
print(fpath)
with open(fpath) as f:
lines = sp.array(f.readlines())
paths_indx = sp.where([line.find('/') > 0 for line in lines])[0]
counts_indx = paths_indx + 1
paths = sp.array([e.strip() for e in lines[paths_indx]])
ellipces = []
for i in counts_indx:
cnt = int(lines[i])
ellipces.append(lines[i+1:i+cnt+1])
ellipces = [ [ [float(num) for num in line.split()[:-1]] for line in e] for e in ellipces]
ellipces = sp.array(ellipces)
for iname,ells in zip(paths[:],ellipces[:]):
ppath = os.path.join(iroot,iname.replace('/','\\')) + '.jpg'
file_id = iname.split('/')[-1]
frame = fr.get_frame(ppath)
for item in ells:
ra,rb,theta,x,y = item
x1,y1,x2,y2 = util.ellipse2bbox(a = ra, b = rb, angle = theta, cx = x, cy = y)
x = x1
y = y1
h = abs(y2-y1)
w = abs(x2-x1)
print(file_id,(y,x,h,w))
non_neg = x > 0 and y > 0
if not non_neg:
continue
if on_drive:
for item in Datasets.data_augmentation(frame,y,x,w,h):
fr.write_frame('F:\\train_data\\pos\\' + str(c) + '_' + str(file_id) + '_pos',item)
c +=1
else:
pass
X = sp.array(X)
y = sp.ones(len(X))
return X,y