OpenCV (开放源代码计算机视觉)是一个计算机视觉库,包含对图像或视频执行操作的各种功能。
null
OpenCV's application areas include :1) Facial recognition system2) motion tracking3) Artificial neural network4) Deep neural network5) video streaming etc.
在Python中,可以使用名为 CV2 .Python不随cv2提供,所以用户需要单独安装。
对于Windows:
pip install opencv-python对于Linux:
sudo apt-get install python-opencv
OpenCv库可用于对视频执行多种操作。让我们尝试使用 CV2 .将视频作为输入,以反向模式播放,方法是将视频逐帧分解,同时将该帧存储在列表中。在获得帧列表后,我们对帧执行迭代。为了在反转模式下播放视频,我们只需要在帧列表中迭代反转。使用列表的反转方法反转列表中帧的顺序。 以下是实施情况:
Python3
# Python program to play a video # in reverse mode using opencv # import cv2 library import cv2 # videoCapture method of cv2 return video object # Pass absolute address of video file cap = cv2.VideoCapture( "video_file_location" ) # read method of video object will return # a tuple with 1st element denotes whether # the frame was read successfully or not, # 2nd element is the actual frame. # Grab the current frame. check , vid = cap.read() # counter variable for # counting frames counter = 0 # Initialize the value # of check variable check = True frame_list = [] # If reached the end of the video # then we got False value of check. # keep looping until we # got False value of check. while (check = = True ): # imwrite method of cv2 saves the # image to the specified format. cv2.imwrite( "frame%d.jpg" % counter , vid) check , vid = cap.read() # Add each frame in the list by # using append method of the List frame_list.append(vid) # increment the counter by 1 counter + = 1 # last value in the frame_list is None # because when video reaches to the end # then false value store in check variable # and None value is store in vide variable. # removing the last value from the # frame_list by using pop method of List frame_list.pop() # looping in the List of frames. for frame in frame_list: # show the frame. cv2.imshow( "Frame" , frame) # waitkey method to stopping the frame # for some time. q key is presses, # stop the loop if cv2.waitKey( 25 ) and 0xFF = = ord ( "q" ): break # release method of video # object clean the input video cap.release() # close any open windows cv2.destroyAllWindows() # reverse the order of the element # present in the list by using # reverse method of the List. frame_list.reverse() for frame in frame_list: cv2.imshow( "Frame" , frame) if cv2.waitKey( 25 ) and 0xFF = = ord ( "q" ): break cap.release() cv2.destroyAllWindows() |
输出:
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END