Python cv2 模块,getTrackbarPos() 实例源码

我们从Python开源项目中,提取了以下21个代码示例,用于说明如何使用cv2.getTrackbarPos()

项目:CE264-Computer_Vision    作者:RobinCPC    | 项目源码 | 文件源码
def skin_calib(self, raw_yrb):
        mask_skin = cv2.inRange(raw_yrb, self.mask_lower_yrb, self.mask_upper_yrb)
        cal_skin = cv2.bitwise_and(raw_yrb, raw_yrb, mask=mask_skin)
        cv2.imshow('YRB_calib', cal_skin)
        k = cv2.waitKey(5) & 0xFF
        if k == ord('s'):
            self.calib_switch = False
            cv2.destroyWindow('YRB_calib')

        ymin = cv2.getTrackbarPos('Ymin', 'YRB_calib')
        ymax = cv2.getTrackbarPos('Ymax', 'YRB_calib')
        rmin = cv2.getTrackbarPos('CRmin', 'YRB_calib')
        rmax = cv2.getTrackbarPos('CRmax', 'YRB_calib')
        bmin = cv2.getTrackbarPos('CBmin', 'YRB_calib')
        bmax = cv2.getTrackbarPos('CBmax', 'YRB_calib')
        self.mask_lower_yrb = np.array([ymin, rmin, bmin])
        self.mask_upper_yrb = np.array([ymax, rmax, bmax])


# Do skin detection with some filtering
项目:python-opencv2    作者:bunkahle    | 项目源码 | 文件源码
def update(dummy=None):
        if seed_pt is None:
            cv2.imshow('floodfill', img)
            return
        flooded = img.copy()
        mask[:] = 0
        lo = cv2.getTrackbarPos('lo', 'floodfill')
        hi = cv2.getTrackbarPos('hi', 'floodfill')
        flags = connectivity
        if fixed_range:
            flags |= cv2.FLOODFILL_FIXED_RANGE
        cv2.floodFill(flooded, mask, seed_pt, (255, 255, 255), (lo,)*3, (hi,)*3, flags)
        cv2.circle(flooded, seed_pt, 2, (0, 0, 255), -1)
        cv2.imshow('floodfill', flooded)
项目:python-opencv2    作者:bunkahle    | 项目源码 | 文件源码
def update(dummy=None):
        sz = cv2.getTrackbarPos('op/size', 'morphology')
        iters = cv2.getTrackbarPos('iters', 'morphology')
        opers = cur_mode.split('/')
        if len(opers) > 1:
            sz = sz - 10
            op = opers[sz > 0]
            sz = abs(sz)
        else:
            op = opers[0]
        sz = sz*2+1

        str_name = 'MORPH_' + cur_str_mode.upper()
        oper_name = 'MORPH_' + op.upper()
        st = cv2.getStructuringElement(getattr(cv2, str_name), (sz, sz))
        res = cv2.morphologyEx(img, getattr(cv2, oper_name), st, iterations=iters)

        draw_str(res, (10, 20), 'mode: ' + cur_mode)
        draw_str(res, (10, 40), 'operation: ' + oper_name)
        draw_str(res, (10, 60), 'structure: ' + str_name)
        draw_str(res, (10, 80), 'ksize: %d  iters: %d' % (sz, iters))
        cv2.imshow('morphology', res)
项目:cv_build18    作者:eknight7    | 项目源码 | 文件源码
def print_hsv(x):
    if x == 1:
        H_low = cv2.getTrackbarPos("H_low", "Segmented")
        S_low = cv2.getTrackbarPos("S_low", "Segmented")
        V_low = cv2.getTrackbarPos("V_low", "Segmented")
        H_high = cv2.getTrackbarPos("H_high", "Segmented")
        S_high = cv2.getTrackbarPos("S_high", "Segmented")
        V_high = cv2.getTrackbarPos("V_high", "Segmented")

        low = np.array([H_low, S_low, V_low])
        high = np.array([H_high, S_high, V_high])
        print "HSV Low: ", low, ", High: ", high

        save_name = 'seg' + '_lh_' + str(low[0]) + '_ls_' + str(low[1]) + '_lv_' + str(low[2]) \
                    + '_hh_' + str(high[0]) + '_hs_' + str(high[1]) + '_hv_' + str(high[2]) \
                    + '_' + img_str

        mask = cv2.inRange(birdsHSV, low, high)
        result = cv2.bitwise_and(birdsImg, birdsImg, mask = mask)
        res_name = '../results/' + save_name
        print "Saving result as", res_name
        cv2.imwrite(res_name, result)
项目:pybot    作者:spillai    | 项目源码 | 文件源码
def trackbar_update(_=None): 
    global trackbars
    for k,v in trackbars.iteritems(): 
        trackbars[k]['value'] = cv2.getTrackbarPos(v['label'], v['win_name'])
项目:PyIntroduction    作者:tody411    | 项目源码 | 文件源码
def value(self):
        return cv2.getTrackbarPos(self._param_name, self._win_name)

    # Trackbar?????
