用於從影片檔案、影像序列或攝像頭捕獲影片的類。更多...
#include <opencv2/videoio.hpp>
|
| | VideoCapture () |
| | 預設建構函式。
|
| |
| | VideoCapture (const Ptr< IStreamReader > &source, int apiPreference, const std::vector< int > ¶ms) |
| | 使用資料流開啟影片。
|
| |
| | VideoCapture (const String &filename, int apiPreference, const std::vector< int > ¶ms) |
| | 以API偏好和引數開啟影片檔案、捕獲裝置或IP影片流進行影片捕獲。
|
| |
| | VideoCapture (const String &filename, int apiPreference=CAP_ANY) |
| | 以API偏好開啟影片檔案、捕獲裝置或IP影片流進行影片捕獲。
|
| |
| | VideoCapture (int index, int apiPreference, const std::vector< int > ¶ms) |
| | 以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 > ¶ms) |
| | 使用資料流開啟影片。
|
| |
| virtual bool | open (const String &filename, int apiPreference, const std::vector< int > ¶ms) |
| | 以API偏好和引數開啟影片檔案、捕獲裝置或IP影片流進行影片捕獲。
|
| |
| virtual bool | open (const String &filename, int apiPreference=CAP_ANY) |
| | 開啟影片檔案、捕獲裝置或IP影片流進行影片捕獲。
|
| |
| virtual bool | open (int index, int apiPreference, const std::vector< int > ¶ms) |
| | 以API偏好和引數開啟攝像頭進行影片捕獲。
|
| |
| virtual bool | open (int index, int apiPreference=CAP_ANY) |
| | 開啟攝像頭進行影片捕獲。
|
| |
| virtual VideoCapture & | operator>> (Mat &image) |
| | 用於讀取下一影片幀的流運算子。
|
| |
| virtual VideoCapture & | operator>> (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) |
| |
用於從影片檔案、影像序列或攝像頭捕獲影片的類。
該類提供了C++ API,用於從攝像頭捕獲影片或讀取影片檔案和影像序列。
以下是該類的使用方法
#include <iostream>
#include <stdio.h>
{
int deviceID = 0;
cap.
open(deviceID, apiID);
cerr << "錯誤!無法開啟攝像頭\n";
return -1;
}
cout << "開始捕獲" << endl
<< "按任意鍵終止" << endl;
for (;;)
{
cerr << "錯誤!捕獲到空白幀\n";
break;
}
imshow("Live", frame);
if (waitKey(5) >= 0)
break;
}
return 0;
}
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
- 注意
- 在 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_FFMPEG 或 cv::CAP_IMAGES 或 cv::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_DSHOW 或 cv::CAP_MSMF 或 cv::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 |
◆ get()
| virtual double cv::VideoCapture::get |
( |
int | propId | ) |
const |
|
virtual |
| Python |
|---|
| cv.VideoCapture.get( | propId | ) -> | retval |
◆ getBackendName()
| String cv::VideoCapture::getBackendName |
( |
| ) |
const |
| Python |
|---|
| cv.VideoCapture.getBackendName( | | ) -> | retval |
◆ getExceptionMode()
| bool cv::VideoCapture::getExceptionMode |
( |
| ) |
const |
|
inline |
| Python |
|---|
| cv.VideoCapture.getExceptionMode( | | ) -> | retval |
◆ grab()
| virtual bool cv::VideoCapture::grab |
( |
| ) |
|
|
virtual |
| Python |
|---|
| cv.VideoCapture.grab( | | ) -> | retval |
◆ 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 |
◆ 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]
◆ operator>>() [2/2]
這是一個過載的成員函式,為方便起見而提供。它與上述函式的區別僅在於其接受的引數。
- 另請參見
- read()
◆ read()
| virtual bool cv::VideoCapture::read |
( |
OutputArray | image | ) |
|
|
virtual |
| Python |
|---|
| cv.VideoCapture.read( | [, image] | ) -> | 返回值, image |
◆ release()
| virtual void cv::VideoCapture::release |
( |
| ) |
|
|
virtual |
| Python |
|---|
| cv.VideoCapture.release( | | ) -> | 無 |
◆ 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 |
◆ 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 |
◆ internal::VideoCapturePrivateAccessor
| friend class internal::VideoCapturePrivateAccessor |
|
friend |
◆ cap
◆ icap
| Ptr<IVideoCapture> cv::VideoCapture::icap |
|
保護 |
◆ throwOnFail
| bool cv::VideoCapture::throwOnFail |
|
保護 |
本類的文件生成自以下檔案