cv::VideoCapture capture
时间: 2023-12-25 17:53:49 浏览: 83
cv::VideoCapture capture is a variable declaration in OpenCV C++ that creates an instance of the VideoCapture class. This variable is used to capture video frames from a video file or a camera device. The constructor of the VideoCapture class initializes the video stream and sets the video source.
To use this variable, you can call its member functions to access video frames, retrieve information about the video stream, and control the video stream playback. For example, you can use the read() function to read the next video frame and store it in a cv::Mat object, or use the set() function to set the video capture properties like the frame size, frame rate, and brightness.
Here is an example of how to use the capture variable to read video frames from a camera device:
```
#include <opencv2/opencv.hpp>
using namespace cv;
int main() {
// Create a VideoCapture object for the camera device
VideoCapture capture(0);
// Check if the camera device is opened successfully
if (!capture.isOpened()) {
std::cerr << "Failed to open camera device" << std::endl;
return -1;
}
// Loop to capture and display video frames
while (true) {
// Read the next video frame
Mat frame;
capture.read(frame);
// Check if the frame is empty
if (frame.empty()) {
std::cerr << "Failed to capture frame" << std::endl;
break;
}
// Display the frame
imshow("Video frame", frame);
// Wait for 30 milliseconds and check if the user pressed a key
if (waitKey(30) >= 0) {
break;
}
}
// Release the camera device and destroy the window
capture.release();
destroyAllWindows();
return 0;
}
```
阅读全文