Debug Assertion Failed _pFirstBlock == pHead using Opencv - c++

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;
}

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!

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).

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 deleted). Or, if memory allocated by VC9 (for example), is being freed by a DLL written in VC8.

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

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.

Related

trouble with setting up OpenCV 4.1.1 on Visual "Microsoft studio 2019" ? (Illegal Instruction.)

I am trying to use Open Cv on Visual studio to write c++ code. I tried a lot of ways to reach this goal for 3 days. here is what I did in these days:
**1.download and extract open cv 4.1.1 (C:\opencv).
2.download and install Visual Microsoft Studio 2019.
3.copy the bin directory of open cv to the system variable path.
(in my case:"C:\opencv\build\x64\vc15\bin;C:\opencv\build" )
4.add include folder to the project's properties(my project name is opencv):
(properties->configuration properties ->edite include directories value to : (C:\opencv\build\include )
5.edite library directory to ( C:\opencv\build\x64\vc15\lib)
6.then in linker menu->inpute->adittional dependancies -> edit its value to "opencv_world411d.lib" .**
now I write a simple code to test open cv:
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main() {
Mat im = imread("cameraman.tiff", 0);
}
this code built correctly but when I run it It doesn't work with error :
Unhandled exception at 0x000007FEBA8D3AE2 (opencv_world411d.dll) in opencv.exe: 0xC000001D: Illegal Instruction.
gfluidimgproc_func.simd.hpp not found
You need to find gfluidimgproc_func.simd.hpp to view the source for the current call stack frame
"I added screenshot"
error report
also, I tried Cmake too.
first, configure and generate OpenCV's source file.
second, open the project in Microsoft visual studio and build all
then I build the install folder.all has been done successfully.
questions:
1.how can I fix this error to run OpenCV on Microsoft visual studio 2019 ?
does Microsoft visual studio 2019 support open cv 4.1.1? have you tried it?
tanks for your attention.
my operation system is: windows 7
intel core i5
>>4.add include folder to the project's properties(my project name is opencv): (properties->configuration properties ->edite include directories value to : (C:\opencv\build\x64 )
This is wrong, you should add C:\opencv\build\include and C:\opencv\build\include\opencv2 to the include directories in your case.
I test your case on My PC, I use VS2019 and OpenCV4.1.1 to make a test. Your other steps are correct. This step will cause the header file not to be found, so the corresponding function can not be identified and will be displayed as illegal instructions.
I have the same problem and from what I understand it is because we compile in x64 bit and execute it on an old CPU which doesn't support sse3 instructions (in my case an old i5 750). I believe your only solution is to recompile OpenCV either in 32bit or in 64bit with sse3 disabled.

Open CV, C++: "Error: The application was unable to start correctly (0x0000005)."

I started working on OpenCV recently and configured OpenCV and MingW. I'm using Windows 7 OS. I am not using any IDEs for my programs. But still I am comfortable with the way I am doing the programs for now.
I wrote my first program and it compiled successfully but when I ran the .exe file it gave an Application error as :
The application was unable to start correctly (0x0000005). Click OK to close the application.
The following is the code I wrote:
#include "cstdlib"
#include "iostream"
#include "opencv2/highgui/highgui.hpp"
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("v.jpg", CV_LOAD_IMAGE_COLOR);
if (img.empty())
{
cout << "Error: Image cannot be loaded...!!" << endl;
system("pause"); //wait for a key press
return -1;
}
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
imshow("MyWindow", img);
waitKey(0);
destroyWindow("MyWindow");
return 0;
}
And for execution, I wrote a batch file as follows and executed it::
g++ -I"D:\opencv\opencv\build\include" -L"D:\opencv\opencv\build\x86\mingw\lib" ImageTest1.cpp -lopencv_core246 -lopencv_highgui246 -o ImageTest1.exe
ImageTest1.exe
pause
I also have added the following to the system path::
D:\MingW\bin;;D:\MingW\msys\1.0\bin;;D:\OpenCV\opencv\build\x64\mingw\bin;;
I tried changing the x64 to x86. But that didn't work.
Edit: I executed the .exe as admin and it says The application was unable to start correctly (0xc000007b). Click OK to close the application
I don't believe that you have reported the error code accurately. I do not believe that the error code contains only 7 hex digits. It contains 8. I believe that you have missed off the first digit, which I bet is c. In which case the error message really is:
The application was unable to start correctly (0xc0000005).
Now, that code is the NT status code STATUS_ACCESS_VIOLATION. When the system tells you that the application was unable to start this means that the error is happening during the loader's code. In other words, your code has not even started running yet. The error will be occurring in the DllMain function of one of your dependent DLLs.
Most likely there is some incompatibility between the different DLLs that are being loaded. In order to debug this further you'll probably need to debug the loading process. Start by running Dependency Walker in profile mode to find out which module's DllMain is raising the exception. Hopefully Dependency Walker will be able to point you towards the mismatch that exists in your dependent libraries.
Put system imports in <> brackets. This is for <cstdio> and <iostream>.
EDIT: I misread the error code. Please ignore the rest of my answer.
It seems windows cannot locate the libraries on startup.
My assumption is based on the 0x7B error.

