當前位置: 首頁>>代碼示例>>Python>>正文


Python cv2.getTrackbarPos方法代碼示例

本文整理匯總了Python中cv2.getTrackbarPos方法的典型用法代碼示例。如果您正苦於以下問題:Python cv2.getTrackbarPos方法的具體用法?Python cv2.getTrackbarPos怎麽用?Python cv2.getTrackbarPos使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cv2的用法示例。


在下文中一共展示了cv2.getTrackbarPos方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: update

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getTrackbarPos [as 別名]
def update(_):
        ang = np.deg2rad( cv2.getTrackbarPos('angle', win) )
        d = cv2.getTrackbarPos('d', win)
        noise = 10**(-0.1*cv2.getTrackbarPos('SNR (db)', win))

        if defocus:
            psf = defocus_kernel(d)
        else:
            psf = motion_kernel(ang, d)
        cv2.imshow('psf', psf)

        psf /= psf.sum()
        psf_pad = np.zeros_like(img)
        kh, kw = psf.shape
        psf_pad[:kh, :kw] = psf
        PSF = cv2.dft(psf_pad, flags=cv2.DFT_COMPLEX_OUTPUT, nonzeroRows = kh)
        PSF2 = (PSF**2).sum(-1)
        iPSF = PSF / (PSF2 + noise)[...,np.newaxis]
        RES = cv2.mulSpectrums(IMG, iPSF, 0)
        res = cv2.idft(RES, flags=cv2.DFT_SCALE | cv2.DFT_REAL_OUTPUT )
        res = np.roll(res, -kh//2, 0)
        res = np.roll(res, -kw//2, 1)
        cv2.imshow(win, res) 
開發者ID:makelove,項目名稱:OpenCV-Python-Tutorial,代碼行數:25,代碼來源:deconvolution.py

示例2: update

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getTrackbarPos [as 別名]
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) 
開發者ID:makelove,項目名稱:OpenCV-Python-Tutorial,代碼行數:24,代碼來源:morphology.py

示例3: update

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getTrackbarPos [as 別名]
def update(_=None):
    noise = cv2.getTrackbarPos('noise', 'fit line')
    n = cv2.getTrackbarPos('point n', 'fit line')
    r = cv2.getTrackbarPos('outlier %', 'fit line') / 100.0
    outn = int(n*r)

    p0, p1 = (90, 80), (w-90, h-80)
    img = np.zeros((h, w, 3), np.uint8)
    cv2.line(img, toint(p0), toint(p1), (0, 255, 0))

    if n > 0:
        line_points = sample_line(p0, p1, n-outn, noise)
        outliers = np.random.rand(outn, 2) * (w, h)
        points = np.vstack([line_points, outliers])
        for p in line_points:
            cv2.circle(img, toint(p), 2, (255, 255, 255), -1)
        for p in outliers:
            cv2.circle(img, toint(p), 2, (64, 64, 255), -1)
        func = getattr(cv2, cur_func_name)
        vx, vy, cx, cy = cv2.fitLine(np.float32(points), func, 0, 0.01, 0.01)
        cv2.line(img, (int(cx-vx*w), int(cy-vy*w)), (int(cx+vx*w), int(cy+vy*w)), (0, 0, 255))

    draw_str(img, (20, 20), cur_func_name)
    cv2.imshow('fit line', img) 
開發者ID:makelove,項目名稱:OpenCV-Python-Tutorial,代碼行數:26,代碼來源:fitline.py

示例4: main

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getTrackbarPos [as 別名]
def main():
    windowname = "OpenCV Media Player"
    cv2.namedWindow(windowname)

    videoFilePath = "/media/amarpandey/Media Files/Movies/Game Of Thrones/Season Seven/Game.of.Thrones.S07E03.720p.WEB.h264-TBS[eztv].mkv"

    capture = cv2.VideoCapture(videoFilePath)
    cv2.createTrackbar('FrameSpeed', windowname, 10, 600, passFunction)

    while (capture.isOpened()):

        FrameSpeed = cv2.getTrackbarPos('FrameSpeed', windowname)
        flag, frame = capture.read()

        if FrameSpeed <= 0: FrameSpeed = 1

        if flag:
            cv2.imshow(windowname, frame)
            if cv2.waitKey(FrameSpeed) & 0xFF == 27:  # because 33 * FPS == 1 second
                break
        else:
            break

    cv2.destroyWindow(windowname)
    capture.release() 
開發者ID:amarlearning,項目名稱:Finger-Detection-and-Tracking,代碼行數:27,代碼來源:MediaPlayer.py

示例5: main

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getTrackbarPos [as 別名]
def main():
    windowName = "OpenCV BGR Color Palette"
    imageData = np.zeros((512, 512, 3), np.uint8)

    cv2.namedWindow(windowName)

    cv2.createTrackbar('Blue', windowName, 0, 255, passFunction)
    cv2.createTrackbar('Green', windowName, 0, 255, passFunction)
    cv2.createTrackbar('Red', windowName, 0, 255, passFunction)

    while (True):
        cv2.imshow(windowName, imageData)

        if cv2.waitKey(1) & 0xFF == 27:
            break

        blue = cv2.getTrackbarPos('Blue', windowName)
        green = cv2.getTrackbarPos('Green', windowName)
        red = cv2.getTrackbarPos('Red', windowName)

        imageData[:] = [blue, green, red]
        print(blue, green, red)

    cv2.destroyWindow(windowName) 
開發者ID:amarlearning,項目名稱:Finger-Detection-and-Tracking,代碼行數:26,代碼來源:ColorPalette.py

示例6: main

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getTrackbarPos [as 別名]
def main():
    windowName = "Transition Effect"

    cv2.namedWindow("Transition Effect")

    imageOne = cv2.imread("../data/lena_color_512.tif", 1)
    imageTwo = cv2.imread("../data/mandril_color.tif", 1)

    cv2.createTrackbar("Alpha", windowName, 0, 1000, passFunction)

    while True:

        alpha = cv2.getTrackbarPos("Alpha", windowName) / 1000
        beta = 1 - alpha

        output = cv2.addWeighted(imageOne, alpha, imageTwo, beta, 0)

        cv2.imshow(windowName, output)

        if cv2.waitKey(1) & 0xFF == 27:
            break

    cv2.destroyAllWindows() 
開發者ID:amarlearning,項目名稱:Finger-Detection-and-Tracking,代碼行數:25,代碼來源:Transition.py

示例7: onTrackbar

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getTrackbarPos [as 別名]
def onTrackbar(self, val):
        # OpenCV-Python seems to have issues with trackbars. Each trackbar's
        # linked variable is not updated when the trackbar position changes.
        # Creating a separate callback function for each trackbar (since a
        # reference to the trackbar is not passed to the callback function)
        # doesn't help. Seems when multiple trackbars are defined in the same
        # window, all trackbars call back to the callback function for the 
        # last defined trackbar (in this case, the one corresponding to
        # ch2HighVal), regardless of which callback function was passed to them.
        #
        # Hence, I've opted to explicitly query each trackbar by name on any
        # trackbar change, regardless of which one was changed.

        self.ch0LowVal = cv2.getTrackbarPos("Ch0 Low", self.CTRL_WIN)
        self.ch0HighVal = cv2.getTrackbarPos("Ch0 High", self.CTRL_WIN)
        self.ch1LowVal = cv2.getTrackbarPos("Ch1 Low", self.CTRL_WIN)
        self.ch1HighVal = cv2.getTrackbarPos("Ch1 High", self.CTRL_WIN)
        self.ch2LowVal = cv2.getTrackbarPos("Ch2 Low", self.CTRL_WIN)
        self.ch2HighVal = cv2.getTrackbarPos("Ch2 High", self.CTRL_WIN)

        if self.mode == "image":
            self.thresholdImage() 
開發者ID:nrsyed,項目名稱:computer-vision,代碼行數:24,代碼來源:colorthresh.py

示例8: update

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getTrackbarPos [as 別名]
def update(_=None):
    noise = cv2.getTrackbarPos('noise', 'fit line')
    n = cv2.getTrackbarPos('point n', 'fit line')
    r = cv2.getTrackbarPos('outlier %', 'fit line') / 100.0
    outn = int(n*r)

    p0, p1 = (90, 80), (w-90, h-80)
    img = np.zeros((h, w, 3), np.uint8)
    cv2.line(img, toint(p0), toint(p1), (0, 255, 0))

    if n > 0:
        line_points = sample_line(p0, p1, n-outn, noise)
        outliers = np.random.rand(outn, 2) * (w, h)
        points = np.vstack([line_points, outliers])
        for p in line_points:
            cv2.circle(img, toint(p), 2, (255, 255, 255), -1)
        for p in outliers:
            cv2.circle(img, toint(p), 2, (64, 64, 255), -1)
        func = getattr(cv2.cv, cur_func_name)
        vx, vy, cx, cy = cv2.fitLine(np.float32(points), func, 0, 0.01, 0.01)
        cv2.line(img, (int(cx-vx*w), int(cy-vy*w)), (int(cx+vx*w), int(cy+vy*w)), (0, 0, 255))

    draw_str(img, (20, 20), cur_func_name)
    cv2.imshow('fit line', img) 
開發者ID:fatcloud,項目名稱:PyCV-time,代碼行數:26,代碼來源:fitline.py

示例9: draw_overlay

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getTrackbarPos [as 別名]
def draw_overlay(self, vis, tracked):
        x0, y0, x1, y1 = tracked.target.rect
        quad_3d = np.float32([[x0, y0, 0], [x1, y0, 0], [x1, y1, 0], [x0, y1, 0]])
        fx = 0.5 + cv2.getTrackbarPos('focal', 'plane') / 50.0
        h, w = vis.shape[:2]
        K = np.float64([[fx*w, 0, 0.5*(w-1)],
                        [0, fx*w, 0.5*(h-1)],
                        [0.0,0.0,      1.0]])
        dist_coef = np.zeros(4)
        ret, rvec, tvec = cv2.solvePnP(quad_3d, tracked.quad, K, dist_coef)
        verts = ar_verts * [(x1-x0), (y1-y0), -(x1-x0)*0.3] + (x0, y0, 0)
        verts = cv2.projectPoints(verts, rvec, tvec, K, dist_coef)[0].reshape(-1, 2)
        for i, j in ar_edges:
            (x0, y0), (x1, y1) = verts[i], verts[j]
            cv2.line(vis, (int(x0), int(y0)), (int(x1), int(y1)), (255, 255, 0), 2) 
開發者ID:makelove,項目名稱:OpenCV-Python-Tutorial,代碼行數:17,代碼來源:plane_ar.py

示例10: update

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getTrackbarPos [as 別名]
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) 
開發者ID:makelove,項目名稱:OpenCV-Python-Tutorial,代碼行數:16,代碼來源:floodfill.py

