现在我碰到了左右为难的问题:
1.如果用静态库dll解决这个问题,那么在有vector作为输入参数调用opencv就会出现析构问题,因为已经跨栈了
运行到下面会卡住:
/*
* If this ASSERT fails, a bad pointer has been passed in. It may be
* totally bogus, or it may have been allocated from another heap.
* The pointer MUST come from the 'local' heap.
*/
_ASSERTE(_CrtIsValidHeapPointer(pUserData));
我代码里有做sift检测:
{
vector<KeyPoint> pt;
m_Detector.detect( (*it2)->pImage, pt );
}运行到这里析构pt的时候就会报错
2.如果用共享库ll,就是内存泄露的问题
Detected memory leaks!
Dumping objects ->
{1139} normal block at 0x01891A58, 512 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{1138} normal block at 0x01891A10, 8 bytes long.
Data: <, > 2C 10 89 01 00 00 00 00
{1137} normal block at 0x018919C8, 8 bytes long.
Data: < > 00 10 89 01 00 00 00 00
{1136} normal block at 0x01891980, 8 bytes long.
Data: < > E0 0F 89 01 00 00 00 00
{1135} normal block at 0x01891938, 8 bytes long.
Data: < > B0 0F 89 01 00 00 00 00
{1134} normal block at 0x018918F0, 8 bytes long.
Data: < > 90 0F 89 01 00 00 00 00
{1133} normal block at 0x01891860, 80 bytes long.
Data: <` ` ` > 60 18 89 01 60 18 89 01 60 18 89 01 CD CD CD CD
{1132} normal block at 0x01891818, 8 bytes long.
Data: <| > 7C 0F 89 01 00 00 00 00
{1131} normal block at 0x018917D0, 8 bytes long.
Data: <\ > 5C 0F 89 01 00 00 00 00
{1130} normal block at 0x01891788, 8 bytes long.
Data: <8 > 38 0F 89 01 00 00 00 00
{1129} normal block at 0x01891740, 8 bytes long.
Data: < > 18 0F 89 01 00 00 00 00
{1128} normal block at 0x018916F8, 8 bytes long.
Data: < > F0 0E 89 01 00 00 00 00
{1127} normal block at 0x018916B0, 8 bytes long.
Data: < > D0 0E 89 01 00 00 00 00
{1123} normal block at 0x01891590, 8 bytes long.
Data: < > 1C 0E 89 01 00 00 00 00
{1122} normal block at 0x01891548, 8 bytes long.
...
下面还有很多。
十分悲剧,对于这个问题,难道不能两全其美了么
经过在这里发帖自己思考后,解决了,原帖如下:
http://www.opencv.org.cn/forum/viewtopic.php?f=1&t=23564&p=68153#p68153
已解决该问题:
1.使用静态库
配置属性-》C++->代码生成->运行库 多线程调试 (/MTd)
2.这个不是opencv的问题,是调用dll的问题,dll中给vector分配成员空间,无论你是传引用,还是指针,只要vector的初始化容器大小,放不下成员,在dll中就会给vector增加空间,故解决方法如下:
vector<KeyPoint> pt(1000);
m_Detector.detect( (*it2)->pImage, pt );
预先在自己程序中分配好,1000只是个估值,根据实际大小最大值来设置