Image Processing






Image Extraction



Extracting and Saving Video Frames using OpenCV-Python:

Follow the following steps to extract images from video. Here all extracted images will be saved in the current folder.

Steps:
  1.  Open the Video file or camera using cv2.VideoCapture()
  2.  Read frame by frame
  3.  Save each frame using cv2.imwrite()
  4.  Release the VideoCapture and destroy all windows
# Extraction of images from Video
import cv2
 
# Opens the Video file
cap= cv2.VideoCapture('canny.mp4')
i=0
while(cap.isOpened()):
    ret, frame = cap.read()
    if ret == False:
        break
    cv2.imwrite('kang'+str(i)+'.jpg',frame)
    i+=1
 
cap.release()
cv2.destroyAllWindows()

 

Output:

After running above code, all the the image from video will be stored in current folder.

 

Note: for above program, create new folder and save above program file in that folder then run your program. your folder will be full of images after running above code.