示例11: update

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getTrackbarPos [as 別名]
def update(dummy=None):
        global need_update
        need_update = False
        thrs = cv2.getTrackbarPos('threshold', 'distrans')
        mark = cv2.Canny(img, thrs, 3*thrs)
        dist, labels = cv2.distanceTransformWithLabels(~mark, cv2.DIST_L2, 5)
        if voronoi:
            vis = cm[np.uint8(labels)]
        else:
            vis = cm[np.uint8(dist*2)]
        vis[mark != 0] = 255
        cv2.imshow('distrans', vis) 
開發者ID:makelove,項目名稱:OpenCV-Python-Tutorial,代碼行數:14,代碼來源:distrans.py

示例12: draw_circle

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getTrackbarPos [as 別名]
def draw_circle(event, x, y, flags, param):
    r = cv2.getTrackbarPos('R', 'image')
    g = cv2.getTrackbarPos('G', 'image')
    b = cv2.getTrackbarPos('B', 'image')
    color = (b, g, r)

    global ix, iy, drawing, mode
    # 當按下左鍵是返回起始位置坐標
    if event == cv2.EVENT_LBUTTONDOWN:
        drawing = True
        ix, iy = x, y
    # 當鼠標左鍵按下並移動是繪製圖形。event 可以查看移動,flag 查看是否按下
    elif event == cv2.EVENT_MOUSEMOVE and flags == cv2.EVENT_FLAG_LBUTTON:
        if drawing is True:
            if mode is True:
                cv2.rectangle(img, (ix, iy), (x, y), color, -1)
            else:
                # 繪製圓圈,小圓點連在一起就成了線,3 代表了筆畫的粗細
                cv2.circle(img, (x, y), 3, color, -1)
                # 下麵注釋掉的代碼是起始點為圓心,起點到終點為半徑的
                # r=int(np.sqrt((x-ix)**2+(y-iy)**2))
                # cv2.circle(img,(x,y),r,(0,0,255),-1)

                # 當鼠標鬆開停止繪畫。
    elif event == cv2.EVENT_LBUTTONUP:
        drawing = False
        # if mode==True:
        #     cv2.rectangle(img,(ix,iy),(x,y),(0,255,0),-1)
        # else:
        #     cv2.circle(img,(x,y),5,(0,0,255),-1) 
