【发布时间】:2017-07-21 10:16:20
【问题描述】:
我正在使用以下代码进行背景减法。我给它的视频路径,视频运行成功,但最后它给出了 Debug Assertion Failed 错误。
我在 Microsoft 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;
}
【问题讨论】:
-
你尝试调试了吗?即使崩溃发生在系统或库文件中,您也可以将调用堆栈向上遍历到您的代码以查看它发生的位置。
-
确保链接到正确的库。在调试模式下构建并链接到发布模式库可能会导致此类问题。
-
@CaptainObvlious 我已经检查过了。所有库都在调试和发布模式下正确链接。
-
@JoachimPileborg 我尝试调试它并在库文件中停止在 _pFirstBlock == pHead 行。
标签: c++ opencv visual-c++ computer-vision assertions