I've got an app that I'm developing in Windows using MFC.
When I display an image directory from the main dialog, it shows fine - with the crosshair cursor over the image. When I display an image from a thread, it shows the window, but no image. The cursor in this case is a "Wait" cursor.
I've debugged and confirmed that both image paths are the same, and it's running through the same code.
Any thoughts?
Here's the code. The "CreateImageWindow" function determines the correct size (windowed or full screen) based on user preference, and calls namedWindow("Name", WINDOW_NORMAL | CV_WINDOW_KEEPRATIO);
// Make sure we have a window
CreateImageWindow();
// Convert our string to ASCII (required by cv library)
CT2A ascii(pszImage);
// Read the file
Mat imgSrc = imread(ascii.m_psz); // Image from the file
if (!imgSrc.data) { // If the read failed - bail out
TRACE("DisplayImage: Failed to read file %s : %ld\n", pszImage, GetLastError());
return FALSE;
}
// It's probably safe to assume that the image we just loaded isn't
// the same size as the display - so we'll always resize it.
Size resizeDims;
float iScreenRatio = (float)gWindowRect.Width() / (float)gWindowRect.Height();
float iImageRatio = (float)imgSrc.cols / (float)imgSrc.rows;
int iLeftRightBorder = 0;
int iTopBottomBorder = 0;
if (iScreenRatio > iImageRatio) { // Image will scale to display height, smaller width
resizeDims.height = gWindowRect.Height();
resizeDims.width = imgSrc.cols * gWindowRect.Height() / imgSrc.rows;
iLeftRightBorder = ((gWindowRect.Width() - resizeDims.width) / 2) + 1;
}
else { // Image will scale to display width, smaller height
resizeDims.height = imgSrc.rows * gWindowRect.Width() / imgSrc.cols;
resizeDims.width = gWindowRect.Width();
iTopBottomBorder = ((gWindowRect.Height() - resizeDims.height) / 2) + 1;
}
Mat imgResized;
resize(imgSrc, imgResized, resizeDims, 0, 0, INTER_LINEAR);
Mat imgDst; // Target image with the border and fill
// Copy the file image to the destination, and fill the remainder (border) with black
copyMakeBorder(imgResized, imgDst, iTopBottomBorder, iTopBottomBorder, iLeftRightBorder, iLeftRightBorder, BORDER_CONSTANT, Scalar(0, 0, 0));
// Show the photo
imshow(SCREEN_TITLE, imgDst);