Mat img = imread(..) vs img = imread(..)
i have img as a member in the .h file, but when i use
img = imread(..);
in the .cpp file, it crashes. however, using
Mat img = imread(..);
works. what is the difference? thanks!
note: opencv3.0 with qt
"it crashes" IS NO ERROR MESSAGE! What exactly happens? Which message do you get?
Is your member in the header file declared public? Is it inside a namespace? The second declaration won't even use your global variable, but rather create a local img object withing the scope of your cpp file, but not update the value of your global img object.
However I am not sure if you can make a non static object in header files. Never done so before, only know the principle.
@FooBar there werent any error messages... a window popped up saying it stopped running and that it is checking for a solution, and on my Qt creator IDE, it says after the program closed, this:
The program has unexpectedly finished.
@StevenPuttemans yes it was in the header file, but in private instead. I tried putting it as public, but it was still the same... I actually dont want to make it a local variable, but it seems like it wont crash if i do it that way.. could it be that it wasnt initialized to something? not sure how this works.. :(
@pingping__ it seems to me that you need to dig deeper in C++ basics of how header and source code files work together. This seems to be not an OpenCV problem at all.