Giới thiệu
Camera mặc định: webcam tích hợp laptop, hoặc camera cổng USB đầu tiên trên desktop. Dùng VideoCapture(0).
Chương trình truy cập camera mặc định
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main() {
Mat myImage;
namedWindow("Video Player");
VideoCapture cap(0);
if (!cap.isOpened()) {
cout << "Không phát hiện luồng video" << endl;
system("pause"); return -1;
}
while (true) {
cap >> myImage;
if (myImage.empty()) break;
imshow("Video Player", myImage);
if (waitKey(25) == 27) break;
}
cap.release();
return 0;
}
Kết quả
Video real-time từ camera mặc định hiển thị trên màn hình.