Ask Your Question

OpenCV Window Resize with Trackbar

asked 2014-09-18 04:07:59 -0500

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!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-09-18 09:22:05 -0500

Hi! use this code:

int desiredWidth=640,desiredheight=480;
resizewindow("Threshold", desiredWidth,desiredheight);
createTrackbar("Min", "Threshold", &threshMin, 255, on_trackbar);
edit flag offensive delete link more


if you don't want to resize the window size use CV_WINDOW_AUTOSIZE. For more details please refer

Balaji R gravatar imageBalaji R ( 2014-09-18 09:34:39 -0500 )edit

This works perfectly! Thanks!

Icetray gravatar imageIcetray ( 2014-09-18 09:35:23 -0500 )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 ( 2014-09-18 09:36:17 -0500 )edit

Question Tools


Asked: 2014-09-18 04:07:59 -0500

Seen: 6,732 times

Last updated: Sep 18 '14