OpenCV图像拍摄

连接工业相机,拍了几张照片!!
主要用到的函数接口:

1、CV_WRAP VideoCapture();
CV_WRAP VideoCapture(const string& filename);
CV_WRAP VideoCapture(int device);**

2、Mat imread( const string& filename, int flags=1 );

3、bool imwrite( const string& filename, InputArray img, const vector& params=vector());

代码如下:


#include "stdafx.h"
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <iostream>
#include <string>
using namespace std;
using namespace cv;

string inttostring(int number){
    stringstream ss;
    ss << number;
    return ss.str();
}

int _tmain(int argc, _TCHAR* argv[])
{
    VideoCapture cap(0);
    if (!cap.isOpened())
    {
        cout << "无法打开摄像头" << endl;
        system("pause");
        return -1;
    }

    char* windowName = "Picture demo";
    char filename[50];
    //文件名序号启示
    int n = 0;
    namedWindow(windowName, CV_WINDOW_AUTOSIZE);

    while (1)
    {
        Mat frame;//图像
        //从摄像头读取帧(frame)
        bool bSuccess = cap.read(frame);
        if (!bSuccess)//检查是否读取成功
        {
            cout << "无法从摄像头读取帧" << endl;
            break;
        }
        imshow(windowName, frame);
        //等待10ms是否按键
        switch (waitKey(10))
        {
        case 27://按下Esc 退出
            return 0;

            break;
        case 13://按下enter保存图片
            sprintf(filename, "D:\\pic\\process\\VideoFrame%d.jpg", n++);
            imwrite(filename, frame);
            break;
        }
    }
    system("pause");
    return 0;
}

这里写图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值