代码
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/core.hpp>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace cv;
using namespace std;
void show_src_image(Mat image)
{
//创建显示图片的窗口
namedWindow("Original Image", CV_WINDOW_AUTOSIZE);
//显示原始图片
imshow("Original Image", image);
}
void show_scharr_image(Mat image)
{
//创建grad_x和grad_y矩阵
Mat grad_x;
Mat grad_y;
//创建scharr算子处理显示图片
Mat scharr_img = Mat::zeros(image.size(), CV_16S);
//创建laplace平滑处理显示图片
Mat laplace_img = Mat::zeros(image.size(), CV_16S);
//定义scharr算子与laplace平滑处理默认参数
int scale = 1;
int delta = 0;
int ddepth = CV_16S;
//求X方向梯度
Scharr(image, grad_x, ddepth, 1, 0, scale, delta, BORDER_DEFAULT );
//求Y方向梯度
Scharr(image, grad_y, ddepth, 0, 1, scale, delta, BORDER_DEFAULT );
//构建流场
for (int i = 0; i < image.rows; i++)
{
for (int j = 0; j < image.cols; j++)
{
if (grad_x.at<ushort>(i, j) != 0)
{
scharr_img.at<ushort>(i , j) = grad_y.at<ushort>(i, j) / grad_x.at<ushort>(i, j);
}
else
{
scharr_img.at<ushort>(i, j) = 90;
}
}
}
//计算利用laplacian算子进行平滑
for (int i = 1; i < scharr_img.rows - 1; i++)
{
for (int j = 1; j < scharr_img.cols - 1; j++)
{