python opencv cv2.VideoCapture(),read(),waitKey()的使用 ret,frame参数
生活随笔
收集整理的這篇文章主要介紹了
python opencv cv2.VideoCapture(),read(),waitKey()的使用 ret,frame参数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
參考文章:python—OpenCV2中 cv2.VideoCapture(),read(),waitKey()的使用
VideoCapture.py
# encoding: utf-8 # module cv2.cv2 # from D:\Yolov3_Tensorflow\python\lib\site-packages\cv2\cv2.cp36-win_amd64.pyd # by generator 1.147 """ Python wrapper for OpenCV. """# imports import cv2.cv2 as # C:\Users\HuaWei\AppData\Local\Programs\Python\Python36\lib\site-packages\cv2\cv2.cp36-win_amd64.pyd import cv2.Error as Error # <module 'cv2.Error'> import cv2.cuda as cuda # <module 'cv2.cuda'> import cv2.detail as detail # <module 'cv2.detail'> import cv2.dnn as dnn # <module 'cv2.dnn'> import cv2.fisheye as fisheye # <module 'cv2.fisheye'> import cv2.flann as flann # <module 'cv2.flann'> import cv2.instr as instr # <module 'cv2.instr'> import cv2.ipp as ipp # <module 'cv2.ipp'> import cv2.ml as ml # <module 'cv2.ml'> import cv2.ocl as ocl # <module 'cv2.ocl'> import cv2.ogl as ogl # <module 'cv2.ogl'> import cv2.samples as samples # <module 'cv2.samples'> import cv2.utils as utils # <module 'cv2.utils'> import cv2.videoio_registry as videoio_registry # <module 'cv2.videoio_registry'> import cv2 as __cv2from .object import objectclass VideoCapture(object):# no docdef get(self, propId): # real signature unknown; restored from __doc__"""get(propId) -> retval(返回值). @brief Returns the specified VideoCapture property(返回指定的VideoCapture屬性). . @param propId Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...). or one from @ref videoio_flags_others(來自cv :: VideoCaptureProperties的屬性標識符(例如cv :: CAP_PROP_POS_MSEC,cv :: CAP_PROP_POS_FRAMES等)。或@ref videoio_flags_others中的一個). @return Value for the specified property. Value 0 is returned when querying a property that is. not supported by the backend used by the VideoCapture instance.(指定屬性的值。 查詢VideoCapture實例使用的后端不支持的屬性時,返回值0。). . @note Reading / writing properties involves many layers. Some unexpected result might happens. along this chain.(讀/寫屬性涉及許多層。 在此鏈上可能會發生一些意外的結果。). @code {.txt}. `VideoCapture -> API Backend -> Operating System -> Device Driver -> Device Hardware`(一連串的因素都可能導致出錯). @endcode. The returned value might be different from what really used by the device or it could be encoded. using device dependent rules (eg. steps or percentage). Effective behaviour depends from device. driver and API Backend(返回的值可能與設備實際使用的值不同,或者可以使用設備相關的規則(例如,步驟或百分比)對其進行編碼。 有效行為取決于設備驅動程序和API后端)"""passdef getBackendName(self): # real signature unknown; restored from __doc__"""getBackendName() -> retval. @brief Returns used backend API name(返回使用的后端API名稱). . @note Stream should be opened.(流應打開。)"""passdef grab(self): # real signature unknown; restored from __doc__"""grab() -> retval. @brief Grabs the next frame from video file or capturing device.(從視頻文件或捕獲設備中獲取下一幀。). . @return `true` (non-zero) in the case of success.(如果成功,則為“ true”(非零)). . The method/function grabs the next frame from video file or camera and returns true (non-zero) in. the case of success.(該方法/函數從視頻文件或攝像機中獲取下一幀,并在成功的情況下返回true(非零)。). . The primary use of the function is in multi-camera environments, especially when the cameras do not. have hardware synchronization. That is, you call VideoCapture::grab() for each camera and after that. call the slower method VideoCapture::retrieve() to decode and get frame from each camera. This way. the overhead on demosaicing or motion jpeg decompression etc. is eliminated and the retrieved frames. from different cameras will be closer in time.(該功能的主要用途是在多相機環境中,尤其是在相機沒有硬件同步的情況下。 也就是說,您為每個攝像機調用VideoCapture :: grab(),然后調用較慢的方法VideoCapture :: retrieve()解碼并從每個攝像機獲取幀。 這樣,消除了去馬賽克或運動jpeg壓縮等方面的開銷,并且從不同攝像機檢索到的幀將在時間上更近。). . Also, when a connected camera is multi-head (for example, a stereo camera or a Kinect device), the. correct way of retrieving data from it is to call VideoCapture::grab() first and then call. VideoCapture::retrieve() one or more times with different values of the channel parameter.(另外,當連接的攝像機是多頭攝像機(例如,立體攝像機或Kinect設備)時,從中檢索數據的正確方法是先調用VideoCapture :: grab(),然后再調用VideoCapture :: retrieve() 使用不同的channel參數值一次或多次。). . @ref tutorial_kinect_openni"""passdef isOpened(self): # real signature unknown; restored from __doc__"""isOpened() -> retval. @brief Returns true if video capturing has been initialized already.(如果視頻捕獲已經初始化,則返回true。). . If the previous call to VideoCapture constructor or VideoCapture::open() succeeded, the method returns. true.(如果先前對VideoCapture構造函數或VideoCapture :: open()的調用成功,則該方法返回true。)"""passdef open(self, filename, apiPreference=None): # real signature unknown; restored from __doc__"""open(filename[, apiPreference]) -> retval. @brief Opens a video file or a capturing device or an IP video stream for video capturing.(打開視頻文件或捕獲設備或IP視頻流以進行視頻捕獲。). . @overload. . Parameters are same as the constructor VideoCapture(const String& filename, int apiPreference = CAP_ANY)(參數與構造函數VideoCapture相同(常量字符串和文件名,int apiPreference = CAP_ANY)). @return `true` if the file has been successfully opened(如果文件已成功打開,則為true). . The method first calls VideoCapture::release to close the already opened file or camera.(該方法首先調用VideoCapture :: release以關閉已打開的文件或攝像機。)open(index[, apiPreference]) -> retval. @brief Opens a camera for video capturing(打開相機進行視頻拍攝). . @overload. . Parameters are same as the constructor VideoCapture(int index, int apiPreference = CAP_ANY)(與構造函數VideoCapture(int index,int apiPreference = CAP_ANY)相同). @return `true` if the camera has been successfully opened.(如果相機已成功打開,則為true。). . The method first calls VideoCapture::release to close the already opened file or camera.(該方法首先調用VideoCapture :: release以關閉已打開的文件或攝像機。)"""passdef read(self, image=None): # real signature unknown; restored from __doc__"""read([, image]) -> retval, image. @brief Grabs, decodes and returns the next video frame.(抓取,解碼并返回下一個視頻幀。). . @param [out] image the video frame is returned here. If no frames has been grabbed the image will be empty.([out]圖片視頻幀返回此處。 如果沒有抓取幀,圖像將為空。). @return `false` if no frames has been grabbed(如果沒有抓取任何幀,則為false). . The method/function combines VideoCapture::grab() and VideoCapture::retrieve() in one call. This is the. most convenient method for reading video files or capturing data from decode and returns the just. grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more. frames in video file), the method returns false and the function returns empty image (with %cv::Mat, test it with Mat::empty()).(該方法/函數在一次調用中將VideoCapture :: grab()和VideoCapture :: retrieve()組合在一起。 這是讀取視頻文件或從解碼中捕獲數據并返回剛抓取的幀的最便捷方法。 如果沒有抓取任何幀(相機已斷開連接,或者視頻文件中沒有其他幀),則該方法返回false,并且該函數返回空圖像(使用%cv :: Mat,使用Mat :: empty()對其進行測試 )。). . @note In @ref videoio_c "C API", functions cvRetrieveFrame() and cv.RetrieveFrame() return image stored inside the video. capturing structure. It is not allowed to modify or release the image! You can copy the frame using. cvCloneImage and then do whatever you want with the copy.(在@ref videoio_c“ C API”中,函數cvRetrieveFrame()和cv.RetrieveFrame()返回存儲在視頻捕獲結構內的圖像。 禁止修改或釋放圖像! 您可以使用cvCloneImage復制框架,然后對副本進行任何操作。)"""passdef release(self): # real signature unknown; restored from __doc__"""release() -> None. @brief Closes video file or capturing device.(關閉視頻文件或捕獲設備。). . The method is automatically called by subsequent VideoCapture::open and by VideoCapture. destructor.(該方法由隨后的VideoCapture :: open和VideoCapture析構函數自動調用。). . The C function also deallocates memory and clears \*capture pointer.(C函數還會取消分配內存并清除\ * capture指針。)"""passdef retrieve(self, image=None, flag=None): # real signature unknown; restored from __doc__"""retrieve([, image[, flag]]) -> retval, image. @brief Decodes and returns the grabbed video frame.(解碼并返回抓取的視頻幀。). . @param [out] image the video frame is returned here. If no frames has been grabbed the image will be empty.([out]圖片視頻幀返回此處。 如果沒有抓取幀,圖像將為空。). @param flag it could be a frame index or a driver specific flag(它可以是幀索引或驅動程序特定標志). @return `false` if no frames has been grabbed(如果沒有抓取任何幀,則為false). . The method decodes and returns the just grabbed frame. If no frames has been grabbed. (camera has been disconnected, or there are no more frames in video file), the method returns false. and the function returns an empty image (with %cv::Mat, test it with Mat::empty()).(該方法解碼并返回剛抓取的幀。 如果沒有抓取任何幀(相機已斷開連接,或者視頻文件中沒有其他幀),則該方法返回false,并且該函數返回空圖像(使用%cv :: Mat,使用Mat :: empty( ))。). . @sa read(). . @note In @ref videoio_c "C API", functions cvRetrieveFrame() and cv.RetrieveFrame() return image stored inside the video. capturing structure. It is not allowed to modify or release the image! You can copy the frame using. cvCloneImage and then do whatever you want with the copy.(在@ref videoio_c“ C API”中,函數cvRetrieveFrame()和cv.RetrieveFrame()返回存儲在視頻捕獲結構內的圖像。 禁止修改或發布圖像! 您可以使用cvCloneImage復制框架,然后對副本進行任何操作。)"""passdef set(self, propId, value): # real signature unknown; restored from __doc__"""set(propId, value) -> retval. @brief Sets a property in the VideoCapture.(在VideoCapture中設置屬性。). . @param propId Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...). or one from @ref videoio_flags_others(來自cv :: VideoCaptureProperties的屬性標識符(例如cv :: CAP_PROP_POS_MSEC,cv :: CAP_PROP_POS_FRAMES等)或@ref videoio_flags_others中的一個). @param value Value of the property.(屬性的值). @return `true` if the property is supported by backend used by the VideoCapture instance.(如果屬性由VideoCapture實例使用的后端支持,則為true。). @note Even if it returns `true` this doesn't ensure that the property. value has been accepted by the capture device. See note in VideoCapture::get()(即使返回“ true”,也不能確保捕獲設備已接受該屬性值。 請參閱VideoCapture :: get()中的注釋)"""passdef __init__(self, *args, **kwargs): # real signature unknownpass@staticmethod # known case of __new__def __new__(*args, **kwargs): # real signature unknown""" Create and return a new object. See help(type) for accurate signature. (創建并返回一個新對象。 請參閱help(type)以獲取準確的簽名。)"""passdef __repr__(self, *args, **kwargs): # real signature unknown""" Return repr(self). """pass總結
以上是生活随笔為你收集整理的python opencv cv2.VideoCapture(),read(),waitKey()的使用 ret,frame参数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python numba库是什么,如何给
- 下一篇: GitHub 如何删除 代码 仓库(re