zoukankan      html  css  js  c++  java
  • opencv复杂一点的变换

    今天的学习中用到了cvPyrDown函数,cvPyrUp函数,canny函数的用法。在此进行记录,以便以后参考。

    使用cvPyrDown()创建一幅宽度和高度均为输入图像一半尺寸的图像

    功能:
    函数cvPyrDown使用Gaussian金字塔分解对输入图像向下采样。
    格式:
    void cvPyrDown(
    const CvArr*src,
    CvArr*dst,
    int filter=CV_GAUSSIAN_5x5);
    参数:
    src输入图像,dst 输出图像,CV_GAUSSIAN_5x5是默认的模版
    例子:
    void doPyrDown(void) {
    IplImage *in=cvLoadImage("lena.jpg");
    int filter = IPL_GAUSSIAN_5x5;
    assert(in->width%2 == 0 && in->height%2 == 0);//确认长宽像素是偶数(否则无法缩放一半)
    IplImage *out=cvCreateImage(cvSize(in->width/2, in->height/2), in->depth, in->nChannels);//创建新图像,长宽各一半,同深度,同通道数
    cvPyrDown(in, out); cvNamedWindow("in");
    cvNamedWindow("out");
    cvShowImage("in", in);
    cvShowImage("out", out);
    cvWaitKey(0);
    cvReleaseImage(&in);
    cvReleaseImage(&out);
    cvDestroyAllWindows();
    }

    cvPyrUP将现有的图像在每个维度上放大两倍

    cvPyrUP(

    IplImage *src,

    IplImage *dst,

    IplFilter filter=CV_GAUSSIAN_5x5

    );

    Canny边缘检测
    void Canny(InputArray src,OutputArray dst,double threshold1, double threshold2, int apertureSize=3,bool L2gradient=false )

    参数详解:

    src:源图像 
    dst:目标图像。 
    threshold1:第一个滞后性阈值。 
    threshold2:第二个滞后性阈值。 
    apertureSize:表示应用Sobel算子的孔径大小,其有默认值3。 
    L2gradient:一个计算图像梯度幅值的标识,有默认值false。

    需要注意的是,这个函数threshold1和threshold2两者的小者用于边缘连接,而大者用来控制强边缘的初始段, 推荐的高低阈值比在2:1到3:1之间。

    下面是将一幅图调用两次doPyrdown,再用canny处理的例子。

    #include "highgui.h"
    #include "cv.h"
    IplImage* out;
    IplImage* doPyrdown(IplImage* in)
    {
    assert(in->width % 2 == 0 && in->height % 2 == 0);
    out = cvCreateImage(
    cvSize(in->width / 2, in->height / 2),
    in->depth,
    in->nChannels
    );
    cvPyrDown(in, out, CV_GAUSSIAN_5x5);
    return (out);
    };
    IplImage* doCanny(IplImage *in,
    double lowThresh,
    double highTresh,
    int aperture
    ) {


    if (in->nChannels != 1) return (0);
    IplImage *out = cvCreateImage(
    cvSize(in->width, in->height),
    IPL_DEPTH_8U,
    1
    );
    cvCanny(in, out, lowThresh, highTresh, aperture);
    return(out);
    };
    int main(int argc, char** argv)
    {
    IplImage* img = cvLoadImage("1.jpg", 0);
    cvNamedWindow("原图", CV_WINDOW_AUTOSIZE);
    cvShowImage("原图", img);
      out = doPyrdown(img);
      out = doPyrdown(out);
    out = doCanny(img, 2, 3, 3);

    cvNamedWindow("两次缩放和边缘检测", CV_WINDOW_AUTOSIZE);

    cvShowImage("两次缩放和边缘检测", out);
    cvWaitKey(0);
    cvReleaseImage(&out);
    cvDestroyWindow("两次缩放和边缘检测");
    cvReleaseImage(&img);
    cvDestroyWindow("原图");
    return 0;
    }

     

     

  • 相关阅读:
    Qt之自定义托盘(二)
    使用react-navigation提示undefind is not a function
    vue使用mockjs配置步骤(无需启动node服务)
    input框type=file设置cursor:pointer的问题
    umi中使用scss
    umi怎么去添加配置式路由
    Rem自适应js
    解决在antd中使用 autoprefixer 9.4.5 会抛出错误 Replace text-decoration-skip: ink to text-decoration-skip-ink: auto, because spec had been changed 的问题
    file类型input框设置上传相同文件,并都可以触发change事件。
    浅谈JavaScript对象数组根据某属性sort升降序排序
  • 原文地址:https://www.cnblogs.com/alpqmz/p/7478259.html
Copyright © 2011-2022 走看看