opencv:图像梯度
常见的图像梯度算子:

一阶导数算子:

#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat src = imread("f:/images/lena.jpg");
if (src.empty())
{
printf("Could not find the image!\n");
return -1;
}
namedWindow("input", WINDOW_AUTOSIZE);
imshow("input", src);
Mat grad_x, grad_y;
Mat result;
// robot
Mat robot_x = (Mat_<int>(2, 2) << 1, 0, 0, -1);
Mat robot_y = (Mat_<int>(2, 2) << 0, 1, -1, 0);
filter2D(src, grad_x, CV_32F, robot_x, Point(-1, -1), 0, BORDER_DEFAULT);
filter2D(src, grad_y, CV_32F, robot_y, Point(-1, -1), 0, BORDER_DEFAULT);
convertScaleAbs(grad_x, grad_x);
convertScaleAbs(grad_y, grad_y);
imshow("robot_x", grad_x);
imshow("robot_y", grad_y);
add(grad_x, grad_y, result);
imshow("robot_result", result);
// sobel
Sobel(src, grad_x, CV_32F, 1, 0, 3);
Sobel(src, grad_y, CV_32F, 0, 1, 3);
convertScaleAbs(grad_x, grad_x);
convertScaleAbs(grad_y, grad_y);
imshow("sobel_x", grad_x);
imshow("sobel_y", grad_y);
//add(grad_x, grad_y, result);
addWeighted(grad_x, 0.5, grad_y, 0.5, 0, result);
imshow("sobel_result", result);
// scharr
Scharr(src, grad_x, CV_32F, 1, 0, 3);
Scharr(src, grad_y, CV_32F, 0, 1, 3);
convertScaleAbs(grad_x, grad_x);
convertScaleAbs(grad_y, grad_y);
imshow("scharr_x", grad_x);
imshow("scharr_y", grad_y);
//add(grad_x, grad_y, result);
addWeighted(grad_x, 0.5, grad_y, 0.5, 0, result);
imshow("scharr_result", result);
waitKey(0);
destroyAllWindows();
return 0;
}
opencv:图像梯度的更多相关文章
- Python+OpenCV图像处理(十二)—— 图像梯度
简介:图像梯度可以把图像看成二维离散函数,图像梯度其实就是这个二维离散函数的求导. Sobel算子是普通一阶差分,是基于寻找梯度强度.拉普拉斯算子(二阶差分)是基于过零点检测.通过计算梯度,设置阀值, ...
- OpenCV学习笔记(10)——图像梯度
学习图像梯度,图像边界等 梯度简单来说就是求导. OpenCV提供了三种不同的梯度滤波器,或者说高通滤波器:Sobel,Scharr和Lapacian.Sobel,Scharr其实就是求一阶或二阶导. ...
- OpenCV常用基本处理函数(6)图像梯度
形态学转换 腐蚀 img = cv2.imread() kernel = np.ones((,),np.uint8) erosion = cv2.erode(img,kernel,iterations ...
- opencv学习笔记(六)---图像梯度
图像梯度的算法有很多方法:sabel算子,scharr算子,laplacian算子,sanny边缘检测(下个随笔)... 这些算子的原理可参考:https://blog.csdn.net/poem_q ...
- opencv python:图像梯度
一阶导数与Soble算子 二阶导数与拉普拉斯算子 图像边缘: Soble算子: 二阶导数: 拉普拉斯算子: import cv2 as cv import numpy as np # 图像梯度(由x, ...
- opencv-学习笔记(6)图像梯度Sobel以及canny边缘检测
opencv-学习笔记(6)图像梯度Sobel以及canny边缘检测 这章讲了 sobel算子 scharr算子 Laplacion拉普拉斯算子 图像深度问题 Canny检测 图像梯度 sobel算子 ...
- OpenCV 图像清晰度评价(相机自动对焦)
相机的自动对焦要求相机根据拍摄环境和场景的变化,通过相机内部的微型驱动马达,自动调节相机镜头和CCD之间的距离,保证像平面正好投影到CCD的成像表面上.这时候物体的成像比较清晰,图像细节信息丰富. 相 ...
- OpenCV4系列之图像梯度和边缘检测
在图像处理中,求解图像梯度是常用操作. Sobel算子 Calculates the first, second, third, or mixed image derivatives using an ...
- OpenCV 图像清晰度(相机自动对焦)
相机的自动对焦要求相机根据拍摄环境和场景的变化,通过相机内部的微型驱动马达,自动调节相机镜头和CCD之间的距离,保证像平面正好投影到CCD的成像表面上.这时候物体的成像比较清晰,图像细节信息丰富. 相 ...
随机推荐
- 852. spfa判断负环
给定一个n个点m条边的有向图,图中可能存在重边和自环, 边权可能为负数. 请你判断图中是否存在负权回路. 输入格式 第一行包含整数n和m. 接下来m行每行包含三个整数x,y,z,表示存在一条从点x到点 ...
- Bootstrap资料
Bootstrap手册 : https://www.jqhtml.com/bootstraps-syntaxhigh/index.html 中文文档 :https://v3.bootcss.com/ ...
- SQLyog使用教程
详见链接:https://blog.csdn.net/qq_41520612/article/details/95474531 SQLyog连接MySQL时出现的2058错误解决方法 解决方法:win ...
- 模拟退火SA刷题记录
洛谷P1337 [JSOI2004]平衡点 / 吊打XXX 基本上是照着别人的代码写的,模拟退火为什么一定能找到答案呢...迷惑,,有时间搜一搜证明啥的 sa步骤:这个是要确定一个(xi,yi)使得函 ...
- Maven2: Missing artifact but jars are in place
那是因为没有update project. 项目右键,maven-update project.
- PP: Learning representations for time series clustering
Problem: time series clustering TSC - unsupervised learning/ category information is not available. ...
- wget安装nginx
#下载: wget http://nginx.org/download/nginx-1.8.0.tar.gz #解压: tar -zxvf nginx-1.8.0.tar.gz #安装依赖插件 yum ...
- MFC使用LoadBitmap方法加载位图文件失败解决方案(转)
用如下方法在原项目中使用LoadBitmap方法加载已有的位图资源作为背景没有问题,但放在别的项目中总是加载不出来,该函数返回NULL HBITMAP hBitmap=LoadBitmap((HINS ...
- 【Linux】解决Linux服务器内存不足问题
在Linux服务器上使用Jmeter进行压测的时候,遇到了一个错误: 根据这里的提示: Java HotSpot(TM) -Bit Server VM warning: INFO: os::commi ...
- c++ 踩坑大法好 枚举
1,枚举是个啥? c++允许程序员创建自己的数据类型,枚举数据类型是程序员自定义的一种数据类型,其值是一组命名整数常量. ,wed,thu,fri,sat,sun}; //定义一个叫day的数据类型, ...