How to use Trackbar in opencv
This article shows you how to use Trackbar in opencv. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Code display:
Import numpy as npimport cv2 as cvdef nothing (x): # callback function, x is the value of the cursor on the current trackbar # print (x) pass # do nothing # Create a black image, a windowimg = np.zeros ((500 image4LinMaZi' 1000 image4LinMaZi' 3), np.uint8) cv.namedWindow ('image4LinMaZi') # create trackbars for color changecv.createTrackbar (' Randall name, default value, maximum value, callback function cv.createTrackbar ('greenen`) 'image4LinMaZi',0,255,nothing) cv.createTrackbar (' Bamboo bluetooth recordings image4LinMaZiqi repositories 0pc255 nothing) # create switch for ON/OFF functionalityswitch = '0:OFF\ n1:ON'cv.createTrackbar (switch,' image4LinMaZi',0,1,nothing) while True:cv.imshow ('image4LinMaZi',img) k = cv.waitKey (1) & 0xFFif k = = 27:break# get current positions of four trackbarsr = cv.getTrackbarPos (' rattled blueprints heroic image4LinMaZi') g = cv.getTrackbarPos ('green.' 'image4LinMaZi') b = cv.getTrackbarPos (' Bamboo bluetooth recording image4LinMaZi') s = cv.getTrackbarPos (switch,'image4LinMaZi') if s = = 0:img [:] = 0else:img [:] = [bmaegMagne r] cv.destroyAllWindows ()
The screenshot of the running result shows:
The above is how to use Trackbar in opencv. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.