微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么有些像素值的原因在播放过程中口吃?

如何解决为什么有些像素值的原因在播放过程中口吃?

我用下面的函数获取的视频帧。我要么传递noise_type=None,以获得原始帧或传递salt and pepper并与椒盐噪声叠加帧(随机地替换一些RGB像素(0,0,0)或(255,255,255)这是传递旁边一些概率的像素将与黑色或白色像素被替换(例如prob=0.1,以取代使用黑色和白色像素的像素的10%)。

请注意,我使用Python 3.7.9和OpenCV 4.4.0。另外,作为视频将被最终被写入使用moviepy音频数据一起,它们在RGB空间;所以这段代码运行和观看视频将是在错误的色彩空间,但你仍然应该看到,在播放过程中视频挂起。

def get_video_frames(filename,noise_type=None,prob=None):

    all_frames = []
    video_capture = cv2.VideoCapture()
    if not video_capture.open(filename):
        print('Error: Cannot open video file {}'.format(filename))
        return

    fps = video_capture.get(cv2.CAP_PROP_FPS)
    print("fps: {}".format(fps))

    while True:
        has_frames,frame = video_capture.read()
        if not has_frames:
            video_capture.release()
            break
        if noise_type is None:
            frame = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
            frame = cv2.resize(frame,dsize=(224,224))

        elif noise_type == 'salt and pepper':
            frame = cv2.cvtColor(frame,224))
            row,col,ch = frame.shape
            s_vs_p = 0.5
        
            salty_x_coords = np.random.choice(frame.shape[0],np.int(np.ceil(frame.shape[0]*frame.shape[1]*prob*s_vs_p)))
            salty_y_coords = np.random.choice(frame.shape[1],np.int(np.ceil(frame.shape[0]*frame.shape[1]*prob*s_vs_p)))
        
            frame[salty_x_coords,salty_y_coords] = 255,255,255
        
            peppery_x_coords = np.random.choice(frame.shape[0],np.int(np.ceil(frame.shape[0]*frame.shape[1]*prob*s_vs_p)))
            peppery_y_coords = np.random.choice(frame.shape[1],np.int(np.ceil(frame.shape[0]*frame.shape[1]*prob*s_vs_p)))

            frame[peppery_x_coords,peppery_y_coords] = 0,0
            
        all_frames.append(frame)
    return all_frames,fps

问题自带的播放,它似乎。我生成干净的帧并使用 opencv 显示它们:

frames_clean,fps = get_video_frames('C:/some_video_file.mp4')
for f in frames_clean:
    cv2.imshow('clean',f)
    cv2.waitKey(33)
cv2.destroyAllWindows()

然后我产生嘈杂帧和使用的OpenCV显示它们:

frames_noisy,fps = get_video_frames('C:/some_video_file.mp4',noise_type='salt and pepper',prob=0.1)
for f in frames_noisy:
    cv2.imshow('noisy',f)
    cv2.waitKey(33)
cv2.destroyAllWindows()

嘈杂的视频在某些帧上挂起/暂停/断断续续。这真是不寻常,因为这两种frames_cleanframes_noisy形状相同的UINT8帧的名单。唯一的区别是噪声帧具有一些不同的像素值。如果我创建使用moviepy与这些框架列出了视频片段,将它们写入磁盘,并用VLC / Windows Media Player播放他们这种行为也存在。后在网上淘了2天,我找不到任何解释。我想喧闹的视频我产生发挥其作为一个看似稳定的显示率按清洁视频无噪音的预期。感谢您的帮助!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。