OpenCV comes with many powerful video editing functions. In current scenario, techniques such as image scanning, face recognition can be accomplished using OpenCV.
Image Analysis is a very common field in the area of Computer Vision. It is the extraction of meaningful information from videos or images. OpenCv library can be used to perform multiple operations on videos.
Modules Needed:
import cv2
import os
Function Used :
VideoCapture(File_path) : Read the video(.mp4 format)
read() : Read data depending upon the type of object that calls
imwrite(filename, img[, params]) : Saves an image to a specified file.
Below is the implementation:
import cv2
import os
cam = cv2.VideoCapture( "C:\\Users\\Admin\\PycharmProjects\\project_1\\openCV.mp4" )
try :
if not os.path.exists( 'data' ):
os.makedirs( 'data' )
except OSError:
print ( 'Error: Creating directory of data' )
currentframe = 0
while ( True ):
ret,frame = cam.read()
if ret:
name = './data/frame' + str (currentframe) + '.jpg'
print ( 'Creating...' + name)
cv2.imwrite(name, frame)
currentframe + = 1
else :
break
cam.release()
cv2.destroyAllWindows()
|
Output:

All the extracted images will be saved in a folder named “data” on the system.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
04 Jan, 2023
Like Article
Save Article