zoukankan      html  css  js  c++  java
  • OpenCV学习总结(3)- 做点基本的事情

    1.缩放

    void resize(InputArray src, OutputArray dst, Size dsize, double fx=0, double fy=0, int interpolation=INTER_LINEAR)
    

    实例:改变图片尺寸

    #include <opencv2/opencv.hpp>
    #include <stdlib.h>
    
    using namespace cv;
    
    int main(void)
    {
        const char *name = "D:\project_opencv\_media\1.jpg";
        Mat srcImage = imread(name);
        imshow("show src", srcImage);
    
        Mat dstImage;
        resize(srcImage,dstImage,Size(200,300));
    
        imshow("show resize", dstImage);
        waitKey(0);
    
        exit(EXIT_SUCCESS);
    }

    2.平滑

    高斯模糊接口

    void GaussianBlur( const Mat& src, Mat& dst, Size ksize,double sigmaX, double sigmaY=0,
    int borderType=BORDER_DEFAULT );

    实例:高斯模糊效果

    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/imgproc/imgproc.hpp>
    
    using namespace cv;
    
    int main()
    {
        Mat srcImage = imread("D:\project_opencv\_media\1.jpg");
        //imshow("avarage filter resource", srcImage);
        waitKey(1000);
    
        Mat dstImage;
        GaussianBlur(srcImage, dstImage, Size(7,7), 100);
    
        imshow("avarage filter effect", dstImage);
        waitKey(0);
    
        //return 0;
    }
    

      

    3.颜色空间转换和阈值化

    void cvtColor(InputArray src, OutputArray dst, int code,int dstCn=0);
    
    void threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type);
    

    实例:颜色转换

    #include <opencv2/opencv.hpp>
    #include <stdlib.h>
    
    using namespace cv;
    
    int main(void)
    {
        const char *name = "D:\project_opencv\_media\1.jpg";
        Mat srcImage = imread(name);
        imshow("show src", srcImage);
    
        Mat dstImage;
        cvtColor(srcImage, dstImage, 10);
    
        imshow("show dst", dstImage);
        waitKey(10000);
    
        exit(EXIT_SUCCESS);
    }
    

      

  • 相关阅读:
    16 类成员
    [Tips] WSL ubuntu 18.04 安装python3
    [Tips]ubuntu安装go
    [Notes] 随笔的标题格式说明
    [Tips]Ubuntu手动修改DNS
    [BUG]Ubuntu 16.04 出现“sudo unable to resolve host”
    [Tips]ubuntu 换源
    [Tips]将本地git文件夹上传云端
    [Notes] Dockerfile中COPY命令的简单性
    [BUG]Ubuntu server 16.04安装,无网卡驱动解决
  • 原文地址:https://www.cnblogs.com/ingy0923/p/9029228.html
Copyright © 2011-2022 走看看