企业为什么要建站台呢,泰安网站建设渠道,做网站能赚钱么,网站服务内容网站建设已解决#xff1a;Vector析构异常Opencv Assert _CrtIsValidHeapPointer 欢迎来到英杰社区https://bbs.csdn.net/topics/617804998 欢迎来到我的主页#xff0c;我是博主英杰#xff0c;211科班出身#xff0c;就职于医疗科技公司#xff0c;热衷分享知识#xff0c;武汉…已解决Vector析构异常Opencv Assert _CrtIsValidHeapPointer 欢迎来到英杰社区https://bbs.csdn.net/topics/617804998 欢迎来到我的主页我是博主英杰211科班出身就职于医疗科技公司热衷分享知识武汉城市开发者社区主理人 擅长.net、C、python开发 如果遇到技术问题即可私聊博主博主一对一为您解答 修改代码、商务合作 Yan--yingjie Yan--yingjie Yan--yingjie 一、问题描述
代码运行时出现_CrtIsValidHeapPointer的异常
跟踪定位到 _CrtIsValidHeapPointer 注意到g8hdbgheap.c 文件中 _CrtIsValidHeapPointer处注释
/** 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)); 大概是因为dll,如果静态链接了运行时库dll就会拥有独立于应用程序堆也称作local heap的运行时堆实例。此时在dll外部就不能访问此local heap所以也就有上面所出现的异常啦。MSDN 中也有介绍 The _CrtIsValidHeapPointer function is used to ensure that a specific memory address is within the local heap. The local heap refers to the heap created and managed by a particular instance of the C run-time library. If a dynamic-link library (DLL) contains a static link to the run-time library, it has its own instance of the run-time heap, and therefore its own heap, independent of the applications local heap. When _DEBUG is not defined, calls to _CrtIsValidHeapPointer are removed during preprocessing. 程序崩溃在当析构一个带有vector成员函数对象的时候在析构vector时会出现这个错误大致原因是因为析构的时候找不到vector分配的空间。 查看代码发现对象里面的points2, status等vector变量是在calcOpticalFlowPyrLK(img1, img2, points1, points2, status, similarity, windowsize, level, termcriteria, lambda, 0); 函数中分配的即opencv的dll所以当对象进行析构的时候因为不能访问此local heap所以会有异常崩溃。
二、解决方法 1 在调用opencv的函数之前自己进行空间的分配。 2 还有一种可能是因为VS版本和opencv使用的版本不一致造成在用hog进行行人检测的时候出现的即是这个问题。 3.手动分配内存在调用OpenCV函数之前手动分配所需的内存空间。 4.确保版本一致性确保Visual Studio的版本与OpenCV库的版本相匹配。 5.避免将DLL添加到PATH直接将DLL复制到可执行文件的路径中而不是添加到PATH环境变量中以避免潜在的冲突。 【其他错误】 如果出现模块错误 进入控制台输入建议使用国内镜像源pip install 模块名称 -i https://mirrors.aliyun.com/pypi/simple我大致罗列了以下几种国内镜像源清华大学
https://pypi.tuna.tsinghua.edu.cn/simple阿里云
https://mirrors.aliyun.com/pypi/simple/豆瓣
https://pypi.douban.com/simple/百度云
https://mirror.baidu.com/pypi/simple/中科大
https://pypi.mirrors.ustc.edu.cn/simple/华为云
https://mirrors.huaweicloud.com/repository/pypi/simple/腾讯云
https://mirrors.cloud.tencent.com/pypi/simple/ 【粉丝福利】
更多粉丝福利关注下方公众号获取