开始出现了一些问题,因为毁掉函数每次只能传回一个值,所以每次只能更新value,后来就弄了两个毁掉函数,这个时候,又出现了滑动其中一个,另一个的值就会变为默认值的情况,这个时候猜想是全局变量的问题,根据猜想改动之后果然是。
感觉还有更简单的方法,不需要设置两个回调参数,对python不是很熟悉,时间有限,先不折腾了
# -*- coding: utf-8 -*- import cv2#两个回调函数def thresholdType(threshold_type): global THRESHOLD_TYPE THRESHOLD_TYPE = threshold_type print threshold_TYPE, threshold_VALUE ret, dst = cv2.threshold(scr, THRESHOLD_VALUE, max_value, THRESHOLD_TYPE) cv2.imshow(window_name,dst)def thresholdValue(threshold_value): global THRESHOLD_VALUE THRESHOLD_VALUE = threshold_value print threshold_TYPE, threshold_VALUE ret, dst = cv2.threshold(scr, THRESHOLD_VALUE, max_value, THRESHOLD_TYPE) cv2.imshow(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"#读入图片,模式为灰度图,创建窗口scr = cv2.imread("G:/homework/SmallTarget.png",0)cv2.namedWindow(window_name)#创建滑动条cv2.createTrackbar( trackbar_type, window_name, / threshold_type, max_type, thresholdType)cv2.createTrackbar( trackbar_value, window_name, / threshold_value, max_value, thresholdValue )#初始化thresholdType(0)if cv2.waitKey(0) == 27: cv2.destroyAllWindows()