加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

OpenCV_图像梯度化

发布时间:2020-12-13 20:46:40 所属栏目:PHP教程 来源:网络整理
导读:OpenCV_图象梯度化 #include stdafx.h#include cv.h#include cxcore.h#include highgui.husing namespace std;using namespace cv;int main(int argc,char **argv){CvPoint center;//定义1个2维坐标的点double scale = ⑶;int i,j;Mat image = imread(pic.jp

OpenCV_图象梯度化

#include "stdafx.h" #include "cv.h" #include "cxcore.h" #include "highgui.h" using namespace std; using namespace cv; int main(int argc,char **argv) { CvPoint center;//定义1个2维坐标的点 double scale = ⑶; int i,j; Mat image = imread("pic.jpg");//打开1张图片 if(!image.data) return ⑴; center=Point2f(image.cols/2,image.rows/2);//构造这个2维坐标的点 Mat ptr[3]; Mat gradImg; split(image,ptr); for(int i=0;i<image.rows;i++) { for(int j=0;j<image.cols;j++) { double dx=(double)(j-center.x)/center.x; double dy=(double)(i-center.y)/center.y; double weight =exp((dx*dx+dy*dy)*scale); ptr[0].at<uchar>(i,j)=(int)ptr[0].at<uchar>(i,j)*weight;// 将浮点数转化为整数。 ptr[1].at<uchar>(i,j)=(int)ptr[1].at<uchar>(i,j)*weight; ptr[2].at<uchar>(i,j)=(int)ptr[2].at<uchar>(i,j)*weight; } } merge(ptr,3,gradImg); imshow("Window",gradImg); cvWaitKey(⑴); return 0; }
效果:



(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读