PYTHON+OPENCV Realization of threshold segmentation

Source: Internet
Author: User

Recently the teacher left a few homework, although with OPENCV very simple word on the out, but also no use Python wrote. In the official document tutorial in the threshold, see can create two sliders to select type and value, decided to use Python to implement
note the global variables in Python, declared with the global
Some problems begin to occur, because the Destroy function can only return a value at a time, so it can only update value at a time, and then get two destroy function, this time, there is another slide one, the other value will become the default value of the case, this time guess is the problem of global variables, according to guess changes is true.
Feel there is a simpler way, do not need to set two callback parameters, not very familiar with Python, time is limited, first not toss

PYTHON+OPENCV implementation of Gaussian smoothing filter
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 thresholdtype(threshold_type):    GlobalThreshold_type Threshold_type = Threshold_typePrintThreshold_type, threshold_value ret, DST = cv2.threshold (SCR, Threshold_value, Max_value, Threshold_type) Cv2.imsho W (WINDOW_NAME,DST) def thresholdvalue(threshold_value):    GlobalThreshold_value Threshold_value = Threshold_valuePrintThreshold_type, threshold_value ret, DST = cv2.threshold (SCR, Threshold_value, Max_value, Threshold_type) Cv2.imsho W (WINDOW_NAME,DST)#全局变量"" " type:0: Binary 1:binary inverted 2:truncate 3:to Zero 4:to Zero inverted" "" "Threshold_value =0Threshold_type =3Max_value =255Max_type =4Max_binary_value =255Window_name ="Threshold Demo"Trackbar_type ="Type"Trackbar_value ="Value"#读入图片, the pattern is a grayscale chart, creating a windowSCR = Cv2.imread ("G:\homework\SmallTarget.png",0) Cv2.namedwindow (Window_name)#创建滑动条Cv2.createtrackbar (Trackbar_type, Window_name, Threshold_type, Max_type, Thresholdtype) Cv2.createTrac Kbar (Trackbar_value, Window_name, Threshold_value, Max_value, Thresholdvalue)#初始化Thresholdtype (0)ifCv2.waitkey (0) == -: Cv2.destroyallwindows ()
Perform
ImportThreshold>>>Reload (threshold)0 02 01 01 11 21 31 41 51 61 71 81 Ten1  A1  -1  -1  -

PYTHON+OPENCV Realization of threshold segmentation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.