OPENCV——VS2015打开摄像头时一片灰色

行者yxq 2016-12-29 08:25:37
#include <opencv2/opencv.hpp>  
#include <iostream>
using namespace cv;
using namespace std;

string name = "我的";

int main()
{
VideoCapture capture; //声明视频读入类
capture.open(0); //从摄像头读入视频 0表示从摄像头读入

if (!capture.isOpened()) //先判断是否打开摄像头
{
cout << "can not open";
cin.get();
return -1;
}

namedWindow(name);

while (1) {
Mat cap; //定义一个Mat变量,用于存储每一帧的图像
capture >> cap; //读取当前帧
if (!cap.empty()) //判断当前帧是否捕捉成功 **这步很重要
imshow(name, cap); //若当前帧捕捉成功,显示
else
cout << "can not ";
waitKey(30); //延时30毫秒
}

return 0;
}


...全文
1103 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
银点 2016-12-30
  • 打赏
  • 举报
回复


#include "cv.h"
#include "highgui.h"

int main(int argc, char** argv) {
    cvNamedWindow("OpenCVideoWindows");

    CvCapture* capture = cvCreateCameraCapture(0);
    IplImage* frame;

    while(1) {
        frame = cvQueryFrame(capture);
        if(!frame) break;
        cvShowImage("OpenCVideoWindows", frame);

        char c = cvWaitKey(30);
        if(c==27) break;
    }

    cvReleaseCapture(&capture);
    cvDestroyWindow("OpenCVideoWindows");
    return 0;
}

银点 2016-12-30
  • 打赏
  • 举报
回复

#include "cv.h"
#include "highgui.h"

int main(int argc, char** argv) {
    cvNamedWindow("OpenCVideoWindows");

    CvCapture* capture = cvCreateCameraCapture(0);
    IplImage* frame;

    while(1) {
        frame = cvQueryFrame(capture);
        if(!frame) break;
        cvShowImage("win", frame);

        char c = cvWaitKey(50);
        if(c==27) break;
    }

    cvReleaseCapture(&capture);
    cvDestroyWindow("OpenCVideoWindows");
    return 0;
}

1,222

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