电脑摄像头在opencv的运用

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

Mat ProcessImage(Mat source)
{
    Mat res;
    //把彩色图转换成灰度图//
    cvtColor(source, res, CV_BGR2GRAY);
    //模糊化//
    blur(res, res, Size(7, 7));
    //边缘化//
    Canny(res, res, 0, 30, 3);

    //高斯模糊//
    //GaussianBlur(source, res, Size(3,3),0,0,BORDER_DEFAULT);
    //灰度化//
    //cvtColor(res, res, CV_RGB2GRAY);
    //Sobel算子//
    //Sobel(res, res, CV_16S, 0, 1, 3, 1, 1, BORDER_DEFAULT);
    //convertScaleAbs(res, res);
    //二值化处理//
    threshold(res, res, 0, 255, CV_THRESH_OTSU + CV_THRESH_BINARY);
    //闭环处理//
    //morphologyEx(res, res, cv::MORPH_CLOSE, getStructuringElement(MORPH_RECT,
    //  Size(17, 5)));

    return res;
}

int main()
{
    //打开索引为0的系统摄像头//
    VideoCapture capture(0);

    //检测摄像头是否打开//
    if (!capture.isOpened())
    {
        cout << "No open..." << endl;
        return -1;
    }

    //定义结果集//
    Mat resultMat;

    //每隔30ms获取一次图片数据//
    while (1)
    {
        //获取一帧的图片数据集//
        Mat frame;
        capture >> frame;
        //检测数据集是否为空//
        if (frame.empty())
        {
            cout << "No frame..." << endl;
        }
        else
        {
            //对图片数据集进行处理//
            resultMat = ProcessImage(frame);

            //显示处理后的图片//
            imshow("result", resultMat);

            //显示原图//
            imshow("source", frame);
        }
        waitKey(30);
    }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值