Ask Your Question
0

Beginner problem: window size from previous run

asked 2013-08-06 05:18:54 -0600

updated 2013-08-06 05:24:27 -0600

Siegfried gravatar image

Hey everybody,

I just started to learn OpenCV and encountered the following problem.

  1. I ran my code which loads and shows an image.
  2. Then I manually changed the size of the window.
  3. When I run my code again, the window will still have the distorted size.

This is the code that I use:

char* imgData;
IplImage *img = cvLoadImage("jpgTest.jpg"); 

// show source image
cvNamedWindow("Image",0); 
cvShowImage("Image",img);

cvWaitKey();
cvReleaseImage(&img);
cvDestroyWindow("Image:");

I am very thankful to any help and explanation and also comments on how to improve the code. Thank you very much!

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2013-08-06 05:46:10 -0600

Siegfried gravatar image

Hi. First of all, you should use the C++ API instead of the old C API. The C API is marked as deprecated (see here).

This is your example in C++:

  cv::Mat img = cv::imread("jpgTest.jpg");
  cv::namedWindow("Image", cv::WINDOW_AUTOSIZE);
  cv::imshow("Image", img);
  cv::waitKey();

The second parameter of cv::namedWindow changes the behavior of the window (see here).

If you want to position the window at a certain location on the scree or want to resize the window use cv::moveWindow() and cv::resizieWindow().

edit flag offensive delete link more

Comments

Euhm and why is this any different of my post? :P

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-06 05:54:08 -0600 )edit
1

It isn't different. I was too slow. While i edited / formated the question of the poster and wrote my answer. You have already answered the question. I saw it after pushing the "Post Your Answer" button and resulting reload of the website.

Siegfried gravatar imageSiegfried ( 2013-08-06 06:00:21 -0600 )edit
1

answered 2013-08-06 05:35:16 -0600

That is because of two things 1) You are using the old C - syle API 2) Once a namedWindow has been made, the container keeps existing, however, you should give it the parameter autosize.

What I suggest is using the newer C++ API and the following code

Mat img = imread("jpgTest.jpg"); 

// show source image
namedWindow("Image", WINDOW_AUTOSIZE); 
imshow("Image",img);

// wait on keystroke to close down
waitKey(0);
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-08-06 05:18:54 -0600

Seen: 428 times

Last updated: Aug 06 '13