I do have <opencv2/highgui/highgui_c.h>
included but cvGetWindowHandle was crashing in OCV 4 if the window already existed previously. Following the debug on subsequent call it was saying that the window did not exist. This all worked in OCV 3.4
namedWindow(“video”, CV_WINDOW_KEEPRATIO);
HWND hw = (HWND)cvGetWindowHandle(“video”);
What I am finding in OCV 4.5 is that it works the first time the “video” window is created but crashes if we are coming into this OpenFile() procedure another time to open another video.
I could not find an OCV way of discovering if a namedWindow already existed and I found that destroyWindow crashed if the window did not already exist.
Using the Windows API
hw = (HWND)FindWindow(NULL, _T(“video”));
I saw that it gave me a handle if the namedWindow was just created and had not existed before but returned NULL if that window already existed.
So what I have done so far was to check with Windows first this way:
HWND hw = (HWND)FindWindow(NULL, _T(“video”));
if (!hw == NULL) {
hw = (HWND)cvGetWindowHandle(“video”);
}
else {
cv::destroyWindow(“video”);
namedWindow(“video”, CV_WINDOW_KEEPRATIO);
hw = (HWND)cvGetWindowHandle(“video”);
}
This works but it seems awfully clumsy. I was hoping for an OCV way of 1) deciding if a namedWindow already existed and 2) an OCV 4.x way of getting a handle to a namedWindow.