Ask Your Question

Image frame saving from Video without losing resolution and quality

asked 2020-10-02 02:40:30 -0500

Imran Hassan gravatar image

I want to save the images extracted from the video without losing any information, resolution and quality. I have saved using OpenCV in four formats png, bmp, jpg, tif The code is as below

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(
    print ("Frames per second using video.get( {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 =
# 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'
# Release video

My Questions are

  1. In which of the format (png, bmp, jpg, tif) I should save so that it should not lose the resolution and quality of video.

  2. Just putting extension like .tif in cv2.imwrite() saves it to that particular format?

  3. Which library is the best to save OpenCV, scikit-image or Pillow

Any help or suggestion will be highly appreciated.


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2020-10-02 04:10:49 -0500

berak gravatar image
  1. png and bmp are lossless (and saving an image does not change its resolution, anyway)
  2. yes, it's that simple
  3. entirely up to you. just keep in mind, that different libraries use different conventions (like bgr / rgb pixel order)
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2020-10-02 02:39:38 -0500

Seen: 1,797 times

Last updated: Oct 02 '20