sobel 算子的c实现
#include <opencv2/opencv.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
#define pos(i,j) ((i)*width+(j))
int main()
{
Mat srcImage = imread("timg.jpg");
imshow("【原始图】Canny边缘检测", srcImage);
Mat edge, grayImage; //参数定义
cvtColor(srcImage, grayImage, COLOR_BGR2GRAY);
edge = Mat(grayImage.size(), grayImage.type());
int width = grayImage.cols;
int height = grayImage.rows;
uchar* data = grayImage.data;
imshow("grayImage灰度图", grayImage);
edge = Mat(grayImage.size(), grayImage.type());
//x方向卷积
int x[3][3]{
{-1,0,1},
{-2, 0, 2},
{-1,0,1},
};
//y方向卷积
int y[3][3]{
{-1,-2,-1},
{0, 0, 0},
{1,2,1},
};
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
if (i == 0 || i == height - 1 || j == 0 || j == width - 1)
continue;
int sumx =