OpenCV 4.12.0
開源計算機視覺
載入中...
搜尋中...
無匹配項
cv::VideoCapture 類參考

用於從影片檔案、影像序列或攝像頭捕獲影片的類。更多...

#include <opencv2/videoio.hpp>

cv::VideoCapture 的協作圖

公共成員函式

 VideoCapture ()
 預設建構函式。
 
 VideoCapture (const Ptr< IStreamReader > &source, int apiPreference, const std::vector< int > &params)
 使用資料流開啟影片。
 
 VideoCapture (const String &filename, int apiPreference, const std::vector< int > &params)
 以API偏好和引數開啟影片檔案、捕獲裝置或IP影片流進行影片捕獲。
 
 VideoCapture (const String &filename, int apiPreference=CAP_ANY)
 以API偏好開啟影片檔案、捕獲裝置或IP影片流進行影片捕獲。
 
 VideoCapture (int index, int apiPreference, const std::vector< int > &params)
 以API偏好和引數開啟攝像頭進行影片捕獲。
 
 VideoCapture (int index, int apiPreference=CAP_ANY)
 開啟攝像頭進行影片捕獲。
 
virtual ~VideoCapture ()
 預設解構函式。
 
virtual double get (int propId) const
 返回指定的 VideoCapture 屬性。
 
String getBackendName () const
 返回使用的後端API名稱。
 
bool getExceptionMode () const
 查詢異常模式是否啟用
 
virtual bool grab ()
 從影片檔案或捕獲裝置捕獲下一幀。
 
virtual bool isOpened () const
 如果影片捕獲已初始化,則返回 true。
 
virtual bool open (const Ptr< IStreamReader > &source, int apiPreference, const std::vector< int > &params)
 使用資料流開啟影片。
 
virtual bool open (const String &filename, int apiPreference, const std::vector< int > &params)
 以API偏好和引數開啟影片檔案、捕獲裝置或IP影片流進行影片捕獲。
 
virtual bool open (const String &filename, int apiPreference=CAP_ANY)
 開啟影片檔案、捕獲裝置或IP影片流進行影片捕獲。
 
virtual bool open (int index, int apiPreference, const std::vector< int > &params)
 以API偏好和引數開啟攝像頭進行影片捕獲。
 
virtual bool open (int index, int apiPreference=CAP_ANY)
 開啟攝像頭進行影片捕獲。
 
virtual VideoCaptureoperator>> (Mat &image)
 用於讀取下一影片幀的流運算子。
 
virtual VideoCaptureoperator>> (UMat &image)
 
virtual bool OutputArray image)
 抓取、解碼並返回下一個影片幀。
 
virtual void release ()
 關閉影片檔案或捕獲裝置。
 
virtual bool retrieve (OutputArray image, int flag=0)
 解碼並返回捕獲的影片幀。
 
virtual bool set (int propId, double value)
 設定 VideoCapture 中的屬性。
 
void setExceptionMode (bool enable)
 

靜態公共成員函式

static bool waitAny (const std::vector< VideoCapture > &streams, std::vector< int > &readyIndex, int64 timeoutNs=0)
 等待來自 VideoCapture 的就緒幀。
 

保護屬性

Ptr< CvCapturecap
 
Ptr< IVideoCapture > icap
 
bool throwOnFail
 

友元

class internal::VideoCapturePrivateAccessor
 

詳細描述

用於從影片檔案、影像序列或攝像頭捕獲影片的類。

該類提供了C++ API,用於從攝像頭捕獲影片或讀取影片檔案和影像序列。

以下是該類的使用方法

