当前位置: 首页>>代码示例>>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;未经允许,请勿转载。