检测视频中的媒体分辨率更改

时间:2015-06-01 19:49:56

标签: python opencv video

我尝试在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的文档。 提前致谢

1 个答案:

答案 0 :(得分:1)

您应该使用OpenCV来遍历每个帧。每当视频更改分辨率时,都应打印“发生更改”:

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