一、把video切分为tile
1. 把video切分成以秒为单位的segment
https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_video_display/py_video_display.html
2.把segment切分成rows*colums个tiles
二、 把user的fixaction进行聚类
三、使用svc进行预测
错误整理
1)
图1. 生成video时的编码解决方法:
Python / OpenCV 2.4.9 doesn't support cv2.VideoWriter_fourcc, which is version 3.x. If you're using 2.4.x:
replace fourcc = cv2.VideoWriter_fourcc(*'XVID')
with fourcc = cv2.cv.CV_FOURCC(*'XVID')
2)
错误:
for r in range(0,rows):
for c in range(0,colums-1):
img = frame[r*image_height:r*image_height+image_height,c*image_width:c*image_width+image_width]
tile_frame.append(img)
# the last colum needs to be processed in different ways
img_last_col = frame[r*image_height:r*image_height+image_height,(c)*image_width:]
tile_frame.append(img_last_col)
执行结果:
正确:
for r in range(0,rows):
for c in range(0,colums-1):
img = frame[r*image_height:r*image_height+image_height,c*image_width:c*image_width+image_width]
tile_frame.append(img)
# the last colum needs to be processed in different ways
img_last_col = frame[r*image_height:r*image_height+image_height,(c+1)*image_width:]
tile_frame.append(img_last_col)
执行结果:分析c在执行最内层的循环 for c in range(0,colums-1) 后,c的值为colums-2,不是colums-1;然而,img_last_col对应的colum应该是colums-1.
3)导入特定path下的module
import sys
sys.path.append("F:/project/python")
from utils import WRFile # utils是文件名
4)python中extend和append的区别
a = []
item = ["time"]
item.extend([1,2,4,5])
a.append(item)
print(a)
5)常见的字符串操作
6)string批量转float
import numpy as np
a = ["wj","1.3","2.1"]
b = np.array(a[1:],dtype = "float64")
print(b) #[1.3 2.1]
7)list.append的返回值情况
a = ["wj","1.3","2.1"]
c = []
d = c.append(a) # 返回结果为None
print(c,d) #[['wj', '1.3', '2.1']] None
8)numpy创建多维度数组
import numpy as np
a = np.array([[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]],[[13,14,15],[16,17,18]]])
print(a)
[[[ 1 2 3]
[ 4 5 6]]
[[ 7 8 9]
[ 0 0 0]]
[[13 14 15]
[16 17 18]]]
修改特定元素的值
a[1,1,:] = np.zeros(3)
print(a)
[[[ 1 2 3]
[ 4 5 6]]
[[ 7 8 9]
[ 0 0 0]]
[[13 14 15]
[16 17 18]]]
水平增加一维度
垂直增加一维度
import numpy as np
b = np.arange(1,11,1).reshape((5,2))
c = np.zeros((1,2))
d = np.ones((5,1))
f = np.vstack((b,c)) # 在b的纵向增加元素
e = np.hstack((b,d))#在b的横向增加元素
print("=========vstack==========")
print(f)
print("=========hstack==========")
print(e)
输出结果
=========vstack==========
[[ 1. 2.]
[ 3. 4.]
[ 5. 6.]
[ 7. 8.]
[ 9. 10.]
[ 0. 0.]]
=========hstack==========
[[ 1. 2. 1.]
[ 3. 4. 1.]
[ 5. 6. 1.]
[ 7. 8. 1.]
[ 9. 10. 1.]]
统计numpy中某个元素出现的次数
labels = clustering.labels_ #待分析的numpy数组
mask0 = (labels==0) #统计label内个元素是否等于0,如果等于,mask0的相应位置去True,反之为false
mask1 = (labels == 1)
mask_1 = (labels ==-1)
count_1 = labels[mask_1].size #获得mask_1取True时,labels的元素
count0 = labels[mask0].size
count1 = labels[mask1].size
生成[a,b]内n个不重复的随机数
import numpy as np
import random as ram
a = np.arange(0,48,1)
b = ram.sample(range(0,48),43)
根据随机生成的索引读取数据
import numpy as np
import random as ram
data = np.arange(1,16,1).reshape(5,3)
whole = range(0,5)
samples = ram.sample(whole,3)
test = list(set(whole)-set(samples))#把set转化为list
print("samples",samples)
print("test ",test)
print("data")
print(data)
print("sampele data")
print(data[samples])
print("test data")
print(data[test])
9)分析向量的欧氏距离,确定参数eps
dist = DistanceMetric.get_metric('euclidean')
result = dist.pairwise(X)
10)绘图
def plotScatter(self,x,y,z,slot):
plt.scatter(x=x,y=y,c=z)
plt.xlabel("x",fontsize=20)
plt.ylabel("y",fontsize=20)
plt.legend("z",fontsize=20)
plt.show()
plt.savefig("F:\\project\\dataset\\vr\\Formated_Data\\Experiment_1\\image/xyz"+str(slot)+".png")