#include <opencv2/core.hpp>
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
int main(int, char**)
{
Mat frame;
//--- 初始化影片捕獲物件
// 使用預設API開啟預設攝像頭
// cap.open(0);
// 或高階用法:選擇任意API後端
int deviceID = 0; // 0 = 開啟預設攝像頭
int apiID = cv::CAP_ANY; // 0 = 自動檢測預設API
// 使用選定的API開啟選定的攝像頭
cap.open(deviceID, apiID);
// 檢查是否成功開啟
if (!cap.isOpened()) {
cerr << "錯誤!無法開啟攝像頭\n";
return -1;
}
//--- 獲取和寫入迴圈
cout << "開始捕獲" << endl
<< "按任意鍵終止" << endl;
for (;;)
{
// 等待來自攝像頭的新幀並將其儲存到'frame'中
cap.read(frame);
// 檢查是否成功開啟
if (frame.empty()) {
cerr << "錯誤!捕獲到空白幀\n";
break;
}
// 顯示即時畫面並等待按鍵,超時時間足夠顯示影像
imshow("Live", frame);
if (waitKey(5) >= 0)
break;
}
// 攝像頭將在VideoCapture解構函式中自動去初始化
return 0;
}
n 維密集陣列類
定義 mat.hpp:830
cv::getTickFrequency
double getTickFrequency()
用於從影片檔案、影像序列或攝像頭捕獲影片的類。
Definition videoio.hpp:772
virtual bool read(OutputArray image)
抓取、解碼並返回下一個影片幀。
virtual bool open(const String &filename, int apiPreference=CAP_ANY)
開啟影片檔案、捕獲裝置或IP影片流進行影片捕獲。
virtual bool isOpened() const
如果影片捕獲已初始化,則返回 true。
@ CAP_ANY
自動檢測 == 0。
定義 videoio.hpp:96
int main(int argc, char *argv[])
定義 highgui_qt.cpp:3
定義 core.hpp:107
STL 名稱空間。
注意
C API 中,使用黑盒結構 CvCapture 而不是 VideoCapture。
  • (C++) 使用 VideoCapture 介面的基本示例可在 OPENCV_SOURCE_CODE/samples/cpp/videocapture_starter.cpp 中找到
  • (Python) 使用 VideoCapture 介面的基本示例可在 OPENCV_SOURCE_CODE/samples/python/video.py 中找到
  • (Python) 多執行緒影片處理示例可在 OPENCV_SOURCE_CODE/samples/python/video_threaded.py 中找到
  • (Python) 演示 Video4Linux2 後端某些功能的 VideoCapture 示例可在 OPENCV_SOURCE_CODE/samples/python/video_v4l2.py 中找到
示例
samples/cpp/camshiftdemo.cpp, samples/cpp/facedetect.cpp, samples/cpp/laplace.cpp, samples/cpp/lkdemo.cpp, samples/cpp/peopledetect.cpp, samples/cpp/polar_transforms.cpp, samples/cpp/segment_objects.cpp, samples/cpp/train_HOG.cpp, samples/cpp/tutorial_code/videoio/video-write/video-write.cpp, samples/cpp/videowriter_basic.cpp, samples/dnn/classification.cpp, samples/dnn/object_detection.cpp, samples/dnn/segmentation.cpp, samples/dnn/text_detection.cpp, and samples/tapi/hog.cpp

建構函式 & 解構函式文件

◆ VideoCapture() [1/6]

cv::VideoCapture::VideoCapture ( )
Python
cv.VideoCapture() -> <VideoCapture 物件>
cv.VideoCapture(filename[, apiPreference]) -> <VideoCapture 物件>
cv.VideoCapture(filename, apiPreference, params) -> <VideoCapture 物件>
cv.VideoCapture(index[, apiPreference]) -> <VideoCapture 物件>
cv.VideoCapture(index, apiPreference, params) -> <VideoCapture 物件>
cv.VideoCapture(source, apiPreference, params) -> <VideoCapture 物件>

預設建構函式。

注意
C API 中,當你完成影片處理後,使用 cvReleaseCapture() 釋放 CvCapture 結構,或使用 Ptr<CvCapture>,它會在解構函式中自動呼叫 cvReleaseCapture()。

