Ask Your Question
0

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

asked 2014-06-20 22:05:45 -0600

firbo gravatar image

updated 2014-06-20 22:08:12 -0600

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.

edit retag flag offensive close merge delete

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 ( 2014-06-21 02:45:14 -0600 )edit

I linked in MTd runtime before. Thanks

firbo gravatar imagefirbo ( 2014-06-22 21:26:40 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-10-12 11:15:39 -0600

kabrau gravatar image

I solved this way:

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

edit flag offensive delete link more

Comments

it doesn't work~

timial gravatar imagetimial ( 2016-01-20 19:48:50 -0600 )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 ( 2016-01-20 20:34:15 -0600 )edit

Question Tools

Stats

Asked: 2014-06-20 22:05:45 -0600

Seen: 1,369 times

Last updated: Jun 20 '14