Ask Your Question
0

Problem using std::vector as a parameter in some opencv functions

asked Jun 21 '14

firbo gravatar image

updated Jun 21 '14

VS2013/Windows8.1/opencv 2.4.9/debug mode

std::vector goes well in other places but once I use it as a parameter of an openCV function, it will end in assertion failed says"File:...\dbgheap.c line:1424 Expression:_pFirstBlock == pHead" Switch to release mode will solve this problem but the data in the vector will automatically and randomly change.

Even a very simple codepiece like this will go wrong

void test(Mat src)

{

vector<Mat> srcPlanes;

split(src, srcPlanes);

//assertion failed here

}

but this will work

void test(Mat src)

{

vector<Mat> srcPlanes;

split(src, srcPlanes);

srcPlanes.push_back(Mat());

srcPlanes.push_back(Mat());

srcPlanes.push_back(Mat());

}

Same problem in some other opencv functions when calling the destructor,for example, findCountours

void test(Mat src)

{

vector<vector<Point>> countours;

findContours(src, countours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);

//assertion failed here

} If I manually change the adress in countours._mylast in debugging (for exsample,from 0x0034e910 to 0x0034e908,the size of the vector will decrease by one),then it will work.

Preview: (hide)

Comments

1

please check, if you're linking to debug dlls (ending in *.d.dll) in debug mode. also, if you link against "multithreaded-dll" c-runtime

berak gravatar imageberak (Jun 21 '14)edit

I linked in MTd runtime before. Thanks

firbo gravatar imagefirbo (Jun 23 '14)edit

1 answer

Sort by » oldest newest most voted
0

answered Oct 12 '15

kabrau gravatar image

I solved this way:

vector<mat> srcPlanes(3); split(src, srcPlanes);

Preview: (hide)

Comments

it doesn't work~

timial gravatar imagetimial (Jan 21 '16)edit

I set the vector<mat> to globle variable and it doesn't throw exception and can be called for multi-times and throw only one exception at last. while the problem may not be sovled in total ,even if I have tried many methods from the web search,such as set the MTd mode or change lib to VC11 in VS2012

timial gravatar imagetimial (Jan 21 '16)edit

Question Tools

Stats

Asked: Jun 21 '14

Seen: 1,581 times

Last updated: Jun 20 '14