jglunk
jglunk

Reputation: 3

OpenCV- Trackbar wont appear- window wont resize

Here's my code, the window doesnt seem to resize or show any of the trackbars. This just shows a blank 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)

Upvotes: 0

Views: 1214

Answers (1)

Gasol
Gasol

Reputation: 2537

According to namedWindow API in Python:

Python:
    None = cv.namedWindow( winname[, flags] )

You should pass cv2.WINDOW_NORMAL as a flag argument, It enables you to resize the window.

Just a reminder, you won't see the window without the loop, Because it will exit immediately after window has been created. I will suggest you add the loop like waitKey in the end of the code.

Here is the modified code for demonstration:

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)

Upvotes: 2

Related Questions