本文整理汇总了Python中FileIO.read_shot_boundaries方法的典型用法代码示例。如果您正苦于以下问题:Python FileIO.read_shot_boundaries方法的具体用法?Python FileIO.read_shot_boundaries怎么用?Python FileIO.read_shot_boundaries使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileIO
的用法示例。
在下文中一共展示了FileIO.read_shot_boundaries方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createMotionDirectionHistograms
# 需要导入模块: import FileIO [as 别名]
# 或者: from FileIO import read_shot_boundaries [as 别名]
def createMotionDirectionHistograms(filename, videoname, v, show_video, flip_video):
#read video
cap = cv2.VideoCapture(videoname)
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
#read ground truth for shot boundaries
ground_truth_start, ground_truth_end = FileIO.read_shot_boundaries(filename)
points0 = 0 #old features
points1 = 0 #new features
mdh_all = [] #list of motion direction histogram for all shots
mdh = []
n = v
points_original = dense_sampling(n, height, width)
ret, frame = cap.read()
#flip video for 16 oberstdorf
if flip_video:
frame = cv2.flip(frame, 1)
index = 1
while cap.isOpened():
ret, frame = cap.read()
if flip_video:
frame = cv2.flip(frame, 1)
#stop after last frame
if frame is None:
cap.release()
break
#init on shot start
if index in ground_truth_start:
#get starting points
old_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# points0 = cv2.goodFeaturesToTrack(old_gray, n, 0.01, 1)
points0 = points_original.copy()
#init motion direction histogram
mdh = [0] * 13
else:
#cvt to gray
frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
#calc optical flow between two frames
points1, status, err = cv2.calcOpticalFlowPyrLK(old_gray, frame_gray, points0, None)
#get good points (points that are in both frames)
points0_good = points0[status == 1]
points1_good = points1[status == 1]
#do the calculations
#---------------
#draw all motion vectors
if show_video:
for i in range(0, len(points1_good)):
#draw
pt1 = (int(points0_good[i][0]), int(points0_good[i][1]))
pt2 = (int(points1_good[i][0]), int(points1_good[i][1]))
cv2.line(frame, pt1, pt2, (0,0,255))
# show frame
cv2.imshow("Video", frame)
#exit or pause
key = cv2.waitKey(10) & 0xFF
if key == ord('q'):
break
if key == ord(' '):
cv2.waitKey(0)
#calc bins
#calc differences of points
sub = np.subtract(points0_good, points1_good)
for i in range(0, len(sub)):
p = sub[i]
#if the point doesn't move, it's in bin #0
if (int(p[0]) == 0) and (int(p[1]) == 0):
mdh[0] += 1
#else calc the angle and add to bin
else:
angle = 180-math.degrees(np.arctan2(p[1], p[0])) #first y, then x
bin_index = int((angle/30)) + 1
mdh[bin_index] += 1
#reset on a new shot
if index in ground_truth_end:
#normalize so every histogram has ~n values
temp = float(sum(mdh)) / n
if int(temp) == 0:
temp = 1
mdh_new = [x/temp for x in mdh]
mdh_all.append(mdh_new[:]) #append a copy of the vector
#----------------
#get points of current frame for next frame
#.........这里部分代码省略.........