코드 11-2 적응형 이진화 예제 프로그램 [ch11/adaptive]
01 #include "opencv2/opencv.hpp" 02 #include <iostream> 03 04 using namespace cv; 05 using namespace std; 06 07 void on_trackbar(int pos, void* userdata); 08 09 int main() 10 { 11 Mat src = imread("sudoku.jpg", IMREAD_GRAYSCALE); 12 13 if (src.empty()) { 14 cerr << "Image load failed!" << endl; 15 return -1; 16 } 17 18 imshow("src", src); 19 20 namedWindow("dst"); 21 createTrackbar("Block Size", "dst", 0, 200, on_trackbar, (void*)&src); 22 setTrackbarPos("Block Size", "dst", 11); 23 24 waitKey(0); 25 return 0; 26 } 27 28 void on_trackbar(int pos, void* userdata) 29 { 30 Mat src = *(Mat*)userdata; 31 32 int bsize = pos; 33 if (bsize % 2 = = 0) bsize--; 34 if (bsize < 3) bsize = 3; 35 36 Mat dst; 37 adaptiveThreshold(src, dst, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 38 bsize, 5); 39 40 imshow("dst", dst); 41 }