本文整理匯總了Python中Math.dis_cos方法的典型用法代碼示例。如果您正苦於以下問題:Python Math.dis_cos方法的具體用法?Python Math.dis_cos怎麽用?Python Math.dis_cos使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Math
的用法示例。
在下文中一共展示了Math.dis_cos方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: classficition
# 需要導入模塊: import Math [as 別名]
# 或者: from Math import dis_cos [as 別名]
def classficition(features_path, save_path, picture_path, suff=".bmp"):
# 標誌序列,0表示沒有比對過的,1表示已經比對過的
if not os.path.exists(save_path):
os.mkdir(save_path)
all_num = text_process.Pic_Num(features_path, count=[0])
mark = [0] * all_num
file_num = 0
dis = 0.65 # 此閾值可根據你自己需要更改
for i in range(all_num):
if mark[i] != 0:
continue
else:
mark[i] = 1
save_dir_name = "%s%d" % (save_path + "/", file_num)
if not os.path.exists(save_dir_name):
os.mkdir(save_dir_name)
oldf_num = "%09d" % i
oldfile_name = "%s%s%s" % (picture_path + "/", oldf_num, suff)
newfile_name = "%s%s%09d%s" % (save_dir_name, "/", 0, suff)
shutil.copyfile(oldfile_name, newfile_name)
bais_feature_num = i
bais_feature_file = "%s%09d%s" % (features_path + "/", bais_feature_num, ".txt")
bais_features_data = text_process.load(bais_feature_file)
j = i + 4000 # 在1000張範圍內搜索
end = Math.Min(j, all_num)
num = 1
count = 0
for k in range(i + 1, end):
if mark[k] != 0:
continue
else:
feature_num = k
feature_file = "%s%09d%s" % (features_path + "/", feature_num, ".txt")
feature_data = text_process.load(feature_file)
# 計算相似度
sim = Math.dis_cos(np.array(bais_features_data), np.array(feature_data), 256, "false")
if sim < dis:
continue
else:
mark[k] = 1
count += 1
oldf_num = "%09d" % k
oldfile_name = "%s%s%s" % (picture_path + "/", oldf_num, suff)
newfile_name = "%s%s%09d%s" % (save_dir_name, "/", num, suff)
num += 1
shutil.copyfile(oldfile_name, newfile_name)
if count < 10:
shutil.rmtree(save_dir_name)
else:
file_num += 1
print u"分類結束,共得到%d類" % (file_num)
示例2: classficition
# 需要導入模塊: import Math [as 別名]
# 或者: from Math import dis_cos [as 別名]
def classficition(features_path,save_path,picture_path,suff='.bmp'):
#標誌序列,0表示沒有比對過的,1表示已經比對過的
if not os.path.exists(save_path):
os.mkdir(save_path)
all_num = text_process.Pic_Num(features_path,count=[0])
mark = [0]*all_num
file_num = 0
dis = 0.65# 此閾值可根據你自己需要更改
for i in range(all_num):
if mark[i] != 0:
continue
else:
mark[i] = 1
save_dir_name = "%s%d"%(save_path+'/',file_num)
if not os.path.exists(save_dir_name):
os.mkdir(save_dir_name)
oldf_num = '%09d'%i
oldfile_name = '%s%s%s'%(picture_path+'/',oldf_num,suff)
newfile_name = '%s%s%09d%s'%(save_dir_name,'/',0,suff)
shutil.copyfile(oldfile_name,newfile_name)
bais_feature_num = i
bais_feature_file = '%s%09d%s'%(features_path+'/',bais_feature_num,'.txt')
bais_features_data = text_process.load(bais_feature_file)
j = i + 2000 #在1000張範圍內搜索
end = Math.Min(j,all_num)
num = 1
for k in range(i+1,end):
if mark[k] != 0:
continue
else:
feature_num = k
feature_file = '%s%09d%s'%(features_path+'/',feature_num,'.txt')
feature_data = text_process.load(feature_file)
#計算相似度
sim = Math.dis_cos(np.array(bais_features_data),np.array(feature_data),256,'false')
if sim<dis:
continue
else:
mark[k] = 1
oldf_num = '%09d'%k
oldfile_name = '%s%s%s'%(picture_path+'/',oldf_num,suff)
newfile_name = '%s%s%09d%s'%(save_dir_name,'/',num,suff)
num += 1
shutil.copyfile(oldfile_name,newfile_name)
file_num += 1
print u'分類結束,共得到%d類'%(file_num)
示例3: feature_class
# 需要導入模塊: import Math [as 別名]
# 或者: from Math import dis_cos [as 別名]
def feature_class(imagelist,save_path,features_path,dis=0.65,suff='.bmp'):
if not os.path.exists(save_path):
os.mkdir(save_path)
fr0 = open(imagelist,'r')
line_num = fr0.readlines()
all_num = len(line_num)
end = all_num
#mark 標記數組 標誌序列 0表示沒有比對過的,1表示已經比對過的
mark = [0]*all_num
file_num = 0
#通過imagelist獲得picture_path
fr = open(imagelist,'r')
line = fr.readline().strip('\n').split('.')[0]
word = line.split('/')
picture_path = word[0]+'/'
for i in range(1,(len(word)-1)):
picture_path += word[i] + '/'
fr.close()
#大循環分類
count = 0
for i in range(all_num):
if mark[i] != 0:
continue
else:
mark[i] = 1
save_dir_name = '%s%s%d'%(save_path,'/',file_num)
if not os.path.exists(save_dir_name):
os.mkdir(save_dir_name)
oldf_num = '%09d'%i
oldfile_name = '%s%s%s'%(picture_path,oldf_num,suff)
newfile_name = '%s%s%09d%s'%(save_dir_name,'/',0,suff)
shutil.copyfile(oldfile_name,newfile_name)# 複製基準圖像到文件夾
bais_feature_num = i
bais_feature_file = '%s%s%09d%s'%(features_path,'/',bais_feature_num,'.pkl')
fr1 = open(bais_feature_file,'rb')
bais_features_data = pickle.load(fr1) #獲得了基準特征數據
num = 1# 每類中圖片編號
for k in range(i+1,end):
if mark[k] != 0:
continue
else:
feature_num = k
feature_file = '%s%s%09d%s'%(features_path,'/',feature_num,'.pkl')
fr2 = open(feature_file,'rb')
feature_data = pickle.load(fr2).reshape(256,1)
#計算相似度
sim = Math.dis_cos(bais_features_data,feature_data)
if sim < dis:
continue
else:
mark[k] = 1
oldf_num = '%09d'%k
oldfile_name = '%s%s%s'%(picture_path,oldf_num,suff)
newfile_name = '%s%s%09d%s'%(save_dir_name,'/',num,suff)
num += 1
shutil.copyfile(oldfile_name,newfile_name)
count += 1
if count%1000 == 0:
print u'feature_class %d 張圖片'%(count)
file_num += 1
fr1.close()
fr2.close()
print u'feature_class 已經完成,共處理%d張圖片'%(count)