我们从Python开源项目中,提取了以下26个代码示例,用于说明如何使用cv2.createTrackbar()。
def run(self): cv2.namedWindow("display", cv2.WINDOW_NORMAL) cv2.setMouseCallback("display", self.opencv_calibration_node.on_mouse) cv2.createTrackbar("scale", "display", 0, 100, self.opencv_calibration_node.on_scale) if self.extra_queue: cv2.namedWindow("extra", cv2.WINDOW_NORMAL) while True: # wait for an image (could happen at the very beginning when the queue is still empty) while len(self.queue) == 0: time.sleep(0.1) im = self.queue[0] cv2.imshow("display", im) k = cv2.waitKey(6) & 0xFF if k in [27, ord('q')]: rospy.signal_shutdown('Quit') elif k == ord('s'): self.opencv_calibration_node.screendump(im) if self.extra_queue: if len(self.extra_queue): extra_img = self.extra_queue[0] cv2.imshow("extra", extra_img)
def __init__(self, files): if len(files) < 2: raise Exception('Need at least two files to compare.') self.image_window = 'Image' self.threshold_window = 'Threshold' self.difference_window = 'Difference' self.files = files self.tb_threshold = 'Threshold' self.tb_image = 'Image' self.current_image = 0 self.image1 = None self.image2 = None self.difference = None self.threshold = 25 self.gray = None cv2.namedWindow(self.image_window, cv2.WINDOW_AUTOSIZE) cv2.namedWindow(self.difference_window, cv2.WINDOW_AUTOSIZE) cv2.namedWindow(self.threshold_window, cv2.WINDOW_AUTOSIZE) cv2.createTrackbar(self.tb_image, self.difference_window, 0, len(self.files) - 2, self.selectImage) cv2.createTrackbar(self.tb_threshold, self.threshold_window, self.threshold, 255, self.renderThreshold) self.render()
def __init__(self): self.bridge = cv_bridge.CvBridge() cv2.namedWindow("input", 1) cv2.createTrackbar('param1', 'input', 10, 300, nothing) cv2.createTrackbar('param2', 'input', 15, 300, nothing) cv2.namedWindow("processed", 1) self.image_sb = rospy.Subscriber('/usb_cam/image_raw', Image, self.image_callback) self.motion = Twist() rate = rospy.Rate(20) # publish to cmd_vel of the jackal pub = rospy.Publisher("/jackal_velocity_controller/cmd_vel", Twist, queue_size=10) while not rospy.is_shutdown(): # publish Twist pub.publish(self.motion) rate.sleep()
def create_cv_ui(self): # Create slider to set HUE cv2.createTrackbar("Hue", 'mask', self.hue, self.MAX_HUE, self.change_hsv_hue) # Create slider to set SATURATION cv2.createTrackbar("Saturation", 'mask', self.sat, self.MAX_UINT, self.change_hsv_sat) # Create slider to set VALUE cv2.createTrackbar("Value", 'mask', self.val, self.MAX_UINT, self.change_hsv_val) # Create slider to set HUE TOLERANCE cv2.createTrackbar("Hue (tol)", 'mask', self.hue_tol, (self.MAX_HUE / 2) + 1, self.change_hsv_hue_tol) # Create slider to set SATURATION TOLERANCE cv2.createTrackbar("Saturation (tol)", 'mask', self.sat_tol, (self.MAX_UINT / 2) + 1, self.change_hsv_sat_tol) # Create slider to set VALUE TOLERANCE cv2.createTrackbar("Value (tol)", 'mask', self.val_tol, (self.MAX_UINT / 2) + 1, self.change_hsv_val_tol)
def __init__(self): self.norm_rgb=np.zeros((600,800,3),np.uint8) self.dst=np.zeros((600,800),np.uint8) self.b=0 self.g=0 self.r=0 self.lb=0 self.lg=0 self.lr=0 self.m=np.zeros((600,800),np.uint8) #self.win=cv2.namedWindow("detect") #self.dst=cv.CreateImage((800,600),8,1) #cv2.createTrackbar("blue", "detect",0,255,self.change_b) #cv2.createTrackbar("green","detect",0,255,self.change_g) #cv2.createTrackbar("red","detect",0,255,self.change_r) #cv2.createTrackbar("low_blue", "detect",0,255,self.change_lb) #cv2.createTrackbar("low_green","detect",0,255,self.change_lg) #cv2.createTrackbar("low_red","detect",0,255,self.change_lr)
def __init__(self): global color self.rgb=np.zeros((600,800,3),np.uint8) self.mask=np.zeros((600,800),np.uint8) self.hue_val=color self.scratch=np.zeros((600,800,3),np.uint8) #cv2.namedWindow("hue") #cv2.createTrackbar("hue", "hue",self.hue_val,255,self.change)
def trackbar_create(label, win_name, v, maxv, scale=1.0): global trackbars if label in trackbars: raise RuntimeError('Duplicate key. %s already created' % label) trackbars[label] = dict(label=label, win_name=win_name, value=v, scale=scale) cv2.namedWindow(win_name) cv2.createTrackbar(label, win_name, v, maxv, trackbar_update)
def __init__(self, image, filter_size=1, threshold1=0, threshold2=0): self.image = image self._filter_size = filter_size self._threshold1 = threshold1 self._threshold2 = threshold2 def onchangeThreshold1(pos): self._threshold1 = pos self._render() def onchangeThreshold2(pos): self._threshold2 = pos self._render() def onchangeFilterSize(pos): self._filter_size = pos self._filter_size += (self._filter_size + 1) % 2 self._render() cv2.namedWindow('edges') cv2.createTrackbar('threshold1', 'edges', self._threshold1, 255, onchangeThreshold1) cv2.createTrackbar('threshold2', 'edges', self._threshold2, 255, onchangeThreshold2) cv2.createTrackbar('filter_size', 'edges', self._filter_size, 20, onchangeFilterSize) self._render() print "Adjust the parameters as desired. Hit any key to close." cv2.waitKey(0) cv2.destroyWindow('edges') cv2.destroyWindow('smoothed')
def __init__(self, param_name, win_name, param_min, param_max, update_func=doNothing): self._update_func = update_func self._trackbar = cv2.createTrackbar(param_name, win_name, param_min, param_max, self._callback) self._param_name = param_name self._win_name = win_name # Trackbar?????
def __init__(self, resolution, wall): cv2.namedWindow(self.window_name) cv2.imshow(self.window_name, wall.img) cv2.createTrackbar("wall width", self.window_name, wall.w, 1000, wall.resize) cv2.waitKey()
def calibrateColor(color, def_range): global kernel name = 'Calibrate '+ color cv2.namedWindow(name) cv2.createTrackbar('Hue', name, 0, 180, nothing) cv2.createTrackbar('Sat', name, 0, 255, nothing) cv2.createTrackbar('Val', name, 0, 255, nothing) while(1): ret , frameinv = cap.read() frame=cv2.flip(frameinv ,1) hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) hue = cv2.getTrackbarPos('Hue', name) sat = cv2.getTrackbarPos('Sat', name) val = cv2.getTrackbarPos('Val', name) lower = np.array([hue-20,sat,val]) upper = np.array([hue+20,255,255]) mask = cv2.inRange(hsv, lower, upper) eroded = cv2.erode( mask, kernel, iterations=1) dilated = cv2.dilate( eroded, kernel, iterations=1) cv2.imshow(name, dilated) k = cv2.waitKey(5) & 0xFF if k == ord(' '): cv2.destroyWindow(name) return np.array([[hue-20,sat,val],[hue+20,255,255]]) elif k == ord('d'): cv2.destroyWindow(name) return def_range
def calibrateColor(color, def_range): global kernel name = 'Calibrate '+ color cv2.namedWindow(name) cv2.createTrackbar('Hue', name, def_range[0][0]+20, 180, nothing) cv2.createTrackbar('Sat', name, def_range[0][1] , 255, nothing) cv2.createTrackbar('Val', name, def_range[0][2] , 255, nothing) while(1): ret , frameinv = cap.read() frame=cv2.flip(frameinv ,1) hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) hue = cv2.getTrackbarPos('Hue', name) sat = cv2.getTrackbarPos('Sat', name) val = cv2.getTrackbarPos('Val', name) lower = np.array([hue-20,sat,val]) upper = np.array([hue+20,255,255]) mask = cv2.inRange(hsv, lower, upper) eroded = cv2.erode( mask, kernel, iterations=1) dilated = cv2.dilate( eroded, kernel, iterations=1) cv2.imshow(name, dilated) k = cv2.waitKey(5) & 0xFF if k == ord(' '): cv2.destroyWindow(name) return np.array([[hue-20,sat,val],[hue+20,255,255]]) elif k == ord('d'): cv2.destroyWindow(name) return def_range
def calibrateColor(color, def_range): global kernel name = 'Calibrate '+ color cv2.namedWindow(name) cv2.createTrackbar('Hue', name, def_range[0][0]+20, 180, nothing) cv2.createTrackbar('Sat', name, def_range[0][1], 255, nothing) cv2.createTrackbar('Val', name, def_range[0][2], 255, nothing) while(1): ret , frameinv = cap.read() frame=cv2.flip(frameinv ,1) hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) hue = cv2.getTrackbarPos('Hue', name) sat = cv2.getTrackbarPos('Sat', name) val = cv2.getTrackbarPos('Val', name) lower = np.array([hue-20,sat,val]) upper = np.array([hue+20,255,255]) mask = cv2.inRange(hsv, lower, upper) eroded = cv2.erode( mask, kernel, iterations=1) dilated = cv2.dilate( eroded, kernel, iterations=1) cv2.imshow(name, dilated) k = cv2.waitKey(5) & 0xFF if k == ord(' '): cv2.destroyWindow(name) return np.array([[hue-20,sat,val],[hue+20,255,255]])
def setup_trackbars(range_filter): cv2.namedWindow("Trackbars", 0) for i in ["MIN", "MAX"]: v = 0 if i == "MIN" else 255 for j in range_filter: cv2.createTrackbar("%s_%s" % (j, i), "Trackbars", v, 255, callback)
def __init__(self): if len(sys.argv) < 2: print('Usage: calibration <directory> [<filename>]') print('The supplied directory should contain the calibration images.') sys.exit(1) size = 640 self.path = sys.argv[1] self.image_window = 'Image Calibration' self.sky_window = 'Sky Calibration' self.tb_image_switch = 'image' self.tb_max_mag = 'maximum magnitude' self.save_file_name = 'data' self.selected_star = None self.selected_color = (0, 0, 255) self.marked_color = (0, 255, 0) self.circle_radius = 5 self.max_mag = 4 self.renderer = SkyRenderer(size) try: self.calibrator = Calibrator(SkyCameraFile.glob(self.path), EarthLocation(lat=Configuration.latitude, lon=Configuration.longitude, height=Configuration.elevation)) except Exception as e: print(e.message) sys.exit(2) if len(sys.argv) > 2: self.save_file_name = sys.argv[2] if os.path.exists(self.save_file_name): self.calibrator.load(self.save_file_name) cv2.namedWindow(self.image_window, cv2.WINDOW_AUTOSIZE) cv2.namedWindow(self.sky_window, cv2.WINDOW_AUTOSIZE) self.selectImage(0) cv2.setMouseCallback(self.image_window, self.imageMouseCallback) cv2.setMouseCallback(self.sky_window, self.skyMouseCallback) cv2.createTrackbar(self.tb_image_switch, self.image_window, 0, len(self.calibrator.files) - 1, self.selectImage) cv2.createTrackbar(self.tb_max_mag, self.sky_window, self.max_mag, 6, self.setMaxMag)
def __init__(self): self.cap = None self.corrected = np.zeros((100, 100), np.uint8) # image with corrected perspective cv2.namedWindow('edge') cv2.createTrackbar('thrs1', 'edge', 2000, 5000, nothing) cv2.createTrackbar('thrs2', 'edge', 4000, 5000, nothing) self.center= [0,0] self.size = [0,0]
def init_trackbar( self, window ): # self.log.init("initializing trackbars " + str(window) ) cv2.namedWindow( window ) cv2.createTrackbar('H_Max',window,0,255,nothing) cv2.createTrackbar('H_Min',window,0,255,nothing) cv2.createTrackbar('S_Max',window,0,255,nothing) cv2.createTrackbar('S_Min',window,0,255,nothing) cv2.createTrackbar('V_Max',window,0,255,nothing) cv2.createTrackbar('V_Min',window,0,255,nothing) # Loads input file, sets upper and lower to the provided values # Usage: self.set_input( "in_file_name" ) # !! Can only load the *.json files !! ( you may also write .json files yourself )
def _initialize_window(self, cspace): cv2.namedWindow(self.name) # Define trackbar names (NOTE: see known issues in README) trackbar_names = ['Ch 1 min ', 'Ch 1 max', 'Ch 2 min ', 'Ch 2 max ', 'Ch 3 min ', 'Ch 3 max'] start_vals = [0, 255, 0, 255, 0, 255] max_vals = [255, 255, 255, 255, 255, 255] # lambdas used because createTrackbar only wants the handle of a single # parameter function (passing the position), but want to send more info cv2.createTrackbar( trackbar_names[0], self.name, start_vals[0], max_vals[0], lambda pos: self._update_lowerb(pos, 0)) cv2.createTrackbar( trackbar_names[1], self.name, start_vals[1], max_vals[1], lambda pos: self._update_upperb(pos, 0)) cv2.createTrackbar( trackbar_names[2], self.name, start_vals[2], max_vals[2], lambda pos: self._update_lowerb(pos, 1)) cv2.createTrackbar( trackbar_names[3], self.name, start_vals[3], max_vals[3], lambda pos: self._update_upperb(pos, 1)) cv2.createTrackbar( trackbar_names[4], self.name, start_vals[4], max_vals[4], lambda pos: self._update_lowerb(pos, 2)) cv2.createTrackbar( trackbar_names[5], self.name, start_vals[5], max_vals[5], lambda pos: self._update_upperb(pos, 2))
def create_trackbar(detector_name): if detector_name == 'harris': cv2.createTrackbar('Quality level', TRACK_WIN, 1, 100, on_quality_level_change) elif detector_name == 'blob': cv2.createTrackbar('Maximum area', TRACK_WIN, 1, 400, on_maximum_area_change) elif detector_name == 'dog': cv2.createTrackbar('Number of octave layers', TRACK_WIN, 1, 10, on_n_octave_layers_change)
def addParameter(self, name, defaultValue, maxValue): self.values[name] = defaultValue if self.show: self.paramCount += 1 cv2.createTrackbar(name, self.windowName, defaultValue, maxValue, lambda x: None) self.__resizeWindow()