opencv 基本算子,LOG算子-墨西哥草帽算子,canny算子

本章内容:


1. LOG算子-墨西哥草帽算子
2. canny算子

1. LOG算子-墨西哥草帽算子

输出结果

 

2. canny算子

输出结果

源代码


#include <ostream>
#include <opencv.hpp>

int main(int argc, char *argv[])
{
    /*
     本章内容:
        1. LOG算子-墨西哥草帽算子
        2. canny算子
    */
    cv::String fileName = "/home/wang/dev/Image/cdut.jpeg";
    cv::Mat src = cv::imread(fileName);
    if(src.data == NULL){
        printf("图像读入失败\n");
        return -1;
    }
    /* 1. LOG算子-墨西哥草帽算子
        计算过程:
                1.图像灰度化
                2.高斯模糊
                3.拉普拉斯算子
    */
    cv::Mat gray;
    cv::Mat dstGs;
    cv::Mat dstLOG;
    cv::cvtColor(src,gray,cv::COLOR_BGR2GRAY);
    cv::GaussianBlur(gray,dstGs,cv::Size(5,5),5.0);
    cv::Laplacian(dstGs,dstLOG,-1, 5);
    cv::imshow("gray",gray);
    cv::imshow("Gaussian blur",dstGs);
    cv::imshow("LOG", dstLOG);

    /*2. canny算子
     计算过程:
            1.图像灰度化
            2.高斯模糊
            3.分别计算x,y方向梯度
            4. 设定上下阈值,候选区的值若链接上阈值,则认为是边缘。
    */
    cv::Mat dstCanny;
    cv::Mat dstCanny1;
    cv::Mat dstX;
    cv::Mat dstY;
    /*
            CV_EXPORTS_W void Sobel( InputArray src, OutputArray dst, int ddepth,
                         int dx, int dy, int ksize = 3,
                         double scale = 1, double delta = 0,
                         int borderType = BORDER_DEFAULT );
    */

    cv::Sobel(dstGs,dstX,CV_16SC1,1,0); // 计算x方向sobel梯度, 梯度图像,输出包含符号
    cv::Sobel(dstGs,dstY,CV_16SC1,0,1); // 计算y方向 sobel梯度, 梯度图像,输出包含符号
    /*
        api接口: CV_EXPORTS_W void Canny( InputArray image, OutputArray edges,
                         double threshold1, double threshold2,
                         int apertureSize = 3, bool L2gradient = false );

        CV_EXPORTS_W void Canny( InputArray dx, InputArray dy,
                                 OutputArray edges,
                                 double threshold1, double threshold2,
                                 bool L2gradient = false );

            参数分析:
               @param ddepth output image depth, see @ref filter_depths "combinations"; in the case of
                8-bit input images it will result in truncated derivatives.
                {
                    Unsigned 8bits uchar 0~255
                    Mat: CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4

                    Signed 8bits char -128~127
                    Mat: CV_8SC1,CV_8SC2,CV_8SC3,CV_8SC4

                    Unsigned 16bits ushort 0~65535
                    Mat: CV_16UC1,CV_16UC2,CV_16UC3,CV_16UC4

                    Signed 16bits short -32768~32767
                    Mat: CV_16SC1,CV_16SC2,CV_16SC3,CV_16SC4

                    Signed 32bits int -2147483648~2147483647
                    Mat: CV_32SC1,CV_32SC2,CV_32SC3,CV_32SC4

                    Float 32bits float -1.18*10-38~3.40*10-38
                    Mat: CV_32FC1,CV_32FC2,CV_32FC3,CV_32FC4

                    Double 64bits double
                    Mat: CV_64FC1,CV_64FC2,CV_64FC3,CV_64FC4
                }
    */
    cv::Canny(dstX,dstY,dstCanny,50,150);
    cv::Canny(dstGs, dstCanny1,50,150);
    cv::imshow("my Canny", dstCanny);
    cv::imshow("sys Canny", dstCanny1);

 

    cv::waitKey(0);
    return 1;
}

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值