如何解决从视频保存图像帧而不会损失分辨率和质量
我想保存从视频中提取的图像,而又不丢失任何信息,分辨率和质量。我已经使用OpenCV保存了四种格式png,bmp,jpg,tif
代码如下
file = "video.MP4"
video = cv2.VideoCapture(file)
# Find OpenCV version
(major_ver,minor_ver,subminor_ver) = (cv2.__version__).split('.')
# With webcam get(CV_CAP_PROP_FPS) does not work.
# Let's see for ourselves.
if int(major_ver) < 3 :
fps = video.get(cv2.cv.CV_CAP_PROP_FPS)
print ("Frames per second using video.get(cv2.cv.CV_CAP_PROP_FPS): {0}".format(fps))
else :
fps = video.get(cv2.CAP_PROP_FPS)
print ("Frames per second using video.get(cv2.CAP_PROP_FPS) : {0}".format(fps))
# Number of frames to capture
num_frames = 120;
print ("Capturing {0} frames".format(num_frames))
# Start time
start = time.time()
data = []
# Grab a few frames
for i in range(0,num_frames) :
ret,frame = video.read()
data.append(frame)
print("Shape",frame.shape)
# End time
end = time.time()
# Time elapsed
seconds = end - start
print ("Time taken : {0} seconds".format(seconds))
# Calculate frames per second
fps = num_frames / seconds;
print ("Estimated frames per second : {0}".format(fps))
for i,img in enumerate(data):
fileName = 'Frames\img_'+ str(i) + '.tif'
cv2.imwrite(fileName,img)
# Release video
video.release()
我的问题是
- 我应该保存哪种格式(
png,tif
),以免丢失视频的分辨率和质量。 - 仅将
.tif
之类的扩展名放入cv2.imwrite()
会将其保存为该特定格式吗? - 哪个图书馆最适合保存
OpenCV,scikit-image or Pillow
任何帮助或建议将不胜感激。
致谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。