“matplotlib.image”加载的图像与使用“fl\u image”从视频中提取的图像之间存在差异`

2024-10-02 20:40:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Python cv2包处理视频帧(mp4)。对于图像处理,我使用moviepy.editor.VideoFileClip的方法fl_image。但是,当我以jpg格式保存提取的帧,然后使用matplotlib.image重新打开它时,加载的图像中有一个小的差异。这两种方法只需取加载图像的平均值即可看出

我想知道为什么两个加载的图像略有不同。这在逐帧处理视频剪辑时造成了一些问题

sampleImage = mpimg.imread("sample-01.jpg")
print("sampleImage", np.mean(sampleImage))

# sampleImage is extracted from the video, say the last frame of the subClip1, and already saved using method imsave

# result
# sampleImage 115.64719075520833

# using the other method 

def processFrameImage(image):
    print("sampleImage", np.mean(image))

    result = extractFeatures(image)

    return result 

clip1 = VideoFileClip("sample-video.mp4")
subClip1 = clip1.subclip(t_start=0.0, t_end=0.1)
whiteClip = subClip1.fl_image(processFrameImage)

# result 
# sampleImage 115.64437065972223

请注意上述打印结果之间的差异


Tags: thesample方法图像imagenp差异result