本文整理汇总了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)