码迷,mamicode.com
首页 > 其他好文 > 详细

OpenCV 计算机视觉(十三)各种卷积算子及自定义算子

时间:2019-07-24 22:37:32      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:iostream   open   ber   names   计算机视觉   space   rtx   nbsp   拉普拉斯算子   

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;
}

技术图片

 

OpenCV 计算机视觉(十三)各种卷积算子及自定义算子

标签:iostream   open   ber   names   计算机视觉   space   rtx   nbsp   拉普拉斯算子   

原文地址:https://www.cnblogs.com/haiboxiaobai/p/11241112.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!