Ask Your Question
1

Assertion failed in Blur/LocateROI

asked 2015-05-13 12:05:42 -0600

Guyygarty gravatar image

updated 2015-05-13 13:41:33 -0600

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

edit retag flag offensive close merge delete

Comments

  • we don't see, what you do with your UserBuffers there, and how they're related to your Mat array.
  • you never increase k, do you even initialize it ? currently, you're initializing a single element 16 times.
  • why do you need both a Mat and a buffer ? the Mat alone should do.
berak gravatar imageberak ( 2015-05-13 12:31:52 -0600 )edit

still, what is in Take_Picture() ?

berak gravatar imageberak ( 2015-05-13 13:48:14 -0600 )edit

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.

Guyygarty gravatar imageGuyygarty ( 2015-05-13 13:59:16 -0600 )edit

^^ 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.

berak gravatar imageberak ( 2015-05-13 14:15:03 -0600 )edit

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.

Guyygarty gravatar imageGuyygarty ( 2015-05-13 15:17:24 -0600 )edit

i never said that, more trying to hint at the gaps in what you show

berak gravatar imageberak ( 2015-05-13 15:21:53 -0600 )edit

yes, please do so ! ;)

(no problem, to cheat a bit on your karma (that's only silly gamification schrrott, btw))

berak gravatar imageberak ( 2015-05-13 15:59:04 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-05-13 15:50:43 -0600

Guyygarty gravatar image

updated 2015-05-13 15:51:47 -0600

I think I found the problem. In my construction cv::Mat.data and cv::Mat.datastart were not pointing to the same place. Replacing:

Result = Take_Picture(&Frame[ii].data, &BufferID[ii]);

with

unsigned char* p;
Result = Take_Picture(&p, &BufferID[ii]);
Frame[ii] = Mat(Height, Width, CV_16UC1, p);

solved the problem. I will convert this to an answer in a day or two (I am not yet allowed to answer my own questions this fast)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-05-13 12:05:42 -0600

Seen: 1,056 times

Last updated: May 13 '15