Code coherent, but the runtime will appear _CrtIsValidHeapPointer exception, followed in the morning to adjust the bug, and finally fix
Trace to _CrtIsValidHeapPointer, noting _CrtIsValidHeapPointer notes in the G 8h "@dbgheap. C File:
/*
* If This asserts fails, a bad pointer has been passed in. It May is
* Totally bogus, or it may have been allocated from another heap.
* The pointer must come from the ' local ' heap.
*/
_asserte (_CrtIsValidHeapPointer (puserdata));
Probably because DLLs if the Run-time library is statically linked, the DLL has a run-time heap instance that is independent of the application heap (also known as local heap). This local heap is not accessible outside of the DLL, so there is an exception that appears above. Also described in MSDN:
The _CrtIsValidHeapPointer function is used to ensure this 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 the 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 he AP, and therefore its own heap, independent to the application ' s local heap. When _DEBUG isn't defined, calls to _CrtIsValidHeapPointer are removed.
program crashes when a vector member function object is destructor, this error occurs when the vector is being refactored, largely because the vector allocated space is not found at the time of the destructor
Line by line View Code discovery, objects inside the points2, status and other vector variables are in calcopticalflowpyrlk (IMG1, Img2, Points1, points2, status, similarity, Window_size, level, Term_criteria, lambda, 0); The OpenCV DLL that is allocated in the function, so there will be an abnormal crash when the object is destructor because it cannot access this local heap.
Workaround:
Allocate the space yourself before calling the OpenCV function
Another possibility is that the version of VS and OpenCV are inconsistent, which is what happens when you use hog for pedestrian testing.