OpenCV- Trackbar 不会出现 - window 不会调整大小
OpenCV- Trackbar wont appear- window wont resize
这是我的代码,window 似乎没有调整大小或显示任何轨迹栏。这只是显示一个空白 window.
import cv2
def empty(a):
pass
cv2.namedWindow("Trackbars")
cv2.resizeWindow("Trackbars",640,300)
cv2.createTrackbar("Hue Min","Trackbars",0,179,empty)
cv2.createTrackbar("Hue Max","Trackbars",179,179,empty)
cv2.createTrackbar("Sat Min","Trackbars",0,255,empty)
cv2.createTrackbar("Sat Max","Trackbars",255,255,empty)
cv2.createTrackbar("Val Min","Trackbars",0,255,empty)
cv2.createTrackbar("Val Max","Trackbars",255,255,empty)
根据 namedWindow API 在 Python 中:
Python:
None = cv.namedWindow( winname[, flags] )
您应该将 cv2.WINDOW_NORMAL
作为标志参数传递,它使您能够调整 window.
的大小
提醒一下,你不会看到没有循环的window,因为它会在window创建后立即退出。我会建议你在代码末尾添加像 waitKey
这样的循环。
这里是修改后的演示代码:
import cv2
def empty(a):
pass
cv2.namedWindow("Trackbars", cv2.WINDOW_NORMAL)
cv2.resizeWindow("Trackbars",640,300)
cv2.createTrackbar("Hue Min","Trackbars",0,179,empty)
cv2.createTrackbar("Hue Max","Trackbars",179,179,empty)
cv2.createTrackbar("Sat Min","Trackbars",0,255,empty)
cv2.createTrackbar("Sat Max","Trackbars",255,255,empty)
cv2.createTrackbar("Val Min","Trackbars",0,255,empty)
cv2.createTrackbar("Val Max","Trackbars",255,255,empty)
ch = None
while ch != 27:
ch = cv2.waitKey(0)
这是我的代码,window 似乎没有调整大小或显示任何轨迹栏。这只是显示一个空白 window.
import cv2
def empty(a):
pass
cv2.namedWindow("Trackbars")
cv2.resizeWindow("Trackbars",640,300)
cv2.createTrackbar("Hue Min","Trackbars",0,179,empty)
cv2.createTrackbar("Hue Max","Trackbars",179,179,empty)
cv2.createTrackbar("Sat Min","Trackbars",0,255,empty)
cv2.createTrackbar("Sat Max","Trackbars",255,255,empty)
cv2.createTrackbar("Val Min","Trackbars",0,255,empty)
cv2.createTrackbar("Val Max","Trackbars",255,255,empty)
根据 namedWindow API 在 Python 中:
Python:
None = cv.namedWindow( winname[, flags] )
您应该将 cv2.WINDOW_NORMAL
作为标志参数传递,它使您能够调整 window.
提醒一下,你不会看到没有循环的window,因为它会在window创建后立即退出。我会建议你在代码末尾添加像 waitKey
这样的循环。
这里是修改后的演示代码:
import cv2
def empty(a):
pass
cv2.namedWindow("Trackbars", cv2.WINDOW_NORMAL)
cv2.resizeWindow("Trackbars",640,300)
cv2.createTrackbar("Hue Min","Trackbars",0,179,empty)
cv2.createTrackbar("Hue Max","Trackbars",179,179,empty)
cv2.createTrackbar("Sat Min","Trackbars",0,255,empty)
cv2.createTrackbar("Sat Max","Trackbars",255,255,empty)
cv2.createTrackbar("Val Min","Trackbars",0,255,empty)
cv2.createTrackbar("Val Max","Trackbars",255,255,empty)
ch = None
while ch != 27:
ch = cv2.waitKey(0)