Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python OpenCV 3 VideoWriter插入额外帧_Python_Opencv - Fatal编程技术网

Python OpenCV 3 VideoWriter插入额外帧

Python OpenCV 3 VideoWriter插入额外帧,python,opencv,Python,Opencv,我正在尝试用OpenCV3(Python 3.6)编写一个视频。我在某处找到了这个代码。代码是有效的,但当我播放视频时,似乎每隔几秒钟就会插入错误的帧。看起来这是序列的第一帧。下面是视频的外观。(如果嵌入代码未运行) 在您的代码中,在此代码之后: images = [] for f in os.listdir(dir_path): if f.endswith(ext): images.append(f) 只需添加: images = sorted(images, key=lambd

我正在尝试用OpenCV3(Python 3.6)编写一个视频。我在某处找到了这个代码。代码是有效的,但当我播放视频时,似乎每隔几秒钟就会插入错误的帧。看起来这是序列的第一帧。下面是视频的外观。(如果嵌入代码未运行)


在您的代码中,在此代码之后:

images = []
for f in os.listdir(dir_path):
if f.endswith(ext):
    images.append(f)
只需添加:

 images = sorted(images, key=lambda x: (int(re.sub('\D','',x)),x))

这样我们将得到一个排序的数据。因此,视频帧将全部设置在这些位置。不要忘记将re作为头文件导入

在代码中,在此代码之后:

images = []
for f in os.listdir(dir_path):
if f.endswith(ext):
    images.append(f)
只需添加:

 images = sorted(images, key=lambda x: (int(re.sub('\D','',x)),x))
这样我们将得到一个排序的数据。因此,视频帧将全部设置在这些位置。不要忘记将re作为头文件导入