開發者ID:makelove,項目名稱:OpenCV-Python-Tutorial,代碼行數:32,代碼來源:8.Trackbar_draw.py

示例13: update_threshold

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getTrackbarPos [as 別名]
def update_threshold(*arg):
    update_image(cv.getTrackbarPos('image', 'marker')) 
開發者ID:jing-vision,項目名稱:lightnet,代碼行數:4,代碼來源:auto_marker.py

示例14: update_image

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getTrackbarPos [as 別名]
def update_image(image_id, category_id = 0, image_filenames=[], enable_vis=True, enable_marker_dump=False):
    try:
        global contours, hierarchy, img, gray, g_image_filenames
        if len(image_filenames) > 0:
            g_image_filenames=image_filenames
        img=cv.imread(g_image_filenames[image_id])
        # print(g_image_filenames[image_id])
        cv.setTrackbarPos('image', 'marker', image_id)

        gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
        gray[np.where(gray <= [3])] = [187]
        gray = cv.medianBlur(gray, 11)

        if enable_vis:
            cv.imshow('gray', gray)

        if CANNY_MODE:
            thrs1 = cv.getTrackbarPos('thrs1', 'marker')
            thrs2 = cv.getTrackbarPos('thrs2', 'marker')
            bin = cv.Canny(gray, thrs1, thrs2, apertureSize=5)
        else:
            bin = cv.adaptiveThreshold(
                gray, 255, cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY_INV, 31, 10)

        if enable_vis:
            cv.imshow('bin', bin)

        _, contours0, hierarchy = cv.findContours(
            bin.copy(), cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
        contours = [cnt for cnt in contours0 if cv.contourArea(cnt) > 200]

        if enable_vis:
            cv.imshow('image', img)
        update_contour(category_id, image_id, enable_vis, enable_marker_dump)
    except Exception:
        import traceback
        traceback.print_exc()
        raise 
開發者ID:jing-vision,項目名稱:lightnet,代碼行數:40,代碼來源:auto_marker.py

示例15: get_value

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getTrackbarPos [as 別名]
def get_value(self):
        value = cv2.getTrackbarPos(self.name, self.parent_window_name)
        return value 
開發者ID:gaborvecsei,項目名稱:Color-Tracker,代碼行數:5,代碼來源:color_range_detector.py


注:本文中的cv2.getTrackbarPos方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。