In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "how to use python opencv library to play video frame rate", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use python opencv library to play video frame rate" article.
Demand background
In many cases, we need to extract a certain frame of the video for some analysis or modification; for example, the author needs to judge the frequency of a person appearing in the video to determine whether he is the protagonist of the video.
About opencv
OpenCV is the Intel open source computer visual library (Computer Version). It consists of a series of C functions and a small number of C++ classes, and implements many general algorithms in image processing and computer vision.
OpenCV has a cross-platform middle and high-level API that includes more than 300 C functions. It does not depend on other external libraries-although some external libraries can also be used. OpenCV is free for both non-commercial and commercial applications
. At the same time, OpenCV provides access to hardware and direct access to the camera, and opencv also provides a simple GUI (graphics user interface) system: highgui. We use some methods provided by OpenCV to construct this face detection (face detection) program.
Install opencv
Pip install opencv-python
Use opencv to intercept video frames at regular intervals and save them as pictures.
This example uses python programming:
Code:
#-*-coding:utf8-*-import cv2import osimport shutildef VideoExtract (filename Count=600):'': param filename: video file path: param count: frame rate interval for saving pictures: return:''# path to save pictures savedpath = filename.split ('.) [0] +'/ 'isExists = os.path.exists (savedpath) if not isExists: os.makedirs (savedpath) print (' path of% s is build') % (savedpath) else: shutil.rmtree (savedpath) os.makedirs (savedpath) print ('path of% s already exist and rebuild'% (savedpath)) # start reading video videoCapture = cv2.VideoCapture (filename) I = 0 j = 0 while True: success Frame = videoCapture.read () I + = 1 if (I% count = = 0): # Save picture j + = 1 savedname = filename.split ('.') [0] +'_'+ str (j) +'_'+ str (I) + '.jpg' cv2.imwrite (savedpath + savedname) Frame) print ('image of% s is saved'% (savedname)) if not success: break
After running, a lot of pictures will be written in the generated picture folder, which is the picture we just pulled out of each count frame.
According to the drawing frame, the protagonist of the video should be TRUMP.
Of course, some video attributes should be judged before frame extraction, such as video duration, video size and so on.
Cap = cv2.VideoCapture (video_name) # frame rate fps = int (round (cap.get (cv2.CAP_PROP_FPS) # Resolution-width width = int (cap.get (cv2.CAP_PROP_FRAME_WIDTH)) # Resolution-height height = int (cap.get (cv2.CAP_PROP_FRAME_HEIGHT)) # Total frames frame_counter = int (cap.get (cv2.CAP_PROP_FRAME_COUNT) cap.release () cv2.destroyAllWindows () # duration Unit sduration = frame_counter / fpsopencv-python to obtain video related information
The following is the information that opencv-python can obtain about the video, which can be obtained through the sequence number starting with 0.
The current location of the CV_CAP_PROP_POS_MSEC video file in milliseconds or the video capture timestamp.
The 0-based index of the next frame to be decoded / captured by CV_CAP_PROP_POS_FRAMES.
Relative position of the CV_CAP_PROP_POS_AVI_RATIO video file: 0-the beginning of the movie, 1-the end of the movie.
The width of the frame in the CV_CAP_PROP_FRAME_WIDTH video stream.
The height of the frame in the CV_CAP_PROP_FRAME_HEIGHT video stream.
CV_CAP_PROP_FPS frame rate.
The 4 character code of the CV_CAP_PROP_FOURCC codec.
The number of frames in the CV_CAP_PROP_FRAME_COUNT video file.
The format retrieve () of the Mat object returned by CV_CAP_PROP_FORMAT.
CV_CAP_PROP_MODE indicates the backend-specific value of the current capture mode.
The brightness of the CV_CAP_PROP_BRIGHTNESS image (for cameras only).
CV_CAP_PROP_CONTRAST image contrast (for cameras only).
The saturation of the CV_CAP_PROP_SATURATION image (cameras only).
The hue of the CV_CAP_PROP_HUE image (for cameras only).
The gain of the CV_CAP_PROP_GAIN image (for cameras only).
CV_CAP_PROP_EXPOSURE exposure (for cameras only).
The CV_CAP_PROP_CONVERT_RGB Boolean flag indicating whether the image should be converted to RGB.
U value of CV_CAP_PROP_WHITE_BALANCE_U white balance setting (Note: only DC1394 v 2.x backend is currently supported)
V value of CV_CAP_PROP_WHITE_BALANCE_V white balance setting (Note: only DC1394 v 2.x backend is currently supported)
CV_CAP_PROP_RECTIFICATION stereo camera rectification logo (Note: only DC1394 v 2.x backend is currently supported)
ISO speed of CV_CAP_PROP_ISO_SPEED camera (Note: only DC1394 v 2.x backend is currently supported)
The number of frames CV_CAP_PROP_BUFFERSIZE stores in the internal buffer memory (Note: currently only DC1394 v 2.x backend is supported)
The above is about the content of this article on "how to use the python opencv library to transfer video frame rate". I believe you all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to learn more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.