cv2.createTrackbar 使用 python [英] cv2.createTrackbar using python

查看:335
本文介绍了cv2.createTrackbar 使用 python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是python和opencv的新手,我想创建一个track-bar来控制函数cv2.findContours的层次结构但我不知道如何将其添加到源代码中她是代码:

I'm a newbie in python and opencv, I want to create a track-bar to control the hierarchy of the function cv2.findContours but I don't know how to add it to the source code her is the code:

import cv2
import cv2.cv as cv

cv2.namedWindow("test")
vc = cv2.VideoCapture(2);
retVal, frame = vc.read();
while True:
    if frame is not None:   
        imgray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
        ret,thresh = cv2.threshold(imgray,127,255,0)
        contours, hierarchy = cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)

        cv2.drawContours(frame, contours, -1, (0,255,0), 2)

        cv2.imshow("test", frame)

     rval, frame = vc.read()

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

cv.DestroyAllWindows()

先谢谢你

推荐答案

我希望你现在已经解决了你的问题,但如果你还没有解决,我会尽力解释它.您可以使用命名的窗口函数创建一个窗口,然后将轨迹栏关联到该窗口.

I hope you have solved your problems by now, but I will try to explain it in case you haven't. You can create a window using the named window function and then associate the trackbar to that window.

cv2.namedWindow('test')
cv2.createTrackbar('thrs1', 'test', 300, 800, callback)
# Do whatever you want with contours
cv2.imshow('test', frame)

您将在此处找到解释的函数 createTrackbar:cv2.createTrackbar

You will find the function createTrackbar explained here: cv2.createTrackbar

回调是指向每次幻灯片更改其位置时将调用的函数的指针.

callback is pointer to the function that will be called everytime the slides changes it's position.

这篇关于cv2.createTrackbar 使用 python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