zoukankan      html  css  js  c++  java
  • OpenCV (十三)各种卷积算子及自定义算子

    Robert算子:

      Robert X 算子:                                           Robert Y 算子:

    代码:

    #include<opencv2/opencv.hpp>	
    #include<iostream>		
    
    using namespace std;
    using namespace cv;
    
    Mat src, robertx, roberty;
    
    int main(int argc, char** argv) {
    	src = imread("D:/OpenCVprj/image/test3.jpg");
    	imshow("src", src);
    	//Robert X 算子
    	Mat robert_x = (Mat_<int>(2, 2) << 1, 0, 0, -1);
    	filter2D(src, robertx, -1, robert_x, Point(-1, -1), 0.0);
    	imshow("robertx", robertx);
    
    	//Robert Y 算子
    	Mat robert_y = (Mat_<int>(2, 2) << 0, 1, -1, 0);
    	filter2D(src, roberty, -1, robert_y, Point(-1, -1), 0.0);
    	imshow("roberty", roberty);
    
    	waitKey(0);
    	return 0;
    }
    

    Sobel 算子:

        Sobel X 算子:                      Sobel Y 算子:

    代码:

    #include<opencv2/opencv.hpp>	
    #include<iostream>		
    
    using namespace std;
    using namespace cv;
    
    Mat src, robertx, roberty, sobel_x, sobel_y;
    
    int main(int argc, char** argv) {
    	src = imread("D:/OpenCVprj/image/test3.jpg");
    	imshow("src", src);
    	//Robert X 算子
    	//Mat robert_x = (Mat_<int>(2, 2) << 1, 0, 0, -1);
    	//filter2D(src, robertx, -1, robert_x, Point(-1, -1), 0.0);
    	//imshow("robertx", robertx);
    	//Robert Y 算子
    	//Mat robert_y = (Mat_<int>(2, 2) << 0, 1, -1, 0);
    	//filter2D(src, roberty, -1, robert_y, Point(-1, -1), 0.0);
    	//imshow("roberty", roberty);
    
    	//Sobel X算子
    	Mat sobelx = (Mat_<int>(3, 3) << -1, 0, 1, -2, 0, 2, -1, 0, 1);
    	filter2D(src, sobel_x, -1, sobelx, Point(-1, -1), 0.0);
    	imshow("sobel_x", sobel_x);
    	//Sobel Y算子
    	Mat sobely = (Mat_<int>(3, 3) << -1, -2, -1, 0, 0, 0, 1, 2, 1);
    	filter2D(src, sobel_y, -1, sobelx, Point(-1, -1), 0.0);
    	imshow("sobel_y", sobel_y);
    
    	waitKey(0);
    	return 0;
    }

    拉普拉斯算子:

    代码:

    #include<opencv2/opencv.hpp>	
    #include<iostream>		
    
    using namespace std;
    using namespace cv;
    
    Mat src, robertx, roberty, sobel_x, sobel_y, laplance_image;
    
    int main(int argc, char** argv) {
    	src = imread("D:/OpenCVprj/image/test3.jpg");
    	imshow("src", src);
    	//Robert X 算子
    	//Mat robert_x = (Mat_<int>(2, 2) << 1, 0, 0, -1);
    	//filter2D(src, robertx, -1, robert_x, Point(-1, -1), 0.0);
    	//imshow("robertx", robertx);
    	//Robert Y 算子
    	//Mat robert_y = (Mat_<int>(2, 2) << 0, 1, -1, 0);
    	//filter2D(src, roberty, -1, robert_y, Point(-1, -1), 0.0);
    	//imshow("roberty", roberty);
    
    	//Sobel X算子
    	//Mat sobelx = (Mat_<int>(3, 3) << -1, 0, 1, -2, 0, 2, -1, 0, 1);
    	//filter2D(src, sobel_x, -1, sobelx, Point(-1, -1), 0.0);
    	//imshow("sobel_x", sobel_x);
    	//Sobel Y算子
    	//Mat sobely = (Mat_<int>(3, 3) << -1, -2, -1, 0, 0, 0, 1, 2, 1);
    	//filter2D(src, sobel_y, -1, sobelx, Point(-1, -1), 0.0);
    	//imshow("sobel_y", sobel_y);
    
    	//拉普拉斯算子
    	Mat kernel_laplance = (Mat_<int>(3, 3) << 0, -1, 0, -1, 4, -1, 0, -1, 0);
    	filter2D(src, laplance_image, -1, kernel_laplance, Point(-1, -1), 0.0);
    	imshow("laplance_image", laplance_image);
    	waitKey(0);
    	return 0;
    }

  • 相关阅读:
    dwz tabs table实现翻页及各tabs查询
    DruidDataSource配置
    利用blob对象实现大文件分片上传
    HTML5 File API 全介绍
    JS获取当前网页内容,创建文件并下载,URL.createObjectURL和URL.revokeObjectURL
    使用 CSS 接收用户的点击事情并对相关节点进行操作
    Flex布局
    background: inherit制作倒影、单行居中两行居左超过两行省略
    层叠顺序与堆栈上下文、font-family字体定义顺序的
    简单使用GA监控网站浏览行为
  • 原文地址:https://www.cnblogs.com/haiboxiaobai/p/11241112.html
Copyright © 2011-2022 走看看