mkuse
mkuse

Reputation: 2508

OpenCV Image Pyramids Display Issue

I am trying to use Image Pyramids with opencv for pose estimation. In particular I am using pyrDown() function. ret_left_cv8UC is the base image. I am storing the images as std::vector<cv::Mat>.

pyd_orgLeftIm.push_back(ret_left_cv8UC);
pyd_orgRightIm.push_back(ret_right_cv8UC);
for( int lvl=1 ; lvl<PYD_LEVEL ; lvl++ )
{
    cv::Mat __tmpL, __tmpR;
    cv::pyrDown( pyd_orgLeftIm[lvl-1],  __tmpL );
    cv::pyrDown( pyd_orgRightIm[lvl-1], __tmpR );

    pyd_orgLeftIm.push_back( __tmpL );
    pyd_orgRightIm.push_back( __tmpR );
}

It seem to work ok, I checked the image sizes and I get as expected. However, with the display it shows up strangely (issue with aspect ratio, I think).

The base image looks correct. How do I enforce the others to show up correctly.

My display code --

for( int lvl=0 ; lvl<PYD_LEVEL ; lvl++ )
{
    char strL[100], strR[100];
    sprintf( strL, "org_imgLeft_%d", lvl );
    sprintf( strR, "org_imgRight_%d", lvl );
    cv::imshow( strL, pyd_orgLeftIm[lvl] );
    cv::imshow( strR, pyd_orgRightIm[lvl] );
    cout << pyd_orgLeftIm[lvl].rows << ", "<< pyd_orgRightIm[lvl].cols << endl;
}

I would also like to add that, initially the display is correct (correct aspect ratio for smaller images), but as soon as I put my mouse over images they scale to fit the window as shown in the screenshots.

enter image description here

Upvotes: 1

Views: 289

Answers (1)

Henrik
Henrik

Reputation: 4314

My best guess is that the images are stretched because the toolbar is wider than the images. You can specify that you want the images to keep the correct aspect ratio at all times with the cv::WINDOW_KEEPRATIO constant added to the window flags using cv::namedWindow. This would cause the image to be stretched both vertically and horizontally. You can also remove the toolbar alltogether with cv::CV_GUI_NORMAL.

int flags = cv::WINDOW_KEEPRATIO | cv::CV_GUI_NORMAL;
cv::namedWindow( strL, flags );
cv::imshow( strL, pyd_orgLeftIm[lvl] );

There is a nice introduction to loading and displaying images in the documentation.

Upvotes: 2

Related Questions