canny高低阈值效果

转自:https://www.cnblogs.com/tingshuixuan2012/p/4472406.html
代码:

// OpenCVExerciseTesting.cpp : 定义控制台应用程序的入口点。
//
//D:\\Work\\Work_Programming\\Source\\Image\\lena.jpg


#include "stdafx.h"
#include <cv.h>
#include <highgui.h>
#include <iostream>

#include <opencv2/legacy/legacy.hpp>
//#pragma comment(lib, "opencv_legacy2411.lib")

using namespace cv;
using namespace std;

//函数声明-->--->-->--->-->--->-->--->//


//<--<--<--<--<--<--<--<--<--函数声明//

int _tmain(int argc, _TCHAR* argv[])
{
    const char * soutceFile = "D:\\Work\\Work_Programming\\Source\\Image\\OpenCVExerciseImage\\第6章\\建筑.jpg";
    IplImage * image_Resource = cvLoadImage(soutceFile, CV_LOAD_IMAGE_GRAYSCALE);
    assert(image_Resource);

    cvNamedWindow("原始图像", CV_WINDOW_NORMAL);
    cvNamedWindow("题目_a_1", CV_WINDOW_NORMAL);
    cvNamedWindow("题目_a_2", CV_WINDOW_NORMAL);
    cvNamedWindow("题目_a_3", CV_WINDOW_NORMAL);
    cvNamedWindow("题目_b_1", CV_WINDOW_NORMAL);
    cvNamedWindow("题目_b_2", CV_WINDOW_NORMAL);
    cvNamedWindow("题目_b_3", CV_WINDOW_NORMAL);
    cvNamedWindow("题目_c_1", CV_WINDOW_NORMAL);
    cvNamedWindow("题目_c_2", CV_WINDOW_NORMAL);
    cvNamedWindow("题目_c_3", CV_WINDOW_NORMAL);
    //cvNamedWindow("题目_d_1", CV_WINDOW_NORMAL);
    //cvNamedWindow("题目_d_2", CV_WINDOW_NORMAL);
    //cvNamedWindow("题目_d_3", CV_WINDOW_NORMAL);
    cvNamedWindow("题目_e_1", CV_WINDOW_NORMAL);
    cvNamedWindow("题目_e_2", CV_WINDOW_NORMAL);
    cvNamedWindow("题目_e_3", CV_WINDOW_NORMAL);

    cvShowImage("原始图像", image_Resource);

    //---------------------------a:开始--------------------------------//

    IplImage * image_Result_a = cvCloneImage(image_Resource);
    cvZero(image_Result_a);
     
    double highThresh = 10;
    double lowThresh = highThresh / 1.5;

    cvCanny(image_Resource, image_Result_a, highThresh, lowThresh, 3);
    cvShowImage("题目_a_1", image_Result_a);

    lowThresh = highThresh / 2.75;
    cvZero(image_Result_a);

    cvCanny(image_Resource, image_Result_a, highThresh, lowThresh, 3);
    cvShowImage("题目_a_2", image_Result_a);

    lowThresh = highThresh / 4.0;
    cvZero(image_Result_a);

    cvCanny(image_Resource, image_Result_a, highThresh, lowThresh, 3);
    cvShowImage("题目_a_3", image_Result_a);

    //---------------------------a:结束--------------------------------//    

    //---------------------------b:开始--------------------------------//

    IplImage * image_Result_b = cvCloneImage(image_Resource);
    cvZero(image_Result_b);

    highThresh = 80;
    lowThresh = highThresh / 1.5;

    cvCanny(image_Resource, image_Result_b, highThresh, lowThresh, 3);
    cvShowImage("题目_b_1", image_Result_b);

    lowThresh = highThresh / 2.75;
    cvZero(image_Result_b);

    cvCanny(image_Resource, image_Result_b, highThresh, lowThresh, 3);
    cvShowImage("题目_b_2", image_Result_b);

    lowThresh = highThresh / 4.0;
    cvZero(image_Result_b);

    cvCanny(image_Resource, image_Result_b, highThresh, lowThresh, 3);
    cvShowImage("题目_b_3", image_Result_b);

    //---------------------------b:结束--------------------------------//    

    //---------------------------c:开始--------------------------------//

    IplImage * image_Result_c = cvCloneImage(image_Resource);
    cvZero(image_Result_c);

    highThresh = 130;
    lowThresh = highThresh / 1.5;

    cvCanny(image_Resource, image_Result_c, highThresh, lowThresh, 3);
    cvShowImage("题目_c_1", image_Result_c);

    lowThresh = highThresh / 2.75;
    cvZero(image_Result_c);

    cvCanny(image_Resource, image_Result_c, highThresh, lowThresh, 3);
    cvShowImage("题目_c_2", image_Result_c);

    lowThresh = highThresh / 4.0;
    cvZero(image_Result_c);

    cvCanny(image_Resource, image_Result_c, highThresh, lowThresh, 3);
    cvShowImage("题目_c_3", image_Result_c);
 
    //---------------------------c:结束--------------------------------//    

    //---------------------------e:开始--------------------------------//

    IplImage * image_Result_e = cvCloneImage(image_Resource);
    cvZero(image_Result_e);

    highThresh = 245;
    lowThresh = highThresh / 1.5;

    cvCanny(image_Resource, image_Result_e, highThresh, lowThresh, 3);
    cvShowImage("题目_e_1", image_Result_e);

    lowThresh = highThresh / 2.75;
    cvZero(image_Result_e);

    cvCanny(image_Resource, image_Result_e, highThresh, lowThresh, 3);
    cvShowImage("题目_e_2", image_Result_e);

    lowThresh = highThresh / 4.0;
    cvZero(image_Result_e);

    cvCanny(image_Resource, image_Result_e, highThresh, lowThresh, 3);
    cvShowImage("题目_e_3", image_Result_e);

    //---------------------------e:结束--------------------------------//    

    cvWaitKey(0);

    cvReleaseImage(&image_Resource);
    cvReleaseImage(&image_Result_a);
    cvReleaseImage(&image_Result_b);
    cvReleaseImage(&image_Result_c);
    cvReleaseImage(&image_Result_e);

    cvDestroyAllWindows();

    return 0;
}

效果图:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

总结:在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值