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()
thank you in advance
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With