Segmentation fault when cv::Mat is constructed by Image buffer and not by VideoCapture::retreive
When I add to a buffer (a Qt QQueue) a cv::MAT that gets acquired using function
Mat grabbedFrame;
videoCapture.retreive(grabbedFrame);
the image gets dequed and cloned just fine.
When I create a Mat using the constructor below
Mat PylonToOpenCvImage = cv::Mat(ptrGrabResult->GetHeight(), ptrGrabResult->GetWidth(), CV_8UC1, (uint8_t *) pylonImage.GetBuffer());
trying to deque and clone gives a segmentation fault....
But Using
cv::imshow()
both images can be viewed....
What could be wrong? What are The differences between the grabbedFrame variable ant the PylonToOpenCvImage one.
The seg fault seems to be here
Mat Mat::clone() const
{
Mat m;
copyTo(m);
return m;
}
at the copyTo(m) function from mat.inl.hpp. Although please don't take it for granted
Also sometimes I get the following
what(): /build/opencv-iC2m9y/opencv-3.2.0+dfsg/modules/core/src/matrix.cpp:522: error: (-215) 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows in function Mat
regards
The "sometimes" errors are a clue. Your code fails sometimes because there are errors somewhere. I'd start putting checks for every function call, starting with verifying that pylonImage is valid, before doing anything with it. More often than not, programmers that use OpenCV fail to check their variables and operations in any way, resulting in very flaky code.
pylonImage is valid, because I can see the ouput with imshow() function Also I don't know how to check if two separate mat are equal, but not necessarily having the same image.... I don't know if that makes sense