注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

*^^* 寂寞的whitebaby

欢迎来到我的家,充满回忆的地方

 
 
 

日志

 
 
关于我

いǒDê個性伱惹吥起                 ヤ 無限囂張.習慣寂寞‰〆┈

网易考拉推荐

OpenCV 边缘检测Edge Detection集合使用范例, 包含Sobel, Canny等  

2011-03-02 17:22:40|  分类: openCV |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

vSmooth(imgGrey,smoothImg,CV_MEDIAN,3,0);//先用Median filter来过滤Salt and Pepper noise;
cvThreshold(smoothImg,binaryImg,40,255,CV_THRESH_BINARY); // 把图像二值化;
cvAdaptiveThreshold(smoothImg,adThresImg,255,CV_ADAPTIVE_THRESH_GAUSSIAN_C, CV_THRESH_BINARY,3,5);//这是一个有意思的函数,除了二值化图像,也可以用作边缘检测,论坛有个帖子也讨论过,请参见http://www.opencv.org.cn/forum/viewtopic.php?t=3355
cvSobel(smoothImg,sobelImg,1,1,5);//使用Sobel过滤图像;
cvCanny(smoothImg,cannyImg,60,150,3);//使用Canny filter
cvSobel(smoothImg,scharrImg,1,0,CV_SCHARR);//使用Scharr filter,请注意导数参数设置。
cvLaplace(smoothImg,laplaceImg,3);//Laplace filter,输出图像必须是IPL_DEPTH_32F(32-bit float).

// opencvHello.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <stdlib.h>

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <math.h>

using namespace std;


/*
  // Coded by Huang,Haiqiao 2009-12-31 for OpenCV China Forum.http://www.opencv.org.cn
  // updated on 2010-01-02 about adaptive Threshold
  //http://www.opencv.org.cn/forum/viewtopic.php?f=1&t=9015
*/
int main(int argc, char** argv)
{
   cout << "Edge Detection OpenCV!"<<endl;
   char* filename="D:\\OpenCV_stuff\\SampleImages\\pattern512salt.bmp";
   IplImage* imgRGB = cvLoadImage(filename);
   IplImage* imgGrey = cvLoadImage(filename,0);

   if (imgGrey==NULL){
      cout << "No valid image input."<<endl;
      char c=getchar();
      return 1;
   }
   int w=imgGrey->width;
   int h=imgGrey->height;

   IplImage* smoothImg = cvCreateImage(cvSize(w, h),IPL_DEPTH_8U, 1);
   IplImage* binaryImg = cvCreateImage(cvSize(w, h),IPL_DEPTH_8U, 1);
   IplImage* sobelImg = cvCreateImage(cvSize(w, h),IPL_DEPTH_8U, 1);
   IplImage* cannyImg = cvCreateImage(cvSize(w, h),IPL_DEPTH_8U, 1);
   IplImage* scharrImg = cvCreateImage(cvSize(w, h),IPL_DEPTH_8U, 1);
   IplImage* adThresImg = cvCreateImage(cvSize(w, h),IPL_DEPTH_8U, 1);
   IplImage* laplaceImg = cvCreateImage(cvSize(w, h),IPL_DEPTH_32F, 1);

   cvSmooth(imgGrey,smoothImg,CV_MEDIAN,3,0);//CV_MEDIAN.//CV_GAUSSIAN
   cvThreshold(smoothImg,binaryImg,40,255,CV_THRESH_BINARY);

   double max_value=255;
   int adpative_method=CV_ADAPTIVE_THRESH_GAUSSIAN_C;//CV_ADAPTIVE_THRESH_MEAN_C
   int threshold_type=CV_THRESH_BINARY;
   int block_size=3;
   int offset=5;
   cvAdaptiveThreshold(smoothImg,adThresImg,max_value,adpative_method,threshold_type,block_size,offset);

   cvSobel(smoothImg,sobelImg,1,1,5);
   cvCanny(smoothImg,cannyImg,60,150,3);
   cvSobel(smoothImg,scharrImg,1,0,CV_SCHARR);
   cvLaplace(smoothImg,laplaceImg,3);
   

   
   cvNamedWindow("original", CV_WINDOW_AUTOSIZE );
   cvShowImage( "original", imgRGB );
   cvNamedWindow("cvSmooth", CV_WINDOW_AUTOSIZE );
   cvShowImage( "cvSmooth", smoothImg );
   cvNamedWindow("cvThreshold", CV_WINDOW_AUTOSIZE );
   cvShowImage( "cvThreshold", binaryImg );
   cvNamedWindow("cvAdaptiveThreshold", CV_WINDOW_AUTOSIZE );
   cvShowImage( "cvAdaptiveThreshold", adThresImg );
   cvNamedWindow("cvCanny", CV_WINDOW_AUTOSIZE );
   cvShowImage( "cvCanny", cannyImg );
   cvNamedWindow("cvSobel", CV_WINDOW_AUTOSIZE );
   cvShowImage( "cvSobel", sobelImg );
   cvNamedWindow("CV_SCHARR", CV_WINDOW_AUTOSIZE );
   cvShowImage( "CV_SCHARR", scharrImg );
   cvNamedWindow("cvLaplace", CV_WINDOW_AUTOSIZE );
   cvShowImage( "cvLaplace", laplaceImg );

   cvWaitKey(0);
   cvReleaseImage(&imgGrey);
   cvReleaseImage(&imgRGB);
   cvDestroyWindow("Original");
   cvReleaseImage(&smoothImg);
   cvDestroyWindow("cvSmooth");

   cvReleaseImage(&binaryImg);
   cvDestroyWindow("cvAdaptiveThreshold");

   cvReleaseImage(&adThresImg);
   cvDestroyWindow("cvThreshold");

   cvReleaseImage(&cannyImg);
   cvDestroyWindow("cvCanny");

   cvReleaseImage(&sobelImg);
   cvDestroyWindow("cvSobel");

   cvReleaseImage(&scharrImg);
   cvDestroyWindow("CV_SCHARR");

   cvReleaseImage(&laplaceImg);
   cvDestroyWindow("cvLaplace");
   
   //char c=getchar();
   return 0;
}


  评论这张
 
阅读(2648)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018