Function:
Create two sliders to control the size of the Gaussian kernel and σ The size of this program is changed on the threshold partition of the program. The threshold splitting program is in this
Note: because σ=0 , OpenCV calculates the window size based on the σ , so, sliding from 0 σ Slider, there is a clear and blurred first edge
PYTHON+OPENCV Realization of threshold segmentation
Python+opencv realizes the Huffman transformation detection line
(2016-5-10) to Opencv-python tutorials ' s documentation! can be downloaded
Code:
#-*-Coding:utf-8-*-ImportCv2#两个回调函数 def gaussianblursize(gaussianblur_size): GlobalKsize ksize = gaussianblur_size *2+3 PrintKsize, SIGMA DST = Cv2. Gaussianblur (SCR, (ksize,ksize), SIGMA, Ksize) cv2.imshow (WINDOW_NAME,DST) def gaussianblursigma(gaussianblur_sigma): GlobalSigma Sigma = gaussianblur_sigma/10.0 PrintKsize, SIGMA DST = Cv2. Gaussianblur (SCR, (ksize,ksize), SIGMA, Ksize) cv2.imshow (WINDOW_NAME,DST)#全局变量Gaussianblur_size =1Gaussianblur_sigma = theKsize =1SIGMA = theMax_value = -Max_type =6Window_name ="Gaussianblurs Demo"Trackbar_size ="Size*2+3"Trackbar_sigema ="SIGMA/10"#读入图片, the pattern is a grayscale chart, creating a windowSCR = Cv2.imread ("G:\homework\lena.bmp",0) Cv2.namedwindow (Window_name)#创建滑动条Cv2.createtrackbar (Trackbar_size, Window_name, Gaussianblur_size, Max_type, gaussianblursize) cv2.cre Atetrackbar (Trackbar_sigema, Window_name, Gaussianblur_sigma, Max_value, Gaussianblursigma)#初始化Gaussianblursize (1) Gaussianblursigma ( the)ifCv2.waitkey (0) == -: Cv2.destroyallwindows ()
Call:
Need to put pictures and cv2.pyd with gaussianblur.py in the same folder
>>>ImportOs>>>Os.chdir ("G:\homework")>>>ImportGaussianblur5 the5 1.55 1.65 1.95 2.45 2.55 2.95 3.05 3.35 3.65 3.95 4.15 4.25 4.35 4.45 4.55 4.65 4.75 4.8
:
PYTHON+OPENCV implementation of Gaussian smoothing filter