- 一开始是用IplImage类型去获取摄像头图像,不管内置摄像头还是USB摄像头,一直读出黑屏。
- 百度说用DirectShow,到底也没弄出个所以然。
- 最后看到有人说使用Mat类,结果能从USB摄像头读出彩色图像,但是笔记本内置摄像头还是读出黑屏。
- 不清楚原因。
以下是测试时使用的C++代码:
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
int main() {
VideoCapture capture(0);
if (!capture.isOpened())
return -1;
Mat frame;
while (1) {
capture >> frame;
imshow("读取视频", frame);
waitKey(30);//给图像绘制留点时间
}
return 0;
}