opencv:摄像头和视频的读取

示例代码:

#include <opencv.hpp>
using namespace cv;
int main()
{
    VideoCapture Capture(0); //打开默认摄像头0
    // VideoCapture Capture("xxx.mp4"); // 读取视频的路径
    while(1)
    {
        Mat frame;
        Capture >> frame; // 获取每一帧
        imshow("显示",frame);  // 显示每一帧
        waitKey(30); // 等待 可以控制速度
    }
    return 0;
}

 使用python:

import cv2

cap = cv2.VideoCapture(0)
while(1):
    ret,frame = cap.read()
    cv2.imshow("cap",frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cv2.destroyAllWindows()
cap.release()

 

  

posted @ 2017-02-27 23:00  whlook  阅读(356)  评论(0编辑  收藏  举报