opencv轮廓检测之椭圆检测-----算法篇(2)---Sobel---自定义卷积核问题
2016-04-06 10:38
471 查看
上一篇讲了怎么用sobel算子获取边缘, 本篇要讲opencv怎么自定义卷积核
还是以sobel算子为例
sobel算子
可以看到效果和算法篇(1)有些相反
而我在定义卷积核后进行了180度旋转.
而根据这个教程http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/sobel_derivatives/sobel_derivatives.html
判断使用 卷积核 在使用前并不需要进行翻转
(上一篇中处理dst有错误, 请忽略吧)
还是以sobel算子为例
sobel算子
#include <opencv2/opencv.hpp>
#include <iostream>
int main(int argc, char ** argv)
{
if(argc < 2)
return -1;
cv::Mat img = cv::imread(argv[1],0);
cv::Mat dst1 , dst2, dst3 ,dst;
cv::Matx33f kernelx(-1,0,1,
-2,0,2,
-1,0,1);
cv::Matx33f kernely(-1,-2,-1,
0, 0, 0,
1, 2, 1);
cv::flip(kernelx,kernelx,-1);
cv::flip(kernely,kernely,-1);
// cv::sepFilter2D(img,dst,CV_64F,kernelx,kernely);//kernel.type() == DataType<DT>::type && (kernel.rows == 1 || kernel.cols == 1)) in RowFilter
cv::filter2D(img,dst1,-1,kernelx);
cv::filter2D(img,dst2,-1,kernely);
dst3 = dst1 + dst2;
cv::filter2D(img,dst,-1,kernelx);
cv::filter2D(dst,dst,-1,kernely);
cv::namedWindow("dst1",cv::WINDOW_AUTOSIZE);
cv::namedWindow("dst2",cv::WINDOW_AUTOSIZE);
cv::namedWindow("dst3",cv::WINDOW_AUTOSIZE);
cv::namedWindow("dst",cv::WINDOW_AUTOSIZE);
cv::imshow("dst1",dst1);
cv::imshow("dst2",dst2);
cv::imshow("dst3",dst3);
cv::imshow("dst",dst);
for(;;)
{
if(cv::waitKey(0)==27)
break;
}
return 0;
}
可以看到效果和算法篇(1)有些相反
而我在定义卷积核后进行了180度旋转.
而根据这个教程http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/sobel_derivatives/sobel_derivatives.html
判断使用 卷积核 在使用前并不需要进行翻转
(上一篇中处理dst有错误, 请忽略吧)
相关文章推荐
- 宿主机Windows访问虚拟机Linux文件(一)
- OpenCV读取和显示图片
- 云舒天气项目分析之架构
- linux重启命令学习
- nginx 安装
- linux ping不通外网unknown host xxxxx解决方法
- 我的2016年决心书(老男孩教育在线课程班)
- Bash玩转脚本2之自己的脚本管理工具
- MapReduce2.0 原理、架构、应用场景
- Hadoop - Hadoop开发环境搭建
- System.Properties和System.getenv区别
- Linux应用服务器搭建手册——weblogic安装
- Linux下chkconfig命令详解
- umask文件权限屏蔽字
- linux如何禁止某个ip连接服务器
- Ubuntu下安装fastboot的时候出现 未发现软件包
- 局域网内Windows使用RealVNC远程连接CentOS6.5桌面
- 硬链接的创建及删除
- 阿里云CentOS使用vsftpd搭建FTP服务器
- LVS、Nginx、Haproxy三大负载均衡软件对比