Mat magX = Mat(src.rows, src.cols, CV_32F);
Mat magY = Mat(src.rows, src.cols, CV_32F);
Sobel(image, magX, CV_32F, 1, 0, 3);
Sobel(image, magY, CV_32F, 0, 1, 3);
// 計算斜率
Mat slopes = Mat(image.rows, image.cols, CV_32F);
divide(magY, magX, slopes);
// 計算每個點的梯度
Mat sum = Mat(image.rows, image.cols, CV_64F);
Mat prodX = Mat(image.rows, image.cols, CV_64F);
Mat prodY = Mat(image.rows, image.cols, CV_64F);
multiply(magX, magX, prodX);
multiply(magY, magY, prodY);
sum = prodX + prodY;
sqrt(sum, sum);
Mat magX = Mat(src.rows, src.cols, CV_32F);
Mat magY = Mat(src.rows, src.cols, CV_32F);
Sobel(image, magX, CV_32F, 1, 0, 3);
Sobel(image, magY, CV_32F, 0, 1, 3);
// 計算斜率
Mat slopes = Mat(image.rows, image.cols, CV_32F);
divide(magY, magX, slopes);
// 計算每個點的梯度
Mat sum = Mat(image.rows, image.cols, CV_64F);
Mat prodX = Mat(image.rows, image.cols, CV_64F);
Mat prodY = Mat(image.rows, image.cols, CV_64F);
multiply(magX, magX, prodX);
multiply(magY, magY, prodY);
sum = prodX + prodY;
sqrt(sum, sum);