Ask Your Question
0

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
1

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

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 ( 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
Login/Signup to Answer

Question Tools

Stats

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

Seen: 3,889 times

Last updated: Sep 18 '14