In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how opencv can call the camera and display, read the video file and display, save the video and so on. The editor finds it very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Call the camera and display the video:
Import numpy as npimport cv2 as cv# cap = cv.VideoCapture (- 1) # cap = cv.VideoCapture (1) cap = cv.VideoCapture (0) # pass in a device index that represents different cameras Or pass in a video file name # cap = cv.VideoCapture ('testVideo.mp4') if not cap.isOpened (): print ("Cannot open camera") exit () width = cap.get (cv.CAP_PROP_FRAME_WIDTH) height = cap.get (cv.CAP_PROP_FRAME_HEIGHT) print (' width and height are:', width, height) # width and height are: 640.0 480.0ret = cap.set (cv.CAP_PROP_FRAME_WIDTH) Set width ret = cap.set (cv.CAP_PROP_FRAME_HEIGHT,240) # set height while True:# Capture frame-by-frameret, frame = cap.read () # returns True or False, if read correctly is True, you can use False to determine whether to reach the end of the video # if frame is read correctly ret is Trueif not ret:print ("Can't receive frame (stream end?). Exiting... ") break# Our operations on the frame come heregray = cv.cvtColor (frame, cv.COLOR_BGR2GRAY) # Display the resulting framecv.imshow ('LinMaZi-frame-LinZuQuan', gray) # set the display window title text if cv.waitKey (1) = = ord (' q'): # determine whether the user enters the Q key break# When everything done, release the capturecap.release () # release resource cv.destroyAllWindows ()
Read the video file and display:
Import numpy as npimport cv2 as cvcap = cv.VideoCapture ('graduation party .MP4') # cap = cv.VideoCapture (0) while cap.isOpened (): ret, frame = cap.read () # if frame is read correctly ret is Trueif not ret:print ("Can't receive frame (stream end?). Exiting. ") breakgray = cv.cvtColor (frame, cv.COLOR_BGR2GRAY) cv.imshow ('frame', gray) if cv.waitKey (25) = = ord (' q'): # choose the appropriate refresh interval, 25 milliseconds is not bad breakcap.release () cv.destroyAllWindows ()
Call the camera and display it, save it as a video file:
Import numpy as npimport cv2 as cvimport timecap = cv.VideoCapture (0) # Define the codec and create VideoWriter objectfourcc = cv.VideoWriter_fourcc (* 'XVID') # both are equivalent # fourcc = cv.VideoWriter_fourcc ("% Yy-%mm-%dd@%Hh%Mm%Ss", time.localtime ()) out = cv.VideoWriter (' output_' + saveTime + '.mp4', fourcc, 20.0,640) Parameter output file name, FourCC code, frames per second (fps), frame sizewhile cap.isOpened (): ret, frame = cap.read () if not ret:print ("Can't receive frame (stream end?). Exiting. ") break# frame = cv.flip (frame, 1) # left and right horizontal flip frame = cv.flip (frame, 0) # up and down vertical flip # write the flipped frameout.write (frame) cv.imshow ('LinMaZi-frame-LinZuQuan', frame) if cv.waitKey (1) = ord (' q'): break# Release everything if job is finishedcap.release () out.release () cv.destroyAllWindows () about" opencv how to call the camera and display Read the video file and display, save the video and other operations. "this article ends here." Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.
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.