我正在尝试读取存储在扩展名为.h5的文件中的视频,而不是将该视频存储在视频文件(.avi,.mp4)中。 我能够读取h5文件中的数据并在屏幕上显示视频。(cv2.imshow) 但无法在视频文件中写入数据。 我正在使用cv2.VideoWriter来编写视频。 我尝试使用不同的视频格式作为输入参数' VideoWriter'。它无效 这是我使用的代码:
fourcc = cv2.VideoWriter_fourcc(*format)
#File to be read
#It is a gray scale video of mouth region extraacted from a coloured video of full face
my_h5_file = 'Z:/sa.h5'
feature_name = 'sequence'
#to read the h5 file
with h5py.File(my_h5_file, 'r') as f:
#roi: contains the value or the video
roi = f[feature_name].value
#numframe 193 , y =36, x = 36
num_frames,y,x = roi.shape[:3]
print(num_frames)
print('y:',y,'x:',x)
#Using VideoWriter to write video in avi format
outvid = cv2.VideoWriter('Z:/output10.avi',fourcc,30,(x,y))
#to write the video frame by frame
for i in range (num_frames):
frame = roi[i,:]
f = np.squeeze(frame)
outvid.write(frame)
outvid.release()
显示此错误:
OpenCV Error: Assertion failed (image->depth == 8) in
CvVideoWriter_FFMPEG_proxy::writeFrame, file
C:\projects\opencv-python\opencv\modules\videoio\src\cap_ffmpeg.cpp,
line 274 Traceback (most recent call last): File
"Z:/VSR/pyVSR/display_roi_video.py", line 38, in <module>
outvid.write(frame) cv2.error: C:\projects\opencv-python\opencv\modules\videoio\src\cap_ffmpeg.cpp:274:
error: (-215) image->depth == 8 in function
CvVideoWriter_FFMPEG_proxy::writeFrame