从(大恒)工业相机读取图片

采用大恒MER系列工业摄像机,不能用opencv自带函数打开摄像头,需要用厂商提供的API
定义控制台应用程序的入口点。

#include "stdafx.h"
#include "core/core.hpp"  
#include <opencv2/imgproc/imgproc.hpp&gt;  
#include <opencv2/highgui/highgui.hpp>  
#include <set>
#include<stdio.h>

#include <opencv2/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/videoio.hpp>//for camera
#include <opencv2/video.hpp>
#include <opencv2/imgPRoc//imgproc.hpp>
#include <opencv2/ml/ml.hpp>

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/ml/ml.hpp"
#include <time.h>
#include <ctime>
#include <iostream>
#include <string>
using namespace std;
using namespace cv;

//一般的情况是不支持使用命名空间的

int main(int argc, char ** argv)
{
    char filename[1024];
    if (argc == 1)
        sprintf(filename, "%s", "camera1.avi");
    if (argc == 2)
        sprintf(filename, "%s", "123");


    VideoCapture capture;
    capture.open(0);
    if (!capture.isOpened())
    {
        cout << "Could not initialize capturing...\n" << endl;
        return -1;
    }

    //按时间格式命名
    time_t now = time(nullprt);获取1970.1.1至当前秒数time_t
    struct tm * timeinfo = localtime(&now); //创建TimeDate,并转化为当地时间,
                                            //struct tm * timeinfo = gmtime ( &currTime );   //创建TimeDate,并转化为GM时间,
    char path[60];
    strftime(path, 60, "%Y_%m_%d_%H_%M_%S", timeinfo);
    char strPath[100];
    sprintf(strPath, "%s.avi", path);//将创建文件的命令存入cmdchar中

                                     //保存为avi格式视频
    Mat frame;
    VideoWriter writer;
    writer.open(strPath, CV_FOURCC('X', 'V', 'I', 'D'), 25, Size(640, 480), true);//Size(640, 480)//Size(frame.rows, frame.cols)//"cam.avi"

    int n = 1;
    while (true)
    {
        capture >> frame;
        char* cstr = new char[120];

    //  sprintf(cstr, "%s%d%s", "/home/caros/Documents/../", n++, ".jpg");

        sprintf(cstr, "%s%d%s", "/home/baidu/Doc/shipin_capture", n++, ".jpg");

        imwrite(cstr, frame);

        imshow("Video_Capture", frame);
        if (frame.empty())
        {
            break;
        }
        writer << frame;
        waitKey(3);

    }

    //return 0;
}
  • 0
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值