我是学习C ++的新手。我得到了这个" Debug Assertion Failed"运行我的代码时出错。我不知道我错在哪里以及如何解决这个问题。我已经调试了这个程序,但在程序结束之前它没有任何错误。
int main()
{
Mat image;
Mat output;
Mat gray_prev;
Mat gray;
string imageName, outputName, rectName;
cout << "please input the name of file:";
getline(cin, imageName);
cout << "please input the name of output:";
getline(cin, outputName);
cout << "please input the name of rectfile:";
getline(cin, rectName);
image = imread(imageName, CV_LOAD_IMAGE_COLOR);
output = imread(outputName, CV_LOAD_IMAGE_COLOR);
if(!image.empty() && !output.empty())
{
cvtColor(image, gray_prev, CV_BGR2GRAY);
cvtColor(output, gray, CV_BGR2GRAY);
}
Rect rect1;
Rect rect2;
char cstring1[1000];
char cstring2[1000];
int x, y, w, h;
fstream f;
f.open(rectName, fstream::in);
f.getline(cstring1, sizeof(cstring1));
sscanf(cstring1, "%i,%i,%i,%i", &x, &y, &w, &h);
rect1 = Rect(x, y, w, h);
f.getline(cstring2, sizeof(cstring2));
sscanf(cstring2, "%i,%i,%i,%i", &x, &y, &w, &h);
rect2 = Rect(x, y, w, h);
vector<vector<Point2f>> points1(2); //存储前后两帧特征点
vector<vector<Point2f>> points2(2);
vector<uchar> status;
vector<float> err;
//points[0].resize(rect1.width*rect1.height);
//points[1].resize(rect2.width*rect2.height - rect1.width*rect1.height);
for(int j=rect2.y; j<(rect2.y+rect2.height); j++){
for(int i=rect2.x; i<(rect2.x+rect2.width); i++){
if( i>=rect1.x && i<=(rect1.x+rect1.width)
&& j>=rect1.y && j<=(rect1.y+rect1.height))
{
points1[0].push_back(Point2f(i, j));
}
else
{
points2[0].push_back(Point2f(i, j));
}
}
}
calcOpticalFlowPyrLK(
gray_prev,
gray,
points1[0],
points1[1],
status,
err);
calcOpticalFlowPyrLK(
gray_prev,
gray,
points2[0],
points2[1],
status,
err);
for(int i=0; i<points1[1].size(); i++)
{
circle(output, points1[1][i], 1, Scalar::all(0), (-1));
}
for(int i=0; i<points2[1].size(); i++)
{
circle(output, points2[1][i], 1, Scalar(255,0,0), (-1));
}
imshow("optimalflow", output);
waitKey(0);
f.close();
}
图片是我遇到的问题。请帮帮我。