我是python和opencv的新手,我想创建一个跟踪栏来控制函数cv2.findContours的层次结构但我不知道如何将它添加到源代码中她是代码:
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()
Run Code Online (Sandbox Code Playgroud)
先感谢您
我希望你现在已经解决了你的问题,但是如果你没有,我会尽力解释.您可以使用指定的窗口函数创建窗口,然后将轨迹栏关联到该窗口.
cv2.namedWindow('test')
cv2.createTrackbar('thrs1', 'test', 300, 800, callback)
# Do whatever you want with contours
cv2.imshow('test', frame)
Run Code Online (Sandbox Code Playgroud)
你会发现这里解释的函数createTrackbar: cv2.createTrackbar
callback是指向每次幻灯片更改位置时将调用的函数的指针.