我尝试在SO中搜索,但无法找到。我想逐帧迭代视频文件,并想检测是否有任何点,当两个连续帧的分辨率变化。伪代码中期望的功能:
resolution1 = videoFile[0]->resolution
resolution2 = 0;
for frame in videoFile[1:]:
resolution2 = frame->resolution
if (resolution1 != resolution2):
print 'Changes occured'
else:
resolution1 = resolution2
请给我一个库的名字来实现它们,我已经尝试并阅读了OpenCV和PiCamera的文档。提前感谢
你应该使用OpenCV来遍历每一帧。当视频改变分辨率时,应该打印"Changes occurred":
import cv2
capture1 = cv2.VideoCapture('videoname') #Open the video
ret, frame = capture1.read() #Read the first frame
resolution1 = frame.shape #Get resolution
while capture1.isOpened():
ret, frame = capture1.read() #Read the next frame
if ret == False or frame == None:
break #Quit if video ends
resolution2 = frame.shape #Get the new resolution
if resolution1 != resolution2:
print 'Changes occured'
#Change resolution1 to resolution2 so that the new resolutions are
#compared with resolution2, not resolution1.
resolution1 = resolution2