Reputation: 1222
I am using following code for background subtraction. I am giving it path of video, video runs successfully but at the end it gives Debug Assertion Failed error.
I am using following code in Microsoft Visual Studio to solve a problem of Computer Vision with opencv.
#include<opencv2/opencv.hpp>
#include<iostream>
#include<string>
#include<vector>
#include "opencv2/video/background_segm.hpp"
using namespace cv;
using namespace std;
int main()
{
Mat frame;
Mat back;
Mat fore;
VideoCapture cap;
cap.open("H:/competition.avi");
BackgroundSubtractorMOG2 bg(100,16,true);
bg.set("nmixtures",3);
vector<vector<Point> > contours;
namedWindow("Frame");
namedWindow("Background");
for(;;)
{
cap >> frame;
if(!frame.empty())
{
bg.operator ()(frame,fore);
bg.getBackgroundImage(back);
erode(fore,fore,Mat());
dilate(fore,fore,Mat());
findContours(fore,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
drawContours(frame,contours,-1,Scalar(0,0,255),2);
imshow("Frame",frame);
imshow("Background",back);
if(waitKey(30) >= 0) break;
}
else
break;
}
return 0;
}
Upvotes: 3
Views: 7002
Reputation: 1
I meet the same problem. I find the resolution through this URL. Debug Assertion Failed Expression: _pFirstBlock == pHead using OpenCV and C++ trying to call SurfFeatureDetector
The reason for this error is the configuration problem,vs2012 is matched with vc11 folder. This may help you.
Upvotes: 0
Reputation: 1
I had the same error,
File: f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c Line 1424
Expression:_pFirstBlock == pHead
when using debug mode on vs12 when testing opencv code for augmented reality, for reference the code I used was from here.
The Solution that worked for me: The problem went away for me after I updated the visual studio settings for release mode, even though I was only using debug. Other opencv code runs no problem in debug mode, so I had not bothered to fully configured the release settings.
Anyway specifically in release the parts I had to update were in Properties -> C++ -> Additional Include Directories; and Properties -> Linker -> Input -> Additional Dependencies. After that the code ran error free in debug mode and release mode. If you don't know what settings to use, they are listed in the setup instruction pages on the opencv website, vs12 instructions are here
Upvotes: 0
Reputation: 2614
For unknown reasons, some versions of opencv (2.x at least) have a CMake variable "BUILD_WITH_STATIC_CRT" that by default gets set to on, thus causing issues like that. Disable that flag, then the solution should get generated with /MDd defined.
Secondarily, open your exe file in dependency walker. Look for multiple versions of MS C++ runtime libraries. For example, you may have a version of QT built against msvcp110.dll (visual studio 2012) but your current project uses msvcp120.dll (visual studio 2013).
Upvotes: 1
Reputation: 3135
I just came across this issue and after serious web trawling, found the answer, at least it worked in my case...
you need to go to your visual studio project settings, to c/c++, to code generation and change the runtime library to Multi-threaded Debug DLL (/MDd).
It seems this error is from a single threaded DLL trying to run in a multi thread project, or something of that nature.
good luck!
Upvotes: 4
Reputation: 18441
Alright. First thing first: Hit Retry
, assuming that you are debugging (F5), and have not launched (Run) the program by hitting (Ctrl+F5). As soon as you'd hit Retry, you will see call stack in debugger.
The call stack will give you possible hint where that invalid/double free/delete is happening. That would be your starting point to analyse the issue. See if some memory is double freed, allocated using different heap (for example, with malloc
, and being delete
d). Or, if memory allocated by VC9 (for example), is being freed by a DLL written in VC8.
Upvotes: 0