项目:Manimouse    作者:shivamkajale    | 项目源码 | 文件源码
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
项目:Manimouse    作者:shivamkajale    | 项目源码 | 文件源码
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
项目:Manimouse    作者:shivamkajale    | 项目源码 | 文件源码
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
项目:Manimouse    作者:shivamkajale    | 项目源码 | 文件源码
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
项目:Manimouse    作者:shivamkajale    | 项目源码 | 文件源码
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]])
项目:Manimouse    作者:shivamkajale    | 项目源码 | 文件源码
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
项目:Manimouse    作者:shivamkajale    | 项目源码 | 文件源码
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
项目:Manimouse    作者:shivamkajale    | 项目源码 | 文件源码
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
项目:diy_driverless_car_ROS    作者:wilselby    | 项目源码 | 文件源码
def get_trackbar_values(range_filter):
    values = []

    for i in ["MIN", "MAX"]:
        for j in range_filter:
            v = cv2.getTrackbarPos("%s_%s" % (j, i), "Trackbars")
            values.append(v)

    return values
项目:Conquest_kshitij    作者:pigeon-kgp    | 项目源码 | 文件源码
def change():
 global ORANGE,orange,PINK,pink
 TrackbarPos = cv2.getTrackbarPos('Orangemin', WindowName)
 orange['min'][0]=ORANGE['min'][0]+TrackbarPos

 TrackbarPos = cv2.getTrackbarPos('Orangemax', WindowName)
 orange['max'][0]=ORANGE['max'][0]+TrackbarPos

 TrackbarPos = cv2.getTrackbarPos('Pinkmin', WindowName)
 pink['min'][0]=PINK['min'][0]+TrackbarPos

 TrackbarPos = cv2.getTrackbarPos('Pinkmax', WindowName)
 pink['max'][0]=PINK['max'][0]+TrackbarPos
项目:Vision_Processing-2016    作者:Sabercat-Robotics-4146-FRC    | 项目源码 | 文件源码
def get_upper_trackbar( self, window ):
        hh = cv2.getTrackbarPos('H_Max',window)
        sh = cv2.getTrackbarPos('S_Max',window)
        vh = cv2.getTrackbarPos('V_Max',window)
        return [ hh, sh, vh ]

    # Gets the value of the lower HSV values from the trackbar
    # Usage: self.get_lower_trackbar( "window_name" )
    # Returns numpy array: np.array( [ h, s, v ] )
项目:Vision_Processing-2016    作者:Sabercat-Robotics-4146-FRC    | 项目源码 | 文件源码
def get_lower_trackbar( self, window ):
        hl = cv2.getTrackbarPos('H_Min',window)
        sl = cv2.getTrackbarPos('S_Min',window)
        vl = cv2.getTrackbarPos('V_Min',window)
        return [ hl, sl, vl ]

    # Sets upper and lower values to their coresponding trackbar
    # Usage: self.set_limits_trackbar( { "window_name": [ np.array([h,s,v]), np.array([h,s,v]) ] } )
    # set the value to their corresponding trackbar if the key is to be filtered
项目:Vision2016    作者:AluminatiFRC    | 项目源码 | 文件源码
def __getitem__(self, name):
        if self.show:
            return cv2.getTrackbarPos(name, self.windowName)
        if name in self.values:
            return self.values[name]
        return -1
项目:SimpleGestureRecognition    作者:EvilPort2    | 项目源码 | 文件源码
def get_trackbar_values(range_filter):
    values = []

    for i in ["MIN", "MAX"]:
        for j in range_filter:
            v = cv2.getTrackbarPos("%s_%s" % (j, i), "Trackbars")
            values.append(v)

    return values
项目:drone-token-tracker    作者:Williangalvani    | 项目源码 | 文件源码
def find_code(self,img ):
        h, w = img.shape[:2]


        gray=img
        thrs1 = cv2.getTrackbarPos('thrs1', 'edge')
        thrs2 = cv2.getTrackbarPos('thrs2', 'edge')
        edge = cv2.Canny(gray, thrs1, thrs2, apertureSize=5)
        vis = cv2.cvtColor(img.copy(), cv2.COLOR_GRAY2BGR)
        vis /= 2

        #vis[edge != 0] = (0, 255, 0)
        #cv2.imshow('edge', vis)

        vis2 = np.zeros((h, w), np.uint8)
        vis2[edge != 0] = 255

        _, contours0, hierarchy = cv2.findContours(vis2.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
        contours = [cv2.approxPolyDP(cnt, 3, True) for cnt in contours0]

        selected = []
        # **[Next, Previous, First_Child, Parent]**
        if hierarchy != None:
            for c, h in zip(contours, hierarchy[0]):
                if h[0] == -1 and h[1] == -1:
                    kid = h[2]
                    if kid != -1:
                        kidh = hierarchy[0][kid]
                        if kidh[0] == -1 and kidh[1] == -1:  ### only checking for nested circles, without brothers
                            selected.append(c)

        cv2.drawContours(vis, selected, -1, (255, 0, 0), 2, cv2.LINE_AA)
        for candidate in selected:
            try:
                self.try_to_decode(candidate, gray, vis)
            except Exception as e:
                print(e)

        cv2.imshow('contours', vis)

        ch = cv2.waitKey(5) & 0xFF
        if ch == 27:
            exit()