0

Anytime I call cvNamedWindow I get a segmentation fault and I don't know why it happens. I've tried compiling online code samples as well as writing my own. Here's a minimal piece of code that reproduces the problem:

#include <opencv2/opencv.hpp>

int main() {
    cvNamedWindow("Video");
    return 0;
}

cv::namedWindow("Video") doesn't work either. Why does this happen? I'm compiling with OpenCV 2.3.1 under MinGW (C++ compiler v4.6.1) with Qt Creator.

Pieter
  • 31,619
  • 76
  • 167
  • 242
  • If I'm not mistaken, cv::namedWindow is in the highgui header, however that should not be the case for your segfault. The only reason I could imagine for that would be that you somehow link to a wrong version of opencv ... – etarion Mar 22 '12 at 14:13
  • This problem has been solved in this post: http://stackoverflow.com/questions/4609069/opencv-2-2-windows-xp-mingw-build-crashes-on-namedwindow-imshow – Bahadir Tasdemir Apr 14 '12 at 07:29

3 Answers3

1

I'm assuming the problem is related to another thread I posted. Long story short, my other problem had to do with a difference between debug and release DLLs that I didn't know about.

Community
  • 1
  • 1
Pieter
  • 31,619
  • 76
  • 167
  • 242
1

Maybe not directly related to the cause of your problem, but for me the reason of the segmentation fault is due to multi-threads (parallel processing).

Fan Zeng
  • 171
  • 5
1

I tested your code and was not able to reproduce the problem on:

  • Linux with GCC 4.5.1 20100924 (Red Hat 4.5.1-4)
  • Windows XP with VS2010

However, it's good practice to call cvDestroyWindow() to release the resources allocated when the window was created:

#include <opencv2/opencv.hpp>

int main() 
{
    cvNamedWindow("Video");

    cvDestroyWindow("Video");

    return 0;
}

On Windows I used OpenCV-2.3.0-win-superpack.exe. Here's a guide for installing it on Visual Studio 2010.

Community
  • 1
  • 1
karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • You're right, I should call `cvDestroyWindow` as well. But I checked with the debugger and the program segfaulted during `cvNamedWindow`, not afterwards. So destroying the window before exiting doesn't fix the issue. – Pieter Mar 22 '12 at 13:57
  • I don't know what to tell you. It doesn't happens on Linux either way. I would recompile OpenCV with MingW and make sure everything compiled successfully. I assume you are using the most recent version of OpenCV! Are you allowed to use other compiler, like [VS2010](http://stackoverflow.com/a/7014918/176769)? – karlphillip Mar 22 '12 at 14:04
  • That didn't make a difference. It's a default parameter, after all. No sign of the compiler being at fault so far! – Pieter Mar 22 '12 at 14:22
  • Updated answer. Problem doesn't happen on VS2010. – karlphillip Mar 22 '12 at 17:03
  • Interesting you mention that. After reading your comment I set up a VS2010 compilation environment and my code ran smoothly. Then I switched back to MinGW and it worked smoothly as well! I don't know what happened but it seems to be fixed. Must've been something in my build environment, I guess. – Pieter Mar 22 '12 at 19:39
  • @Pieter - most likely is that you are picking up the wrong DLL, especially if you have the Qt version of Highgui and you have mingw Qt dlls in the path – Martin Beckett Mar 22 '12 at 20:35
  • Turns out you were right. `cvNamedWindow` worked but consecutive OpenCV commands caused "Unknown signal" errors. Guess I'm back to where I started! I'd compile with VC++ except that I don't have certain crucial headers like *cstdlib* on my hard drive. I only have the MinGW and cygwin versions. I'm trying to download them but I'm not sure what I need to install. While I'm working on that route, any other guesses as to why it's failing with MinGW? – Pieter Mar 25 '12 at 08:40
  • I would open your app with Dependency Walker and check if there is anything missing. Seems like it could be an environment issue. – karlphillip Mar 25 '12 at 14:26
  • Hmm... interesting. [Here](http://i.imgur.com/WqsBK.jpg) are the results. I'm getting a *At least one module has an unresolved import due to a missing export function in a delay-load dependent module* warning but according to [some sites](http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/c032ad28-57b3-4a6e-bf6b-ffb1d8636a4d/) it's no big deal. – Pieter Mar 26 '12 at 08:21
  • Yes, I get that warning sometimes as well. – karlphillip Mar 26 '12 at 10:38