Ask Your Question
0

OpenCV Window Resize with Trackbar

asked Sep 18 '14

Icetray gravatar image

Hi Guys,

I have set my windows to CV_WINDOW_NORMAL but whenever I add a track-bar to a window, it expends that window to the full width and I cannot re-size properly. It can be re sized vertically and slightly horizontally till the end of the slider. Is there anyway around it? Perhaps limiting the max length of the slider or having the slider automatically re-size to the window width?

An example:

    namedWindow("Threshold", CV_WINDOW_NORMAL);
    createTrackbar("Min", "Threshold", &threshMin, 255, on_trackbar);
    imshow("Threshold", imageThresh);

And this is what I get: See image:

If it helps, I'm using Visual Studio 2013 running on Windows 7. When the trackbar is removed from the window, it can be re-sized normally.

Thanks in advance!

Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered Sep 18 '14

Hi! use this code:

int desiredWidth=640,desiredheight=480;
resizewindow("Threshold", desiredWidth,desiredheight);
createTrackbar("Min", "Threshold", &threshMin, 255, on_trackbar);
Preview: (hide)

Comments

if you don't want to resize the window size use CV_WINDOW_AUTOSIZE. For more details please refer http://docs.opencv.org/modules/highgui/doc/user_interface.html#namedwindow

Balaji R gravatar imageBalaji R (Sep 18 '14)edit

This works perfectly! Thanks!

Icetray gravatar imageIcetray (Sep 18 '14)edit

Please mark this as an answer if this solves your problem so that others will not look into this.

Balaji R gravatar imageBalaji R (Sep 18 '14)edit

Question Tools

Stats

Asked: Sep 18 '14

Seen: 10,899 times

Last updated: Sep 18 '14