How to implement Tesseract to run with project in Visual Studio 2010

I have a C++ project in Visual Studio 2010 and wish to use OCR. I came across many "tutorials" for Tesseract but sadly, all I got was a headache and wasted time.
In my project I have an image stored as a Mat. One solution to my problem is to save this Mat as an image (image.jpg for example) and then call Tesseract executable file like this:
system("tesseract.exe image.jpg out");
Which gets me an output out.txt and then I call
infile.open ("out.txt");
to read the output from Tesseract.
It is all good and works like a chair but it is not an optimal solution. In my project I am processing a video so save/call .exe/write/read at 10+ FPS is not what I am really looking for. I want to implement Tesseract to existing code so to be able to pass a Mat as an argument and immediately get a result as a String.
Do you know any good tutorial(pref. step-by-step) to implement Tesseract OCR with Visual Studio 2010? Or your own solution?
OK, I figured it out but it works for Release and Win32 configuration only (No debug or x64). There are many linking errors under Debug configuration.
So,
1. First of all, download prepared library folder(Tesseract + Leptonica) here:
Mirror 1(Google Drive)
Mirror 2(MediaFire)
2. Extract tesseract.zip to C:\
3. In Visual Studio, go under C/C++ > General > Additional Include Directories
Insert C:\tesseract\include
4. Under Linker > General > Additional Library Directories
Insert C:\tesseract\lib
5. Under Linker > Input > Additional Dependencies
Add:
liblept168.lib
libtesseract302.lib
Sample code should look like this:
#include <tesseract\baseapi.h>
#include <leptonica\allheaders.h>
#include <iostream>
using namespace std;
int main(void){
tesseract::TessBaseAPI api;
api.Init("", "eng", tesseract::OEM_DEFAULT);
api.SetPageSegMode(static_cast<tesseract::PageSegMode>(7));
api.SetOutputName("out");
cout<<"File name:";
char image[256];
cin>>image;
PIX *pixs = pixRead(image);
STRING text_out;
api.ProcessPages(image, NULL, 0, &text_out);
cout<<text_out.string();
system("pause");
}
For interaction with OpenCV and Mat type images look HERE
It has been a lot since the last reply but it may be help to others;
I think you must also add "liblept168.lib" and "liblept168d.lib" to Additional Dependencies
Add "liblept168.dll" and "liblept168d.dll" to the destination of your exe.
Add #include to your code.
(This answer must be a comment to Bruce's answer. Sorry for confusion. )
You need to use the library through the API.
Most probably:
start by downlaoding the libs ( https://code.google.com/p/tesseract-ocr/downloads/detail?name=tesseract-3.02.02-win32-lib-include-dirs.zip&can=2&q= ). They're compiled with Visual 2008 but it should be enough
Use the API directly (example, look at an open source project using it: https://code.google.com/p/qtesseract/source/browse/#svn%2Ftrunk%2Ftessdata ) and read the links from this answer : How can i use tesseract ocr(or any other free ocr) in small c++ project?

OpenCV 2.3 and Visual Studio 2010

I am having so much trouble installing openCV 2.3 with visual studio 2010. Crash after crash, installation after installation and after several weeks I've had no luck.
Unfortunately there are no installation documents for openCV 2.3 and the directory structure and file locations are different from openCV 2.2 which makes the current tutorials almost useless. :(
Has anyone out there had any success with openCV 2.3? Can someone please try it and let me know if its an openCV build issue or my setup?
Or maybe someone can suggest an alternative to openCV. What my end goal is, is to get Pixel info, use inpaint functions, and basic image processing for After Effects and Maya.
EDIT: Sorry I thought I posed the error! This is what happens when I run the code:
#include <iostream>
#include <cv.h>
#include <highgui.h>
using namespace cv;
int main()
{
Mat image;
image = imread( "c:/image1.png", 1 );
namedWindow( "Gray image", CV_WINDOW_AUTOSIZE );
imshow( "Gray image", image );
waitKey(0);
return 0;
}
It runs until imshow. If I comment out imshow it runs fine with no errors.
Here is the errors when I add IMSHOW:
Unhandled exception at 0x76bfb727 in openCV_test.exe: Microsoft C++ exception: cv::Exception at memory location 0x0015ec20. and it gives me the option to break or continue.
This is what the output window shows:
First-chance exception at 0x76bfb727 in openCV_test.exe: Microsoft C++ exception: cv::Exception at memory location 0x0015ec20..
Unhandled exception at 0x76bfb727 in openCV_test.exe: Microsoft C++ exception: cv::Exception at memory location 0x0015ec20..
It then goes on to open SYSTEM.CPP and give me this:
- exc {msg="......\modules\core\src\array.cpp:2482: error: (-206) Unrecognized or unsupported array type
" code=-206 err="Unrecognized or unsupported array type" ...} const cv::Exception &
+ std::exception {_Mywhat=0x00000000 _Mydofree=false } std::exception
+ msg "......\modules\core\src\array.cpp:2482: error: (-206) Unrecognized or unsupported array type
" std::basic_string,std::allocator >
code -206 int
+ err "Unrecognized or unsupported array type" std::basic_string,std::allocator >
+ func "" std::basic_string,std::allocator >
+ file "......\modules\core\src\array.cpp" std::basic_string,std::allocator >
line 2482 int
Thanks!
I have OpenCV2.3 and had no problem to install it with Visual Studio v9.0.
What you should do to compile and run correctly your project in all the Visual Studio versions :
Properties of your project (right click on it)
C/C++
General
Include directory add the < your directory >\OpenCV2.3\include\opencv2, < your directory >\OpenCV2.3\include\opencv and < your directory >\OpenCV2.3\include
Linker
General
Add lib directory < your directory >\OpenCV2.3\lib
Input
Add all the libs like opencv_core230d.lib opencv_highgui230d.lib and so on...
Then don't forget to add the dll to your system path.
Configuration panel > System > Advanced > Environment variables > Path
you can add a user environment path which will override the other one,
just click New (if you have never added directory to your system path before) and write the path eg : < your directory >\OpenCV2.3\bin
Without more information, I hope it could help...
Julien,
Sometimes, the compiler cannot find the dll even if you have the correct path settings. At that point try copying the dll files from the openCV folder to ur current project (not solution) folder.
Rather than copy pasting I'll just link: http://theroundedengineer.blogspot.com/2011/07/opencv-23-for-vs-2008-from-source.html
Hopefully that helps. Granted I'm far from an expert on the differences between VS 2008 and VS 2010.
I got exactly the same problem. I couldn't read any image. I checked the data flag and image size. The flag indicated error and the size was always (0, 0). Although I do not know the actual cause, I somehow could avoid the problem and run my program fine.
At first, I compiled OpenCV myself. Even though all the dlls seemed to be created correctly and there was no build error, I noticed that the header folders are not correctly organized. Therefore, I switched to the superpack binary and tried static linking. There were a lot of undefined symbols at the beginning, so I basically just put everything into VS link options. The number of libraries I had to input to VS was quite absurd, but it is a good way to test if the superpack works.
These are what I use.
opencv_core230d.lib;opencv_calib3d230d.lib;opencv_contrib230d.lib;opencv_features2d230d.lib;opencv_highgui230d.lib;opencv_legacy230d.lib;opencv_ml230d.lib;opencv_imgproc230d.lib;opencv_video230d.lib;libjasperd.lib;libjpegd.lib;libpngd.lib;libtiffd.lib;zlibd.lib;
I also need to input Comctl32.lib to resolve linking error.
I tested my program with static libraries of superpack. Things work fine now.
The headers I used are
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
I do not try using dlls yet, but I can confirm that VS 2010 + OpenCV 2.3 64 bit from the superpack work. I hope you will have some luck with the superpack too.
(Hmm, I can't remember if I put opencv.hpp in the opencv2 folder myself, or if it was there right from the beginning. I did a lot of things to make it work and was a bit confused. But, I believe you can figure this out yourself if there is anything wrong about the header.)
Hope this helps,
Pinyo
You should try making a cycle structure:
#include <iostream>
#include <cv.h>
#include <highgui.h>
using namespace cv;
int main(){
Mat image;
namedWindow( "Gray image", 2 );
while(1){
image = imread( "d://Gaa6P.png", 1 );
imshow( "Gray image", image );
waitKey(0);
}
return 0;
}
Check your firewall. turn off firewall totally. Your antivirus may block the process too.
I had the same problem: cv::exception for memory and this was it's cause.

Strange behavior with OpenCV

When I compile my Windows application (called CrosslinesDetection) in Visual C++ 2005 including OpenCV 1.1, a computer vision library, I do not get any compile or link errors, but when I am running it, it gets to a point and freezes, and Windows says the following:
"Unhandled exception at 0x7c915223 in CrosslinesDetection.exe:
0xC0000005: Access violation writing location 0x00030ffc."
The program is a common C++ Windows Applikation with two lines of OpenCV code:
IplImage *img = cvCreateImage( cvSize( 1024, 768 ), IPL_DEPTH_8U, 1 );
cvReleaseImage( &img );
The strange behavior is now, if I
- include the OpenCV lines, the program throws the exception
- exclude the OpenCV lines, the program works properly.
I used the OpenCV libraries in another project without any problems. In particular, I made a C# project for the GUI and a C++ project compiled as DLL in the background. If I create such a solution for the above lines, I have not problems during execution.
Has anybody an idea, what might cause this error?
Thanks for any help, Stefan
Thanks for the comments.
Meanwhile, I use a minimal project for testing.
I still do not fully understand the problem, but meanwhile, I figured out, that the excpetion occurs, when I include a third party library (from uEye).
If I use a single function from OpenCV and from the uEye library in the project, then an exception occurs. If I use either a single function from OpenCV or from uEye, no exception is thrown. So, these to libraries seem to be somewhat incompatible, or yet there is another problem. However, I don't know how to detect it.
No not at this point. In the minimal example the functions are unrelated. One functions initializes the camera and the other function intializes an image structure.
But maybe the error is elsewhere...
I created in Visual Studio a C++ Windows Form Application. I added to the form a button as well as corresponding function in Form1.h file:
private: System::Void Form1_Click(System::Object^ sender, System::EventArgs^ e) {
OpenCamera();
IplImage * img = cvCreateImageHeader( cvSize( 1024, 768 ), IPL_DEPTH_8U, 1);
cvReleaseImage( &img );
CloseCamera();
}
And I added the headeras at the begin of Form1.h:
#include "CameraControl.h"
#include "cv.h"
Then, I had to switch off the precompiled header option and I had to change from /clr:pure to /clr option to successfully compile and link the project.
But, then I run the program the above mentioned exception is thrown...
I am wondering, if I misuse the C++ Windows Form Application and I should not inlcude my pure C++ code or if there is really a problem with OpenCV or the uEye library.
I would suggest to test this same code in a native project, without managed code. Either MFC or a Win32 console application.
Isn't it
cvReleaseImage( img );
? (ampersand removed)
Also you should check the proper calling convention.
I just ran and compiled those exact lines with OpenCV 1.0 and Visual Studio 2008, with no errors. Maybe try creating an empty project which does nothing else but includes the cxcore.h header and then runs those two lines.
Also just to the other poster: no the ampersand is part of the specification, he's correct there. Sorry I would post this as a comment but can't yet.