zoukankan      html  css  js  c++  java
  • opencv

    第一个opencv,显示图片

    #include<iostream>
    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    using namespace cv;
    int main()
    {
    // 读入一张图片(游戏原画)
    Mat img = imread("E://3.jpg");
    // 在窗口中显示游戏原画
    imshow("游戏原画", img);
    // 等待6000 ms后窗口自动关闭
    waitKey(6000);
    }

    第二个opencv,图片腐蚀

    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/imgproc/imgproc.hpp>
    using namespace cv;

    int main()
    {
    //载入原图
    Mat srcImage = imread("E://3.jpg");
    //显示原图
    imshow("原图腐蚀操作",srcImage);
    //腐蚀操作
    Mat element = getStructuringElement(MORPH_RECT, Size(15, 15));
    Mat dstImage;
    erode(srcImage, dstImage, element);
    //显示图片效果
    imshow("效果图腐蚀操作", dstImage);
    waitKey(0);
    }

    第三个opencv,图像模糊

    #include <opencv2/core/core.hpp> 
    #include <opencv2/highgui/highgui.hpp> 
    #include <opencv2/imgproc/imgproc.hpp>
    using namespace cv;
    int main()
    {
    //载入图片
    Mat srcImage = imread("E://3.jpg");
    //显示原始图片
    imshow("原图", srcImage);
    //进行均值滤波操作
    Mat dstImage;
    blur(srcImage, dstImage, Size(7, 7));
    //显示效果图
    imshow("效果图", dstImage);
    waitKey(0);
    }

    第四个opencv,canny边缘检测

    #include <opencv2/core/core.hpp> 
    #include <opencv2/highgui/highgui.hpp> 
    #include <opencv2/imgproc/imgproc.hpp>
    using namespace cv;

    int main()
    {
    //载入图片
    Mat srcImage = imread("E://3.jpg");
    //显示原图
    imshow("原图",srcImage);
    //参数定义
    Mat edge, grayImage;
    //【1】将原图转换为灰度图像
    cvtColor(srcImage, grayImage, CV_BGR2GRAY);
    //【2】先使用3*3内核来降噪
    blur(grayImage, edge, Size(3, 3));
    //【3】运行canny算子
    Canny(edge,edge,3,9,3);
    //显示效果图
    imshow("效果图", edge);
    waitKey(0);
    return 0;
    }

    opencv读取播放视频

    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/imgproc/imgproc.hpp>
    using namespace cv;

    int main()
    {
    //【1】读入视频
    VideoCapture capture("E://video1.mp4");
    //【2】循环显示每一帧
    while (1)
    {
    Mat frame;//定义变量
    capture >> frame;//读取当前帧

    //若视频播放完成,退出循环
    if (frame.empty())
    {
    break;
    }
    imshow("读视频", frame);//显示当前帧
    waitKey(30);//延时30ms
    }
    return 0;
    }

    调用摄像头采集图像

    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/imgproc/imgproc.hpp>
    using namespace cv;

    int main()
    {
    //【1】从摄像头读入视频
    VideoCapture capture(0);
    //【2】循环显示每一帧
    while (1)
    {
    Mat frame;//定义一个Mat变量,用于存储每一帧的图像
    capture >> frame;//拂去当前帧
    imshow("读取视频",frame);
    waitKey(30);
    }
    return 0;
    }

    canny边缘检测后的视频

    int main()
    {
    //从摄像头读入视频
    VideoCapture capture(0);
    Mat edges;
    //循环每一帧
    while (1)
    {
    //【1】读入图像
    Mat frame;
    capture >> frame;//读取当前帧
    //【2】将图片转换为灰度图像
    cvtColor(frame, edges, COLOR_BGR2GRAY);//转化BGR彩色图为灰度图
    //【3】3*3内核降噪
    blur(edges, edges, Size(7, 7));
    //【4】进行canny边缘检测并显示
    Canny(edges, edges, 0, 30, 3);
    imshow("canny后的视频",edges);
    if (waitKey(30) >= 0) break;//延时30ms
    }
    return 0;
    }

  • 相关阅读:
    Bootstrap标签(label)的使用
    Docker学习(二)
    linux 的tee命令
    解决 Docker pull 出现的net/http: TLS handshake timeout 的一个办法
    win 10 安装.msi 程序出现the error code is 2503
    Kbuntu16.04利用快捷键调用终端Konsole
    ubuntu上swift开发学习2
    ubuntu上swift开发学习1
    Linux中常用文件传输命令及使用方法
    Kbuntu16.04添加工作空间
  • 原文地址:https://www.cnblogs.com/j657521265/p/7337735.html
Copyright © 2011-2022 走看看