Assertion failed in Blur/LocateROI
Hi,
I am trying to grab images off a sCMOS camera and process them on the fly. As the title says I am getting an assertion failed error when invoking blur (I have also seen this with several other functions)
The error seems to be in line 714 of matrix.cpp (I am using the precompiled 2.4.10 release):
void Mat::locateROI( Size& wholeSize, Point& ofs ) const
...
CV_DbgAssert( data == datastart + ofs.y*step[0] + ofs.x*esz );
I suspect this is related to the roundabout way I am allocating memory.
During camera setup I declare a buffer that is big enough for 16 images.
*UserBufferBlock = (WORD*)malloc(*BufSize*NBUF);
for (int i=0;i<NBUF;i++)
UserBuffers[i] = UserBufferBlock + (*BufSize*i)/2;// /2 because it counts in words and everybody else counts in bytes.
The camera SDK then dumps consecutive images into UserBuffers[i]
I transfer the images to Mat structures, by modifying the Mat.data pointer to point to UserBuffers[i], the image returned by the camera:
#define NFRAMES 1
#define MFRAMES 16
Mat Frame[NFRAMES*MFRAMES];
//width =1120; Height=500
for (int j = 0; j<MFRAMES; j++)
for (int i = 0; i<NFRAMES; i++)
{
Frame[k] = Mat(Height,Width,CV_16UC1);
k++;
}
Result = Take_Picture(&Frame[ii].data, &BufferID[ii]);
Any suggestions on how to fix this? guy
still, what is in Take_Picture() ?
The camera requires a series of WORD* arrays into which it grabs consecutive images. These need to be defined and allocated in advance.
I want a cv::Mat on which to do math. What I'm trying to do here is to minimize/eliminate clone() operations and have cv::Mat structures pointing at the buffers defined in the camera. I have verified that the first call to Take_Picture returns the WORD* pointer UserBuffer[0] and the correct image.
At a later stage I will want a larger Mat that has several images tiled together. I am therefore trying to control the location of the images to have them in a continuous memory block, rather than having the camera arbitrarily assign memory blocks.
regarding the k, I forgot to copy over the incrementation of k into the question, I fixed it.
^^ yea, all makes a lot of sense. still, don't blame blur(), or any opencv function subsequently called.
there's something foul in your memory allocation / handling, unfortunately, the gaps in the information you give are still far too wide to pinpoint anything.
I didn't intend to blame opencv - I am well aware that 99% of these errors are made by me messing up pointers somehow. I was just hoping that somebody may have some insight on specifics I should be looking for, based on the line that throws the error. I'll try to get rid of my memory management bits and see if that solves the problem.
i never said that, more trying to hint at the gaps in what you show
yes, please do so ! ;)
(no problem, to cheat a bit on your karma (that's only silly gamification schrrott, btw))