I'm using OpenCV 2.4.10 in a 32-bit C#/C++ application, I feed Bitmaps (which were taken from videos, they are in memory) from C# to C++/OpenCV using a C++/CLI wrapper and it works fine in my PC and some other machines, but I'm having issues on a server running Windows Server 2008. My code throws a SEHException, which doesn't help much except for pointing out where the problem occurred.
The failing function is this one:
void charToMat(vector<uchar> in, Mat& out, int h, int w, int stride) {
// If stride is unknown, assume it's channels * width;
// Have tested with AUTO_STEP too and it's worked the same.
stride = stride > 0 ? stride : 3 * w;
Mat bucket(Size(w, h), CV_8UC3, in.data(), stride);
Mat conv = Mat(Size(w, h), CV_8UC1);
cvtColor(bucket, conv, CV_BGR2GRAY);
conv.copyTo(out);
conv.release();
bucket.release();
}
Usually it gives me this exception:
System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
at cv.Mat.create(Mat* , Int32 , Int32* , Int32 )
at cv.Mat.create(Mat* , Int32 rows, Int32 cols, Int32 type) in ...\mat.hpp:line 353
at cv.Mat.{ctor}(Mat* , Size_<int>* size, Int32 type) in ...\mat.hpp:line 88
at charToMat(vector<unsigned char\,std::allocator<unsigned char> >* in, Mat* out, Int32 h, Int32 w, Int32 stride) in ...\utils.cpp:line 15
To break down the problem and test it, I changed the code a bit. Instead of receiving a input, the method just creates a gray Mat image inside the function:
void charToMat(vector<uchar> in, Mat& out, int h, int w, int stride) {
// Testing with fixed size now.
Mat bucket(Size(100, 100), CV_8UC3, Scalar(127, 127, 127));
Mat conv = Mat(Size(100, 100), CV_8UC1);
cvtColor(bucket, conv, CV_BGR2GRAY);
conv.copyTo(out);
conv.release();
bucket.release();
}
This has thrown that, indicating a problem in the same line 353 at mat.hpp, meaning it's not a pointer/interop issue. Instead, it just can't create a simple Mat.
System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
at cv.Mat.create(Mat* , Int32 , Int32* , Int32 )
at cv.Mat.create(Mat* , Int32 rows, Int32 cols, Int32 type) in ...\mat.hpp:line 353
at cv.Mat.{ctor}(Mat* , Size_<int>* size, Int32 type, Scalar_<double>* s) ...\mat.hpp:line 94
at charToMat(...) in ...\utils.cpp:line 12
Can anyone give me a clue what to do here? If I need to, I'll get the images through the disk/imread, but it's hardly the best way to do it, and maybe imread would yield the same error.