Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

Get Trackbar Wont Work

$
0
0
Hi guys, i really need help for my project. Im new to python and openCV. I want to create trackbar for detecting the right threshold values for canny edge detection, However, it seems didnt work. Below is the code: import numpy as np import cv2 def nothing(x): pass def find_contour(th1,th2): edges = cv2.Canny(gaus,th1,th2) contours,hierarchy = cv2.findContours(edges,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) for cnt in contours: color = np.random.randint(0,255,(3)).tolist() cv2.drawContours(img,[cnt],0,color,2) cv2.imshow('output',img) img=cv2.imread('C:/Users/USER/Desktop/PytonCVImageProcessing/Tutorials/picture/pineapple.jpg') grayscaled = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) gaus=cv2.adaptiveThreshold(grayscaled,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY, 11, 2) cv2.namedWindow('Result',cv2.WINDOW_NORMAL) cv2.createTrackbar('TH1','Result',0,255,nothing) cv2.createTrackbar('TH2','Result',0,255,nothing) find_contour(cv2.getTrackbarPos('TH1','Result'),cv2.getTrackbarPos('TH2','Result')) while True: k = cv2.waitKey(0) & 0xFF if k == 27: break # ESC key to exit cv2.destroyAllWindows()

Viewing all articles
Browse latest Browse all 19555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>