◆ VideoCapture() [2/6]

cv::VideoCapture::VideoCapture ( const String & filename,
int apiPreference = CAP_ANY )
顯式
Python
cv.VideoCapture() -> <VideoCapture 物件>
cv.VideoCapture(filename[, apiPreference]) -> <VideoCapture 物件>
cv.VideoCapture(filename, apiPreference, params) -> <VideoCapture 物件>
cv.VideoCapture(index[, apiPreference]) -> <VideoCapture 物件>
cv.VideoCapture(index, apiPreference, params) -> <VideoCapture 物件>
cv.VideoCapture(source, apiPreference, params) -> <VideoCapture 物件>

以API偏好開啟影片檔案、捕獲裝置或IP影片流進行影片捕獲。

這是一個過載的成員函式,為方便起見而提供。它與上述函式的區別僅在於其接受的引數。

引數
filename它可以是
  • 影片檔名(例如 video.avi
  • 或影像序列(例如 img_%02d.jpg,這將讀取諸如 img_00.jpg, img_01.jpg, img_02.jpg, ... 的示例)
  • 或影片流的URL(例如 protocol://host:port/script_name?script_params|auth
  • 或GStreamer管道字串,如果GStreamer用作後端,則為gst-launch工具格式。請注意,每個影片流或IP攝像機源都有自己的URL方案。請參考源流的文件以瞭解正確的URL。
apiPreference首選的捕獲API後端。如果存在多個實現,可用於強制使用特定的讀取器實現:例如 cv::CAP_FFMPEGcv::CAP_IMAGEScv::CAP_DSHOW
另請參見
cv::VideoCaptureAPIs

◆ VideoCapture() [3/6]

cv::VideoCapture::VideoCapture ( const String & filename,
int apiPreference,
const std::vector< int > & params )
顯式
Python
cv.VideoCapture() -> <VideoCapture 物件>
cv.VideoCapture(filename[, apiPreference]) -> <VideoCapture 物件>
cv.VideoCapture(filename, apiPreference, params) -> <VideoCapture 物件>
cv.VideoCapture(index[, apiPreference]) -> <VideoCapture 物件>
cv.VideoCapture(index, apiPreference, params) -> <VideoCapture 物件>
cv.VideoCapture(source, apiPreference, params) -> <VideoCapture 物件>

以API偏好和引數開啟影片檔案、捕獲裝置或IP影片流進行影片捕獲。

這是一個過載的成員函式,為方便起見而提供。它與上述函式的區別僅在於其接受的引數。

params 引數允許指定額外引數,這些引數以對的形式編碼:(paramId_1, paramValue_1, paramId_2, paramValue_2, ...)。詳見 cv::VideoCaptureProperties

◆ VideoCapture() [4/6]

cv::VideoCapture::VideoCapture ( int index,
int apiPreference = CAP_ANY )
顯式
Python
cv.VideoCapture() -> <VideoCapture 物件>
cv.VideoCapture(filename[, apiPreference]) -> <VideoCapture 物件>
cv.VideoCapture(filename, apiPreference, params) -> <VideoCapture 物件>
cv.VideoCapture(index[, apiPreference]) -> <VideoCapture 物件>
cv.VideoCapture(index, apiPreference, params) -> <VideoCapture 物件>
cv.VideoCapture(source, apiPreference, params) -> <VideoCapture 物件>

開啟攝像頭進行影片捕獲。

這是一個過載的成員函式,為方便起見而提供。它與上述函式的區別僅在於其接受的引數。

引數
index要開啟的影片捕獲裝置的ID。要使用預設後端開啟預設攝像頭,只需傳遞0。(為了向後相容,當 apiPreference 為 CAP_ANY 時,使用 camera_id + domain_offset (CAP_*) 是有效的)
apiPreference首選的捕獲API後端。如果存在多個實現,可用於強制使用特定的讀取器實現:例如 cv::CAP_DSHOWcv::CAP_MSMFcv::CAP_V4L
另請參見
cv::VideoCaptureAPIs

◆ VideoCapture() [5/6]

cv::VideoCapture::VideoCapture ( int index,
int apiPreference,
const std::vector< int > & params )
顯式
Python
cv.VideoCapture() -> <VideoCapture 物件>
cv.VideoCapture(filename[, apiPreference]) -> <VideoCapture 物件>
cv.VideoCapture(filename, apiPreference, params) -> <VideoCapture 物件>
cv.VideoCapture(index[, apiPreference]) -> <VideoCapture 物件>
cv.VideoCapture(index, apiPreference, params) -> <VideoCapture 物件>
cv.VideoCapture(source, apiPreference, params) -> <VideoCapture 物件>

以API偏好和引數開啟攝像頭進行影片捕獲。

這是一個過載的成員函式,為方便起見而提供。它與上述函式的區別僅在於其接受的引數。

params 引數允許指定額外引數,這些引數以對的形式編碼:(paramId_1, paramValue_1, paramId_2, paramValue_2, ...)。詳見 cv::VideoCaptureProperties

◆ VideoCapture() [6/6]

cv::VideoCapture::VideoCapture ( const Ptr< IStreamReader > & source,
int apiPreference,
const std::vector< int > & params )
Python
cv.VideoCapture() -> <VideoCapture 物件>
cv.VideoCapture(filename[, apiPreference]) -> <VideoCapture 物件>
cv.VideoCapture(filename, apiPreference, params) -> <VideoCapture 物件>
cv.VideoCapture(index[, apiPreference]) -> <VideoCapture 物件>
cv.VideoCapture(index, apiPreference, params) -> <VideoCapture 物件>
cv.VideoCapture(source, apiPreference, params) -> <VideoCapture 物件>

使用資料流開啟影片。

這是一個過載的成員函式,為方便起見而提供。它與上述函式的區別僅在於其接受的引數。

params 引數允許指定額外引數,這些引數以對的形式編碼:(paramId_1, paramValue_1, paramId_2, paramValue_2, ...)。詳見 cv::VideoCaptureProperties

◆ ~VideoCapture()

virtual cv::VideoCapture::~VideoCapture ( )
virtual

預設解構函式。

該方法首先呼叫 VideoCapture::release 以關閉已開啟的檔案或攝像頭。

成員函式文件

◆ get()

virtual double cv::VideoCapture::get ( int propId) const
virtual
Python
cv.VideoCapture.get(propId) -> retval

返回指定的 VideoCapture 屬性。

引數
propId來自 cv::VideoCaptureProperties 的屬性識別符號(例如 cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...)或來自 影片I/O API後端附加標誌 之一。
返回
指定屬性的值。當查詢 VideoCapture 例項使用的後端不支援的屬性時,返回值為 0。
注意
讀/寫屬性涉及多個層。沿此鏈可能發生一些意外結果。
VideoCapture -> API 後端 -> 作業系統 -> 裝置驅動 -> 裝置硬體
返回的值可能與裝置實際使用的值不同,或者可能使用裝置相關的規則(例如,步進或百分比)進行編碼。實際行為取決於裝置驅動程式和API後端。
示例
samples/cpp/laplace.cpp.

◆ getBackendName()

String cv::VideoCapture::getBackendName ( ) const
Python
cv.VideoCapture.getBackendName() -> retval

返回使用的後端API名稱。

注意
流應已開啟。

◆ getExceptionMode()

bool cv::VideoCapture::getExceptionMode ( ) const
inline
Python
cv.VideoCapture.getExceptionMode() -> retval

查詢異常模式是否啟用

◆ grab()

virtual bool cv::VideoCapture::grab ( )
virtual
Python
cv.VideoCapture.grab() -> retval

從影片檔案或捕獲裝置捕獲下一幀。

返回
成功時為 true (非零)。

該方法/函式從影片檔案或攝像頭抓取下一幀,並在成功時返回 true(非零值)。

此函式主要用於多攝像頭環境,尤其是當攝像頭沒有硬體同步時。也就是說,您為每個攝像頭呼叫 VideoCapture::grab(),然後呼叫較慢的 VideoCapture::retrieve() 方法來解碼並從每個攝像頭獲取幀。透過這種方式,消除了去馬賽克或運動JPEG解壓縮等開銷,並且從不同攝像頭檢索到的幀在時間上會更接近。

此外,當連線的攝像頭是多頭的(例如,立體攝像頭或Kinect裝置)時,從其檢索資料的正確方法是首先呼叫 VideoCapture::grab(),然後以不同的通道引數值呼叫 VideoCapture::retrieve() 一次或多次。

使用 Kinect 和其他 OpenNI 相容的深度感測器

◆ isOpened()

virtual bool cv::VideoCapture::isOpened ( ) const
virtual
Python
cv.VideoCapture.isOpened() -> retval

◆ open() [1/5]

virtual bool cv::VideoCapture::open ( const Ptr< IStreamReader > & source,
int apiPreference,
const std::vector< int > & params )
virtual
Python
cv.VideoCapture.open(filename[, apiPreference]) -> retval
cv.VideoCapture.open(filename, apiPreference, params) -> retval
cv.VideoCapture.open(index[, apiPreference]) -> retval
cv.VideoCapture.open(index, apiPreference, params) -> retval
cv.VideoCapture.open(source, apiPreference, params) -> retval

使用資料流開啟影片。

這是一個過載的成員函式,為方便起見而提供。它與上述函式的區別僅在於其接受的引數。

params 引數允許指定額外引數,這些引數以對的形式編碼:(paramId_1, paramValue_1, paramId_2, paramValue_2, ...)。詳見 cv::VideoCaptureProperties

返回
如果檔案成功開啟則為 true

該方法首先呼叫 VideoCapture::release 以關閉已開啟的檔案或攝像頭。

◆ open() [2/5]

virtual bool cv::VideoCapture::open ( const String & filename,
int apiPreference,
const std::vector< int > & params )
virtual
Python
cv.VideoCapture.open(filename[, apiPreference]) -> retval
cv.VideoCapture.open(filename, apiPreference, params) -> retval
cv.VideoCapture.open(index[, apiPreference]) -> retval
cv.VideoCapture.open(index, apiPreference, params) -> retval
cv.VideoCapture.open(source, apiPreference, params) -> retval

以API偏好和引數開啟影片檔案、捕獲裝置或IP影片流進行影片捕獲。

這是一個過載的成員函式,為方便起見而提供。它與上述函式的區別僅在於其接受的引數。

params 引數允許指定額外引數,這些引數以對的形式編碼:(paramId_1, paramValue_1, paramId_2, paramValue_2, ...)。詳見 cv::VideoCaptureProperties

返回
如果檔案成功開啟則為 true

該方法首先呼叫 VideoCapture::release 以關閉已開啟的檔案或攝像頭。

◆ open() [3/5]

virtual bool cv::VideoCapture::open ( const String & filename,
int apiPreference = CAP_ANY )
virtual
Python
cv.VideoCapture.open(filename[, apiPreference]) -> retval
cv.VideoCapture.open(filename, apiPreference, params) -> retval
cv.VideoCapture.open(index[, apiPreference]) -> retval
cv.VideoCapture.open(index, apiPreference, params) -> retval
cv.VideoCapture.open(source, apiPreference, params) -> retval

開啟影片檔案、捕獲裝置或IP影片流進行影片捕獲。

這是一個過載的成員函式,為方便起見而提供。它與上述函式的區別僅在於其接受的引數。

引數與建構函式 VideoCapture(const String& filename, int apiPreference = CAP_ANY) 相同。

返回
如果檔案成功開啟則為 true

該方法首先呼叫 VideoCapture::release 以關閉已開啟的檔案或攝像頭。

示例
samples/cpp/camshiftdemo.cpp, samples/cpp/facedetect.cpp, samples/cpp/laplace.cpp, samples/cpp/lkdemo.cpp, samples/cpp/peopledetect.cpp, samples/cpp/polar_transforms.cpp, samples/cpp/segment_objects.cpp, samples/cpp/train_HOG.cpp, samples/dnn/classification.cpp, samples/dnn/object_detection.cpp, samples/dnn/segmentation.cpp, samples/dnn/text_detection.cpp, and samples/tapi/hog.cpp

◆ open() [4/5]

virtual bool cv::VideoCapture::open ( int index,
int apiPreference,
const std::vector< int > & params )
virtual
Python
cv.VideoCapture.open(filename[, apiPreference]) -> retval
cv.VideoCapture.open(filename, apiPreference, params) -> retval
cv.VideoCapture.open(index[, apiPreference]) -> retval
cv.VideoCapture.open(index, apiPreference, params) -> retval
cv.VideoCapture.open(source, apiPreference, params) -> retval

以API偏好和引數開啟攝像頭進行影片捕獲。

這是一個過載的成員函式,為方便起見而提供。它與上述函式的區別僅在於其接受的引數。

params 引數允許指定額外引數,這些引數以對的形式編碼:(paramId_1, paramValue_1, paramId_2, paramValue_2, ...)。詳見 cv::VideoCaptureProperties

返回
如果攝像頭成功開啟則為 true

該方法首先呼叫 VideoCapture::release 以關閉已開啟的檔案或攝像頭。

◆ open() [5/5]

virtual bool cv::VideoCapture::open ( int index,
int apiPreference = CAP_ANY )
virtual
Python
cv.VideoCapture.open(filename[, apiPreference]) -> retval
cv.VideoCapture.open(filename, apiPreference, params) -> retval
cv.VideoCapture.open(index[, apiPreference]) -> retval
cv.VideoCapture.open(index, apiPreference, params) -> retval
cv.VideoCapture.open(source, apiPreference, params) -> retval

開啟攝像頭進行影片捕獲。

這是一個過載的成員函式,為方便起見而提供。它與上述函式的區別僅在於其接受的引數。

引數與建構函式 VideoCapture(int index, int apiPreference = CAP_ANY) 相同。

返回
如果攝像頭成功開啟則為 true

該方法首先呼叫 VideoCapture::release 以關閉已開啟的檔案或攝像頭。

◆ operator>>() [1/2]

virtual VideoCapture & cv::VideoCapture::operator>> ( Mat & image)
virtual

用於讀取下一影片幀的流運算子。

另請參見
read()

◆ operator>>() [2/2]

virtual VideoCapture & cv::VideoCapture::operator>> ( UMat & image)
virtual

這是一個過載的成員函式,為方便起見而提供。它與上述函式的區別僅在於其接受的引數。

另請參見
read()

◆ read()

virtual bool cv::VideoCapture::read ( OutputArray image)
virtual
Python
cv.VideoCapture.read([, image]) -> 返回值, image

抓取、解碼並返回下一個影片幀。

引數
[輸出]image影片幀在此處返回。如果沒有抓取到幀,則影像將為空。
返回
如果沒有抓取到幀則為 false

該方法/函式將 VideoCapture::grab()VideoCapture::retrieve() 結合在一個呼叫中。這是讀取影片檔案或從解碼捕獲資料並返回剛抓取幀的最便捷方法。如果沒有抓取到幀(攝像頭已斷開連線,或影片檔案中沒有更多幀),該方法返回 false,並且函式返回空影像(對於 cv::Mat,可使用 Mat::empty() 進行測試)。

注意
C API 中,函式 cvRetrieveFrame() 和 cv.RetrieveFrame() 返回儲存在影片捕獲結構中的影像。不允許修改或釋放該影像!您可以使用 cvCloneImage 複製幀,然後對副本進行任何操作。
示例
samples/cpp/videowriter_basic.cpp.

◆ release()

virtual void cv::VideoCapture::release ( )
virtual
Python
cv.VideoCapture.release() ->

關閉影片檔案或捕獲裝置。

該方法由隨後的 VideoCapture::open 以及 VideoCapture 解構函式自動呼叫。

C函式還會解除分配記憶體並清除 *capture 指標。

◆ retrieve()

virtual bool cv::VideoCapture::retrieve ( OutputArray image,
int flag = 0 )
virtual
Python
cv.VideoCapture.retrieve([, image[, flag]]) -> 返回值, image

解碼並返回捕獲的影片幀。

引數
[輸出]image影片幀在此處返回。如果沒有抓取到幀,則影像將為空。
flag它可以是幀索引或驅動程式特定標誌
返回
如果沒有抓取到幀則為 false

該方法解碼並返回剛抓取的幀。如果沒有抓取到幀(攝像頭已斷開連線,或影片檔案中沒有更多幀),該方法返回 false,並且函式返回空影像(對於 cv::Mat,可使用 Mat::empty() 進行測試)。

另請參見
read()
注意
C API 中,函式 cvRetrieveFrame() 和 cv.RetrieveFrame() 返回儲存在影片捕獲結構中的影像。不允許修改或釋放該影像!您可以使用 cvCloneImage 複製幀,然後對副本進行任何操作。

◆ set()

virtual bool cv::VideoCapture::set ( int propId,
double  )
virtual
Python
cv.VideoCapture.set(propId, value) -> retval

設定 VideoCapture 中的屬性。

引數
propId來自 cv::VideoCaptureProperties 的屬性識別符號(例如 cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...)或來自 影片I/O API後端附加標誌 之一。
屬性的值。
返回
如果屬性受 VideoCapture 例項使用的後端支援,則為 true
注意
即使返回 true,這也不能保證屬性值已被捕獲裝置接受。請參閱 VideoCapture::get() 中的註釋。
示例
samples/cpp/laplace.cpp.

◆ setExceptionMode()

void cv::VideoCapture::setExceptionMode ( bool 啟用)
inline
Python
cv.VideoCapture.setExceptionMode(啟用) ->

切換異常模式

如果不成功,方法會丟擲異常而不是返回錯誤程式碼

◆ waitAny()

static bool cv::VideoCapture::waitAny ( const std::vector< VideoCapture > & streams,
std::vector< int > & readyIndex,
int64 timeoutNs = 0 )
static
Python
cv.VideoCapture.waitAny(streams[, timeoutNs]) -> retval, readyIndex
cv.VideoCapture_waitAny(streams[, timeoutNs]) -> retval, readyIndex

等待來自 VideoCapture 的就緒幀。

引數
streams輸入影片流
readyIndex具有已抓取幀的流索引(可使用 .retrieve() 獲取實際幀)
timeoutNs納秒數(0 - 無限)
返回
如果 streamReady 不為空則為 true
異常
Exception流錯誤時丟擲異常(檢查 .isOpened() 以過濾掉格式錯誤的流),或者 VideoCapture 型別不受支援

此函式主要用於多攝像頭環境。該方法填充就緒狀態向量,如果攝像頭就緒,則抓取影片幀。

此呼叫後,使用 VideoCapture::retrieve() 解碼並獲取幀資料。

友元和相關符號文件

◆ internal::VideoCapturePrivateAccessor

friend class internal::VideoCapturePrivateAccessor
friend

成員資料文件

◆ cap

Ptr<CvCapture> cv::VideoCapture::cap
保護

◆ icap

Ptr<IVideoCapture> cv::VideoCapture::icap
保護

◆ throwOnFail

bool cv::VideoCapture::throwOnFail
保護

本類的文件生成自以下檔案