使用Opencv进行调试断言失败_pFirstBlock == pHead。

时间:2022-09-01 20:43:16

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.

我用下面的代码来做背景减法。我给它的视频路径,视频运行成功,但最后它给出了调试断言失败的错误。

使用Opencv进行调试断言失败_pFirstBlock == pHead。

I am using following code in Microsoft Visual Studio to solve a problem of Computer Vision with opencv.

我在微软Visual Studio中使用以下代码来解决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;
}

5 个解决方案

#1


4  

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

您需要到visual studio项目设置,到c/c++,到代码生成,并将运行时库更改为多线程调试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.

看起来这个错误来自一个线程DLL,试图在多线程项目中运行,或者类似的特性。

good luck!

好运!

#2


1  

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.

由于未知的原因,一些版本的opencv(2)。至少有一个CMake变量“BUILD_WITH_STATIC_CRT”,默认情况下,它会被设置为on,从而引发诸如此类的问题。禁用该标志,然后应该使用/MDd定义解决方案。

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

其次,打开您的exe文件在依赖项walker。查找MS c++运行时库的多个版本。例如,您可能有一个针对msvcp110的QT版本。dll (visual studio 2012),但是您当前的项目使用msvcp120。dll(visual studio 2013)。

#3


0  

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.

好吧。首先:重试,假设您正在调试(F5),并且没有通过按下(Ctrl+F5)启动程序(运行)。一旦重试,您将在调试器中看到调用堆栈。

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.

调用栈将给您提示无效/双*/删除正在发生的地方。这将是你分析这个问题的出发点。查看是否有些内存是双释放的,分配使用不同的堆(例如,使用malloc,并被删除)。或者,如果VC9(例如)分配的内存被VC8中写入的DLL释放。

#4


0  

I had the same error,

我有同样的错误,

File: f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c Line 1424

文件:f:\ dd \ vctools crt \ src \ \ crt_bld \ self_x86 \ dbgheap。c 1424行

Expression:_pFirstBlock == pHead

表达式:_pFirstBlock = = pHead

when using debug mode on vs12 when testing opencv code for augmented reality, for reference the code I used was from here.

当在vs12上使用调试模式时,在测试增强现实的opencv代码时,参考我使用的代码。

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.

为我工作的解决方案:在我更新了发布模式的visual studio设置之后,问题就消失了,尽管我只使用了debug。其他opencv代码在调试模式下没有问题,所以我没有费心去完全配置释放设置。

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

无论如何,具体来说,我必须更新的部分是在属性中-> c++ ->附加包括目录;和属性-> Linker ->输入->附加依赖项。在此之后,代码在调试模式和发布模式下*运行。如果你不知道使用什么设置,他们会在opencv网站上的设置指令页面中列出,vs12指令在这里。

#5


0  

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

我遇到了同样的问题。我通过这个URL找到了解决方案。调试断言失败表达式:_pFirstBlock == pHead使用OpenCV和c++尝试调用surffeature检测器。

The reason for this error is the configuration problem,vs2012 is matched with vc11 folder. This may help you.

这个错误的原因是配置问题,vs2012匹配与vc11文件夹。这可能会帮助你。

#1


4  

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

您需要到visual studio项目设置,到c/c++,到代码生成,并将运行时库更改为多线程调试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.

看起来这个错误来自一个线程DLL,试图在多线程项目中运行,或者类似的特性。

good luck!

好运!

#2


1  

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.

由于未知的原因,一些版本的opencv(2)。至少有一个CMake变量“BUILD_WITH_STATIC_CRT”,默认情况下,它会被设置为on,从而引发诸如此类的问题。禁用该标志,然后应该使用/MDd定义解决方案。

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

其次,打开您的exe文件在依赖项walker。查找MS c++运行时库的多个版本。例如,您可能有一个针对msvcp110的QT版本。dll (visual studio 2012),但是您当前的项目使用msvcp120。dll(visual studio 2013)。

#3


0  

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.

好吧。首先:重试,假设您正在调试(F5),并且没有通过按下(Ctrl+F5)启动程序(运行)。一旦重试,您将在调试器中看到调用堆栈。

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.

调用栈将给您提示无效/双*/删除正在发生的地方。这将是你分析这个问题的出发点。查看是否有些内存是双释放的,分配使用不同的堆(例如,使用malloc,并被删除)。或者,如果VC9(例如)分配的内存被VC8中写入的DLL释放。

#4


0  

I had the same error,

我有同样的错误,

File: f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c Line 1424

文件:f:\ dd \ vctools crt \ src \ \ crt_bld \ self_x86 \ dbgheap。c 1424行

Expression:_pFirstBlock == pHead

表达式:_pFirstBlock = = pHead

when using debug mode on vs12 when testing opencv code for augmented reality, for reference the code I used was from here.

当在vs12上使用调试模式时,在测试增强现实的opencv代码时,参考我使用的代码。

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.

为我工作的解决方案:在我更新了发布模式的visual studio设置之后,问题就消失了,尽管我只使用了debug。其他opencv代码在调试模式下没有问题,所以我没有费心去完全配置释放设置。

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

无论如何,具体来说,我必须更新的部分是在属性中-> c++ ->附加包括目录;和属性-> Linker ->输入->附加依赖项。在此之后,代码在调试模式和发布模式下*运行。如果你不知道使用什么设置,他们会在opencv网站上的设置指令页面中列出,vs12指令在这里。

#5


0  

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

我遇到了同样的问题。我通过这个URL找到了解决方案。调试断言失败表达式:_pFirstBlock == pHead使用OpenCV和c++尝试调用surffeature检测器。

The reason for this error is the configuration problem,vs2012 is matched with vc11 folder. This may help you.

这个错误的原因是配置问题,vs2012匹配与vc11文件夹。这可能会帮助你。