#include <iostream>
#include <opencv2/opencv.hpp>
#define window1 "【原圖】"
#define window2 "【效果圖1】"
#define window3 "【效果圖2】"
using namespace cv;
using namespace std;
//sobel算子簡單示例。
int main()
{
//1.原圖像。
Mat src = imread("水果圖.jpg");
//resize(src, src, Size(), 0.4, 0.4);
imshow(window1,src);
//2.x方向。
Mat sobel_x;
Sobel(src,sobel_x,CV_64F,1,0,3,1,1,BORDER_DEFAULT);
convertScaleAbs(sobel_x,sobel_x);//計算模,並轉換爲八位圖。
imshow("x",sobel_x);
//3.y方向sobel
Mat sobel_y;
Sobel(src,sobel_y,CV_64F,0,1,3,1,1,BORDER_DEFAULT);
convertScaleAbs(sobel_y, sobel_y);
imshow("y",sobel_y);
//4.綜合。(近似)
Mat comb_xy;
addWeighted(sobel_x,0.5,sobel_y,0.5,0,comb_xy);
imshow("comb",comb_xy);
waitKey(0);
return 0;
}